]> asedeno.scripts.mit.edu Git - linux.git/blob - sound/soc/soc-core.c
ASoC: remove .get_regmap
[linux.git] / sound / soc / soc-core.c
1 /*
2  * soc-core.c  --  ALSA SoC Audio Layer
3  *
4  * Copyright 2005 Wolfson Microelectronics PLC.
5  * Copyright 2005 Openedhand Ltd.
6  * Copyright (C) 2010 Slimlogic Ltd.
7  * Copyright (C) 2010 Texas Instruments Inc.
8  *
9  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10  *         with code, comments and ideas from :-
11  *         Richard Purdie <richard@openedhand.com>
12  *
13  *  This program is free software; you can redistribute  it and/or modify it
14  *  under  the terms of  the GNU General  Public License as published by the
15  *  Free Software Foundation;  either version 2 of the  License, or (at your
16  *  option) any later version.
17  *
18  *  TODO:
19  *   o Add hw rules to enforce rates, etc.
20  *   o More testing with other codecs/machines.
21  *   o Add more codecs and platforms to ensure good API coverage.
22  *   o Support TDM on PCM and I2S
23  */
24
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/pm.h>
30 #include <linux/bitops.h>
31 #include <linux/debugfs.h>
32 #include <linux/platform_device.h>
33 #include <linux/pinctrl/consumer.h>
34 #include <linux/ctype.h>
35 #include <linux/slab.h>
36 #include <linux/of.h>
37 #include <linux/of_graph.h>
38 #include <linux/dmi.h>
39 #include <sound/core.h>
40 #include <sound/jack.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
44 #include <sound/soc-dpcm.h>
45 #include <sound/soc-topology.h>
46 #include <sound/initval.h>
47
48 #define CREATE_TRACE_POINTS
49 #include <trace/events/asoc.h>
50
51 #define NAME_SIZE       32
52
53 #ifdef CONFIG_DEBUG_FS
54 struct dentry *snd_soc_debugfs_root;
55 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
56 #endif
57
58 static DEFINE_MUTEX(client_mutex);
59 static LIST_HEAD(codec_list);
60 static LIST_HEAD(component_list);
61
62 /*
63  * This is a timeout to do a DAPM powerdown after a stream is closed().
64  * It can be used to eliminate pops between different playback streams, e.g.
65  * between two audio tracks.
66  */
67 static int pmdown_time = 5000;
68 module_param(pmdown_time, int, 0);
69 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
70
71 /* If a DMI filed contain strings in this blacklist (e.g.
72  * "Type2 - Board Manufacturer" or  "Type1 - TBD by OEM"), it will be taken
73  * as invalid and dropped when setting the card long name from DMI info.
74  */
75 static const char * const dmi_blacklist[] = {
76         "To be filled by OEM",
77         "TBD by OEM",
78         "Default String",
79         "Board Manufacturer",
80         "Board Vendor Name",
81         "Board Product Name",
82         NULL,   /* terminator */
83 };
84
85 static ssize_t pmdown_time_show(struct device *dev,
86                                 struct device_attribute *attr, char *buf)
87 {
88         struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
89
90         return sprintf(buf, "%ld\n", rtd->pmdown_time);
91 }
92
93 static ssize_t pmdown_time_set(struct device *dev,
94                                struct device_attribute *attr,
95                                const char *buf, size_t count)
96 {
97         struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
98         int ret;
99
100         ret = kstrtol(buf, 10, &rtd->pmdown_time);
101         if (ret)
102                 return ret;
103
104         return count;
105 }
106
107 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
108
109 static struct attribute *soc_dev_attrs[] = {
110         &dev_attr_pmdown_time.attr,
111         NULL
112 };
113
114 static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
115                                        struct attribute *attr, int idx)
116 {
117         struct device *dev = kobj_to_dev(kobj);
118         struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
119
120         if (attr == &dev_attr_pmdown_time.attr)
121                 return attr->mode; /* always visible */
122         return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
123 }
124
125 static const struct attribute_group soc_dapm_dev_group = {
126         .attrs = soc_dapm_dev_attrs,
127         .is_visible = soc_dev_attr_is_visible,
128 };
129
130 static const struct attribute_group soc_dev_group = {
131         .attrs = soc_dev_attrs,
132         .is_visible = soc_dev_attr_is_visible,
133 };
134
135 static const struct attribute_group *soc_dev_attr_groups[] = {
136         &soc_dapm_dev_group,
137         &soc_dev_group,
138         NULL
139 };
140
141 #ifdef CONFIG_DEBUG_FS
142 static void soc_init_component_debugfs(struct snd_soc_component *component)
143 {
144         if (!component->card->debugfs_card_root)
145                 return;
146
147         if (component->debugfs_prefix) {
148                 char *name;
149
150                 name = kasprintf(GFP_KERNEL, "%s:%s",
151                         component->debugfs_prefix, component->name);
152                 if (name) {
153                         component->debugfs_root = debugfs_create_dir(name,
154                                 component->card->debugfs_card_root);
155                         kfree(name);
156                 }
157         } else {
158                 component->debugfs_root = debugfs_create_dir(component->name,
159                                 component->card->debugfs_card_root);
160         }
161
162         if (!component->debugfs_root) {
163                 dev_warn(component->dev,
164                         "ASoC: Failed to create component debugfs directory\n");
165                 return;
166         }
167
168         snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
169                 component->debugfs_root);
170 }
171
172 static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
173 {
174         debugfs_remove_recursive(component->debugfs_root);
175 }
176
177 static int codec_list_show(struct seq_file *m, void *v)
178 {
179         struct snd_soc_codec *codec;
180
181         mutex_lock(&client_mutex);
182
183         list_for_each_entry(codec, &codec_list, list)
184                 seq_printf(m, "%s\n", codec->component.name);
185
186         mutex_unlock(&client_mutex);
187
188         return 0;
189 }
190 DEFINE_SHOW_ATTRIBUTE(codec_list);
191
192 static int dai_list_show(struct seq_file *m, void *v)
193 {
194         struct snd_soc_component *component;
195         struct snd_soc_dai *dai;
196
197         mutex_lock(&client_mutex);
198
199         list_for_each_entry(component, &component_list, list)
200                 list_for_each_entry(dai, &component->dai_list, list)
201                         seq_printf(m, "%s\n", dai->name);
202
203         mutex_unlock(&client_mutex);
204
205         return 0;
206 }
207 DEFINE_SHOW_ATTRIBUTE(dai_list);
208
209 static void soc_init_card_debugfs(struct snd_soc_card *card)
210 {
211         if (!snd_soc_debugfs_root)
212                 return;
213
214         card->debugfs_card_root = debugfs_create_dir(card->name,
215                                                      snd_soc_debugfs_root);
216         if (!card->debugfs_card_root) {
217                 dev_warn(card->dev,
218                          "ASoC: Failed to create card debugfs directory\n");
219                 return;
220         }
221
222         card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
223                                                     card->debugfs_card_root,
224                                                     &card->pop_time);
225         if (!card->debugfs_pop_time)
226                 dev_warn(card->dev,
227                        "ASoC: Failed to create pop time debugfs file\n");
228 }
229
230 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
231 {
232         debugfs_remove_recursive(card->debugfs_card_root);
233 }
234
235 static void snd_soc_debugfs_init(void)
236 {
237         snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
238         if (IS_ERR_OR_NULL(snd_soc_debugfs_root)) {
239                 pr_warn("ASoC: Failed to create debugfs directory\n");
240                 snd_soc_debugfs_root = NULL;
241                 return;
242         }
243
244         if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
245                                  &codec_list_fops))
246                 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
247
248         if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
249                                  &dai_list_fops))
250                 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
251 }
252
253 static void snd_soc_debugfs_exit(void)
254 {
255         debugfs_remove_recursive(snd_soc_debugfs_root);
256 }
257
258 #else
259
260 static inline void soc_init_component_debugfs(
261         struct snd_soc_component *component)
262 {
263 }
264
265 static inline void soc_cleanup_component_debugfs(
266         struct snd_soc_component *component)
267 {
268 }
269
270 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
271 {
272 }
273
274 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
275 {
276 }
277
278 static inline void snd_soc_debugfs_init(void)
279 {
280 }
281
282 static inline void snd_soc_debugfs_exit(void)
283 {
284 }
285
286 #endif
287
288 static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
289                               struct snd_soc_component *component)
290 {
291         struct snd_soc_rtdcom_list *rtdcom;
292         struct snd_soc_rtdcom_list *new_rtdcom;
293
294         for_each_rtdcom(rtd, rtdcom) {
295                 /* already connected */
296                 if (rtdcom->component == component)
297                         return 0;
298         }
299
300         new_rtdcom = kmalloc(sizeof(*new_rtdcom), GFP_KERNEL);
301         if (!new_rtdcom)
302                 return -ENOMEM;
303
304         new_rtdcom->component = component;
305         INIT_LIST_HEAD(&new_rtdcom->list);
306
307         list_add_tail(&new_rtdcom->list, &rtd->component_list);
308
309         return 0;
310 }
311
312 static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
313 {
314         struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
315
316         for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
317                 kfree(rtdcom1);
318
319         INIT_LIST_HEAD(&rtd->component_list);
320 }
321
322 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
323                                                 const char *driver_name)
324 {
325         struct snd_soc_rtdcom_list *rtdcom;
326
327         if (!driver_name)
328                 return NULL;
329
330         for_each_rtdcom(rtd, rtdcom) {
331                 const char *component_name = rtdcom->component->driver->name;
332
333                 if (!component_name)
334                         continue;
335
336                 if ((component_name == driver_name) ||
337                     strcmp(component_name, driver_name) == 0)
338                         return rtdcom->component;
339         }
340
341         return NULL;
342 }
343 EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
344
345 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
346                 const char *dai_link, int stream)
347 {
348         struct snd_soc_pcm_runtime *rtd;
349
350         list_for_each_entry(rtd, &card->rtd_list, list) {
351                 if (rtd->dai_link->no_pcm &&
352                         !strcmp(rtd->dai_link->name, dai_link))
353                         return rtd->pcm->streams[stream].substream;
354         }
355         dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
356         return NULL;
357 }
358 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
359
360 static const struct snd_soc_ops null_snd_soc_ops;
361
362 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
363         struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
364 {
365         struct snd_soc_pcm_runtime *rtd;
366
367         rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
368         if (!rtd)
369                 return NULL;
370
371         INIT_LIST_HEAD(&rtd->component_list);
372         rtd->card = card;
373         rtd->dai_link = dai_link;
374         if (!rtd->dai_link->ops)
375                 rtd->dai_link->ops = &null_snd_soc_ops;
376
377         rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) *
378                                         dai_link->num_codecs,
379                                         GFP_KERNEL);
380         if (!rtd->codec_dais) {
381                 kfree(rtd);
382                 return NULL;
383         }
384
385         return rtd;
386 }
387
388 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
389 {
390         kfree(rtd->codec_dais);
391         snd_soc_rtdcom_del_all(rtd);
392         kfree(rtd);
393 }
394
395 static void soc_add_pcm_runtime(struct snd_soc_card *card,
396                 struct snd_soc_pcm_runtime *rtd)
397 {
398         list_add_tail(&rtd->list, &card->rtd_list);
399         rtd->num = card->num_rtd;
400         card->num_rtd++;
401 }
402
403 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
404 {
405         struct snd_soc_pcm_runtime *rtd, *_rtd;
406
407         list_for_each_entry_safe(rtd, _rtd, &card->rtd_list, list) {
408                 list_del(&rtd->list);
409                 soc_free_pcm_runtime(rtd);
410         }
411
412         card->num_rtd = 0;
413 }
414
415 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
416                 const char *dai_link)
417 {
418         struct snd_soc_pcm_runtime *rtd;
419
420         list_for_each_entry(rtd, &card->rtd_list, list) {
421                 if (!strcmp(rtd->dai_link->name, dai_link))
422                         return rtd;
423         }
424         dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
425         return NULL;
426 }
427 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
428
429 static void codec2codec_close_delayed_work(struct work_struct *work)
430 {
431         /* Currently nothing to do for c2c links
432          * Since c2c links are internal nodes in the DAPM graph and
433          * don't interface with the outside world or application layer
434          * we don't have to do any special handling on close.
435          */
436 }
437
438 #ifdef CONFIG_PM_SLEEP
439 /* powers down audio subsystem for suspend */
440 int snd_soc_suspend(struct device *dev)
441 {
442         struct snd_soc_card *card = dev_get_drvdata(dev);
443         struct snd_soc_component *component;
444         struct snd_soc_pcm_runtime *rtd;
445         int i;
446
447         /* If the card is not initialized yet there is nothing to do */
448         if (!card->instantiated)
449                 return 0;
450
451         /* Due to the resume being scheduled into a workqueue we could
452         * suspend before that's finished - wait for it to complete.
453          */
454         snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
455
456         /* we're going to block userspace touching us until resume completes */
457         snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
458
459         /* mute any active DACs */
460         list_for_each_entry(rtd, &card->rtd_list, list) {
461
462                 if (rtd->dai_link->ignore_suspend)
463                         continue;
464
465                 for (i = 0; i < rtd->num_codecs; i++) {
466                         struct snd_soc_dai *dai = rtd->codec_dais[i];
467                         struct snd_soc_dai_driver *drv = dai->driver;
468
469                         if (drv->ops->digital_mute && dai->playback_active)
470                                 drv->ops->digital_mute(dai, 1);
471                 }
472         }
473
474         /* suspend all pcms */
475         list_for_each_entry(rtd, &card->rtd_list, list) {
476                 if (rtd->dai_link->ignore_suspend)
477                         continue;
478
479                 snd_pcm_suspend_all(rtd->pcm);
480         }
481
482         if (card->suspend_pre)
483                 card->suspend_pre(card);
484
485         list_for_each_entry(rtd, &card->rtd_list, list) {
486                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
487
488                 if (rtd->dai_link->ignore_suspend)
489                         continue;
490
491                 if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control)
492                         cpu_dai->driver->suspend(cpu_dai);
493         }
494
495         /* close any waiting streams */
496         list_for_each_entry(rtd, &card->rtd_list, list)
497                 flush_delayed_work(&rtd->delayed_work);
498
499         list_for_each_entry(rtd, &card->rtd_list, list) {
500
501                 if (rtd->dai_link->ignore_suspend)
502                         continue;
503
504                 snd_soc_dapm_stream_event(rtd,
505                                           SNDRV_PCM_STREAM_PLAYBACK,
506                                           SND_SOC_DAPM_STREAM_SUSPEND);
507
508                 snd_soc_dapm_stream_event(rtd,
509                                           SNDRV_PCM_STREAM_CAPTURE,
510                                           SND_SOC_DAPM_STREAM_SUSPEND);
511         }
512
513         /* Recheck all endpoints too, their state is affected by suspend */
514         dapm_mark_endpoints_dirty(card);
515         snd_soc_dapm_sync(&card->dapm);
516
517         /* suspend all COMPONENTs */
518         list_for_each_entry(component, &card->component_dev_list, card_list) {
519                 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
520
521                 /* If there are paths active then the COMPONENT will be held with
522                  * bias _ON and should not be suspended. */
523                 if (!component->suspended) {
524                         switch (snd_soc_dapm_get_bias_level(dapm)) {
525                         case SND_SOC_BIAS_STANDBY:
526                                 /*
527                                  * If the COMPONENT is capable of idle
528                                  * bias off then being in STANDBY
529                                  * means it's doing something,
530                                  * otherwise fall through.
531                                  */
532                                 if (dapm->idle_bias_off) {
533                                         dev_dbg(component->dev,
534                                                 "ASoC: idle_bias_off CODEC on over suspend\n");
535                                         break;
536                                 }
537
538                         case SND_SOC_BIAS_OFF:
539                                 if (component->suspend)
540                                         component->suspend(component);
541                                 component->suspended = 1;
542                                 if (component->regmap)
543                                         regcache_mark_dirty(component->regmap);
544                                 /* deactivate pins to sleep state */
545                                 pinctrl_pm_select_sleep_state(component->dev);
546                                 break;
547                         default:
548                                 dev_dbg(component->dev,
549                                         "ASoC: COMPONENT is on over suspend\n");
550                                 break;
551                         }
552                 }
553         }
554
555         list_for_each_entry(rtd, &card->rtd_list, list) {
556                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
557
558                 if (rtd->dai_link->ignore_suspend)
559                         continue;
560
561                 if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control)
562                         cpu_dai->driver->suspend(cpu_dai);
563
564                 /* deactivate pins to sleep state */
565                 pinctrl_pm_select_sleep_state(cpu_dai->dev);
566         }
567
568         if (card->suspend_post)
569                 card->suspend_post(card);
570
571         return 0;
572 }
573 EXPORT_SYMBOL_GPL(snd_soc_suspend);
574
575 /* deferred resume work, so resume can complete before we finished
576  * setting our codec back up, which can be very slow on I2C
577  */
578 static void soc_resume_deferred(struct work_struct *work)
579 {
580         struct snd_soc_card *card =
581                         container_of(work, struct snd_soc_card, deferred_resume_work);
582         struct snd_soc_pcm_runtime *rtd;
583         struct snd_soc_component *component;
584         int i;
585
586         /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
587          * so userspace apps are blocked from touching us
588          */
589
590         dev_dbg(card->dev, "ASoC: starting resume work\n");
591
592         /* Bring us up into D2 so that DAPM starts enabling things */
593         snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
594
595         if (card->resume_pre)
596                 card->resume_pre(card);
597
598         /* resume control bus DAIs */
599         list_for_each_entry(rtd, &card->rtd_list, list) {
600                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
601
602                 if (rtd->dai_link->ignore_suspend)
603                         continue;
604
605                 if (cpu_dai->driver->resume && cpu_dai->driver->bus_control)
606                         cpu_dai->driver->resume(cpu_dai);
607         }
608
609         list_for_each_entry(component, &card->component_dev_list, card_list) {
610                 if (component->suspended) {
611                         if (component->resume)
612                                 component->resume(component);
613                         component->suspended = 0;
614                 }
615         }
616
617         list_for_each_entry(rtd, &card->rtd_list, list) {
618
619                 if (rtd->dai_link->ignore_suspend)
620                         continue;
621
622                 snd_soc_dapm_stream_event(rtd,
623                                           SNDRV_PCM_STREAM_PLAYBACK,
624                                           SND_SOC_DAPM_STREAM_RESUME);
625
626                 snd_soc_dapm_stream_event(rtd,
627                                           SNDRV_PCM_STREAM_CAPTURE,
628                                           SND_SOC_DAPM_STREAM_RESUME);
629         }
630
631         /* unmute any active DACs */
632         list_for_each_entry(rtd, &card->rtd_list, list) {
633
634                 if (rtd->dai_link->ignore_suspend)
635                         continue;
636
637                 for (i = 0; i < rtd->num_codecs; i++) {
638                         struct snd_soc_dai *dai = rtd->codec_dais[i];
639                         struct snd_soc_dai_driver *drv = dai->driver;
640
641                         if (drv->ops->digital_mute && dai->playback_active)
642                                 drv->ops->digital_mute(dai, 0);
643                 }
644         }
645
646         list_for_each_entry(rtd, &card->rtd_list, list) {
647                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
648
649                 if (rtd->dai_link->ignore_suspend)
650                         continue;
651
652                 if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control)
653                         cpu_dai->driver->resume(cpu_dai);
654         }
655
656         if (card->resume_post)
657                 card->resume_post(card);
658
659         dev_dbg(card->dev, "ASoC: resume work completed\n");
660
661         /* Recheck all endpoints too, their state is affected by suspend */
662         dapm_mark_endpoints_dirty(card);
663         snd_soc_dapm_sync(&card->dapm);
664
665         /* userspace can access us now we are back as we were before */
666         snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
667 }
668
669 /* powers up audio subsystem after a suspend */
670 int snd_soc_resume(struct device *dev)
671 {
672         struct snd_soc_card *card = dev_get_drvdata(dev);
673         bool bus_control = false;
674         struct snd_soc_pcm_runtime *rtd;
675
676         /* If the card is not initialized yet there is nothing to do */
677         if (!card->instantiated)
678                 return 0;
679
680         /* activate pins from sleep state */
681         list_for_each_entry(rtd, &card->rtd_list, list) {
682                 struct snd_soc_dai **codec_dais = rtd->codec_dais;
683                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
684                 int j;
685
686                 if (cpu_dai->active)
687                         pinctrl_pm_select_default_state(cpu_dai->dev);
688
689                 for (j = 0; j < rtd->num_codecs; j++) {
690                         struct snd_soc_dai *codec_dai = codec_dais[j];
691                         if (codec_dai->active)
692                                 pinctrl_pm_select_default_state(codec_dai->dev);
693                 }
694         }
695
696         /*
697          * DAIs that also act as the control bus master might have other drivers
698          * hanging off them so need to resume immediately. Other drivers don't
699          * have that problem and may take a substantial amount of time to resume
700          * due to I/O costs and anti-pop so handle them out of line.
701          */
702         list_for_each_entry(rtd, &card->rtd_list, list) {
703                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
704                 bus_control |= cpu_dai->driver->bus_control;
705         }
706         if (bus_control) {
707                 dev_dbg(dev, "ASoC: Resuming control bus master immediately\n");
708                 soc_resume_deferred(&card->deferred_resume_work);
709         } else {
710                 dev_dbg(dev, "ASoC: Scheduling resume work\n");
711                 if (!schedule_work(&card->deferred_resume_work))
712                         dev_err(dev, "ASoC: resume work item may be lost\n");
713         }
714
715         return 0;
716 }
717 EXPORT_SYMBOL_GPL(snd_soc_resume);
718 #else
719 #define snd_soc_suspend NULL
720 #define snd_soc_resume NULL
721 #endif
722
723 static const struct snd_soc_dai_ops null_dai_ops = {
724 };
725
726 static struct snd_soc_component *soc_find_component(
727         const struct device_node *of_node, const char *name)
728 {
729         struct snd_soc_component *component;
730
731         lockdep_assert_held(&client_mutex);
732
733         list_for_each_entry(component, &component_list, list) {
734                 if (of_node) {
735                         if (component->dev->of_node == of_node)
736                                 return component;
737                 } else if (strcmp(component->name, name) == 0) {
738                         return component;
739                 }
740         }
741
742         return NULL;
743 }
744
745 /**
746  * snd_soc_find_dai - Find a registered DAI
747  *
748  * @dlc: name of the DAI or the DAI driver and optional component info to match
749  *
750  * This function will search all registered components and their DAIs to
751  * find the DAI of the same name. The component's of_node and name
752  * should also match if being specified.
753  *
754  * Return: pointer of DAI, or NULL if not found.
755  */
756 struct snd_soc_dai *snd_soc_find_dai(
757         const struct snd_soc_dai_link_component *dlc)
758 {
759         struct snd_soc_component *component;
760         struct snd_soc_dai *dai;
761         struct device_node *component_of_node;
762
763         lockdep_assert_held(&client_mutex);
764
765         /* Find CPU DAI from registered DAIs*/
766         list_for_each_entry(component, &component_list, list) {
767                 component_of_node = component->dev->of_node;
768                 if (!component_of_node && component->dev->parent)
769                         component_of_node = component->dev->parent->of_node;
770
771                 if (dlc->of_node && component_of_node != dlc->of_node)
772                         continue;
773                 if (dlc->name && strcmp(component->name, dlc->name))
774                         continue;
775                 list_for_each_entry(dai, &component->dai_list, list) {
776                         if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
777                             && (!dai->driver->name
778                                 || strcmp(dai->driver->name, dlc->dai_name)))
779                                 continue;
780
781                         return dai;
782                 }
783         }
784
785         return NULL;
786 }
787 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
788
789
790 /**
791  * snd_soc_find_dai_link - Find a DAI link
792  *
793  * @card: soc card
794  * @id: DAI link ID to match
795  * @name: DAI link name to match, optional
796  * @stream_name: DAI link stream name to match, optional
797  *
798  * This function will search all existing DAI links of the soc card to
799  * find the link of the same ID. Since DAI links may not have their
800  * unique ID, so name and stream name should also match if being
801  * specified.
802  *
803  * Return: pointer of DAI link, or NULL if not found.
804  */
805 struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
806                                                int id, const char *name,
807                                                const char *stream_name)
808 {
809         struct snd_soc_dai_link *link, *_link;
810
811         lockdep_assert_held(&client_mutex);
812
813         list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
814                 if (link->id != id)
815                         continue;
816
817                 if (name && (!link->name || strcmp(name, link->name)))
818                         continue;
819
820                 if (stream_name && (!link->stream_name
821                         || strcmp(stream_name, link->stream_name)))
822                         continue;
823
824                 return link;
825         }
826
827         return NULL;
828 }
829 EXPORT_SYMBOL_GPL(snd_soc_find_dai_link);
830
831 static bool soc_is_dai_link_bound(struct snd_soc_card *card,
832                 struct snd_soc_dai_link *dai_link)
833 {
834         struct snd_soc_pcm_runtime *rtd;
835
836         list_for_each_entry(rtd, &card->rtd_list, list) {
837                 if (rtd->dai_link == dai_link)
838                         return true;
839         }
840
841         return false;
842 }
843
844 static int soc_bind_dai_link(struct snd_soc_card *card,
845         struct snd_soc_dai_link *dai_link)
846 {
847         struct snd_soc_pcm_runtime *rtd;
848         struct snd_soc_dai_link_component *codecs = dai_link->codecs;
849         struct snd_soc_dai_link_component cpu_dai_component;
850         struct snd_soc_component *component;
851         struct snd_soc_dai **codec_dais;
852         struct device_node *platform_of_node;
853         const char *platform_name;
854         int i;
855
856         dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
857
858         if (soc_is_dai_link_bound(card, dai_link)) {
859                 dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
860                         dai_link->name);
861                 return 0;
862         }
863
864         rtd = soc_new_pcm_runtime(card, dai_link);
865         if (!rtd)
866                 return -ENOMEM;
867
868         cpu_dai_component.name = dai_link->cpu_name;
869         cpu_dai_component.of_node = dai_link->cpu_of_node;
870         cpu_dai_component.dai_name = dai_link->cpu_dai_name;
871         rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
872         if (!rtd->cpu_dai) {
873                 dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
874                          dai_link->cpu_dai_name);
875                 goto _err_defer;
876         }
877         snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component);
878
879         rtd->num_codecs = dai_link->num_codecs;
880
881         /* Find CODEC from registered CODECs */
882         codec_dais = rtd->codec_dais;
883         for (i = 0; i < rtd->num_codecs; i++) {
884                 codec_dais[i] = snd_soc_find_dai(&codecs[i]);
885                 if (!codec_dais[i]) {
886                         dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
887                                 codecs[i].dai_name);
888                         goto _err_defer;
889                 }
890                 snd_soc_rtdcom_add(rtd, codec_dais[i]->component);
891         }
892
893         /* Single codec links expect codec and codec_dai in runtime data */
894         rtd->codec_dai = codec_dais[0];
895         rtd->codec = rtd->codec_dai->codec;
896
897         /* if there's no platform we match on the empty platform */
898         platform_name = dai_link->platform_name;
899         if (!platform_name && !dai_link->platform_of_node)
900                 platform_name = "snd-soc-dummy";
901
902         /* find one from the set of registered platforms */
903         list_for_each_entry(component, &component_list, list) {
904                 platform_of_node = component->dev->of_node;
905                 if (!platform_of_node && component->dev->parent->of_node)
906                         platform_of_node = component->dev->parent->of_node;
907
908                 if (dai_link->platform_of_node) {
909                         if (platform_of_node != dai_link->platform_of_node)
910                                 continue;
911                 } else {
912                         if (strcmp(component->name, platform_name))
913                                 continue;
914                 }
915
916                 snd_soc_rtdcom_add(rtd, component);
917         }
918
919         soc_add_pcm_runtime(card, rtd);
920         return 0;
921
922 _err_defer:
923         soc_free_pcm_runtime(rtd);
924         return  -EPROBE_DEFER;
925 }
926
927 static void soc_remove_component(struct snd_soc_component *component)
928 {
929         if (!component->card)
930                 return;
931
932         list_del(&component->card_list);
933
934         if (component->remove)
935                 component->remove(component);
936
937         snd_soc_dapm_free(snd_soc_component_get_dapm(component));
938
939         soc_cleanup_component_debugfs(component);
940         component->card = NULL;
941         module_put(component->dev->driver->owner);
942 }
943
944 static void soc_remove_dai(struct snd_soc_dai *dai, int order)
945 {
946         int err;
947
948         if (dai && dai->probed &&
949                         dai->driver->remove_order == order) {
950                 if (dai->driver->remove) {
951                         err = dai->driver->remove(dai);
952                         if (err < 0)
953                                 dev_err(dai->dev,
954                                         "ASoC: failed to remove %s: %d\n",
955                                         dai->name, err);
956                 }
957                 dai->probed = 0;
958         }
959 }
960
961 static void soc_remove_link_dais(struct snd_soc_card *card,
962                 struct snd_soc_pcm_runtime *rtd, int order)
963 {
964         int i;
965
966         /* unregister the rtd device */
967         if (rtd->dev_registered) {
968                 device_unregister(rtd->dev);
969                 rtd->dev_registered = 0;
970         }
971
972         /* remove the CODEC DAI */
973         for (i = 0; i < rtd->num_codecs; i++)
974                 soc_remove_dai(rtd->codec_dais[i], order);
975
976         soc_remove_dai(rtd->cpu_dai, order);
977 }
978
979 static void soc_remove_link_components(struct snd_soc_card *card,
980         struct snd_soc_pcm_runtime *rtd, int order)
981 {
982         struct snd_soc_component *component;
983         struct snd_soc_rtdcom_list *rtdcom;
984
985         for_each_rtdcom(rtd, rtdcom) {
986                 component = rtdcom->component;
987
988                 if (component->driver->remove_order == order)
989                         soc_remove_component(component);
990         }
991 }
992
993 static void soc_remove_dai_links(struct snd_soc_card *card)
994 {
995         int order;
996         struct snd_soc_pcm_runtime *rtd;
997         struct snd_soc_dai_link *link, *_link;
998
999         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1000                         order++) {
1001                 list_for_each_entry(rtd, &card->rtd_list, list)
1002                         soc_remove_link_dais(card, rtd, order);
1003         }
1004
1005         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1006                         order++) {
1007                 list_for_each_entry(rtd, &card->rtd_list, list)
1008                         soc_remove_link_components(card, rtd, order);
1009         }
1010
1011         list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1012                 if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK)
1013                         dev_warn(card->dev, "Topology forgot to remove link %s?\n",
1014                                 link->name);
1015
1016                 list_del(&link->list);
1017                 card->num_dai_links--;
1018         }
1019 }
1020
1021 static int snd_soc_init_multicodec(struct snd_soc_card *card,
1022                                    struct snd_soc_dai_link *dai_link)
1023 {
1024         /* Legacy codec/codec_dai link is a single entry in multicodec */
1025         if (dai_link->codec_name || dai_link->codec_of_node ||
1026             dai_link->codec_dai_name) {
1027                 dai_link->num_codecs = 1;
1028
1029                 dai_link->codecs = devm_kzalloc(card->dev,
1030                                 sizeof(struct snd_soc_dai_link_component),
1031                                 GFP_KERNEL);
1032                 if (!dai_link->codecs)
1033                         return -ENOMEM;
1034
1035                 dai_link->codecs[0].name = dai_link->codec_name;
1036                 dai_link->codecs[0].of_node = dai_link->codec_of_node;
1037                 dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
1038         }
1039
1040         if (!dai_link->codecs) {
1041                 dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
1042                 return -EINVAL;
1043         }
1044
1045         return 0;
1046 }
1047
1048 static int soc_init_dai_link(struct snd_soc_card *card,
1049                                    struct snd_soc_dai_link *link)
1050 {
1051         int i, ret;
1052
1053         ret = snd_soc_init_multicodec(card, link);
1054         if (ret) {
1055                 dev_err(card->dev, "ASoC: failed to init multicodec\n");
1056                 return ret;
1057         }
1058
1059         for (i = 0; i < link->num_codecs; i++) {
1060                 /*
1061                  * Codec must be specified by 1 of name or OF node,
1062                  * not both or neither.
1063                  */
1064                 if (!!link->codecs[i].name ==
1065                     !!link->codecs[i].of_node) {
1066                         dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
1067                                 link->name);
1068                         return -EINVAL;
1069                 }
1070                 /* Codec DAI name must be specified */
1071                 if (!link->codecs[i].dai_name) {
1072                         dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
1073                                 link->name);
1074                         return -EINVAL;
1075                 }
1076         }
1077
1078         /*
1079          * Platform may be specified by either name or OF node, but
1080          * can be left unspecified, and a dummy platform will be used.
1081          */
1082         if (link->platform_name && link->platform_of_node) {
1083                 dev_err(card->dev,
1084                         "ASoC: Both platform name/of_node are set for %s\n",
1085                         link->name);
1086                 return -EINVAL;
1087         }
1088
1089         /*
1090          * CPU device may be specified by either name or OF node, but
1091          * can be left unspecified, and will be matched based on DAI
1092          * name alone..
1093          */
1094         if (link->cpu_name && link->cpu_of_node) {
1095                 dev_err(card->dev,
1096                         "ASoC: Neither/both cpu name/of_node are set for %s\n",
1097                         link->name);
1098                 return -EINVAL;
1099         }
1100         /*
1101          * At least one of CPU DAI name or CPU device name/node must be
1102          * specified
1103          */
1104         if (!link->cpu_dai_name &&
1105             !(link->cpu_name || link->cpu_of_node)) {
1106                 dev_err(card->dev,
1107                         "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
1108                         link->name);
1109                 return -EINVAL;
1110         }
1111
1112         return 0;
1113 }
1114
1115 void snd_soc_disconnect_sync(struct device *dev)
1116 {
1117         struct snd_soc_component *component = snd_soc_lookup_component(dev, NULL);
1118
1119         if (!component || !component->card)
1120                 return;
1121
1122         snd_card_disconnect_sync(component->card->snd_card);
1123 }
1124 EXPORT_SYMBOL_GPL(snd_soc_disconnect_sync);
1125
1126 /**
1127  * snd_soc_add_dai_link - Add a DAI link dynamically
1128  * @card: The ASoC card to which the DAI link is added
1129  * @dai_link: The new DAI link to add
1130  *
1131  * This function adds a DAI link to the ASoC card's link list.
1132  *
1133  * Note: Topology can use this API to add DAI links when probing the
1134  * topology component. And machine drivers can still define static
1135  * DAI links in dai_link array.
1136  */
1137 int snd_soc_add_dai_link(struct snd_soc_card *card,
1138                 struct snd_soc_dai_link *dai_link)
1139 {
1140         if (dai_link->dobj.type
1141             && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1142                 dev_err(card->dev, "Invalid dai link type %d\n",
1143                         dai_link->dobj.type);
1144                 return -EINVAL;
1145         }
1146
1147         lockdep_assert_held(&client_mutex);
1148         /* Notify the machine driver for extra initialization
1149          * on the link created by topology.
1150          */
1151         if (dai_link->dobj.type && card->add_dai_link)
1152                 card->add_dai_link(card, dai_link);
1153
1154         list_add_tail(&dai_link->list, &card->dai_link_list);
1155         card->num_dai_links++;
1156
1157         return 0;
1158 }
1159 EXPORT_SYMBOL_GPL(snd_soc_add_dai_link);
1160
1161 /**
1162  * snd_soc_remove_dai_link - Remove a DAI link from the list
1163  * @card: The ASoC card that owns the link
1164  * @dai_link: The DAI link to remove
1165  *
1166  * This function removes a DAI link from the ASoC card's link list.
1167  *
1168  * For DAI links previously added by topology, topology should
1169  * remove them by using the dobj embedded in the link.
1170  */
1171 void snd_soc_remove_dai_link(struct snd_soc_card *card,
1172                              struct snd_soc_dai_link *dai_link)
1173 {
1174         struct snd_soc_dai_link *link, *_link;
1175
1176         if (dai_link->dobj.type
1177             && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1178                 dev_err(card->dev, "Invalid dai link type %d\n",
1179                         dai_link->dobj.type);
1180                 return;
1181         }
1182
1183         lockdep_assert_held(&client_mutex);
1184         /* Notify the machine driver for extra destruction
1185          * on the link created by topology.
1186          */
1187         if (dai_link->dobj.type && card->remove_dai_link)
1188                 card->remove_dai_link(card, dai_link);
1189
1190         list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1191                 if (link == dai_link) {
1192                         list_del(&link->list);
1193                         card->num_dai_links--;
1194                         return;
1195                 }
1196         }
1197 }
1198 EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
1199
1200 static void soc_set_name_prefix(struct snd_soc_card *card,
1201                                 struct snd_soc_component *component)
1202 {
1203         int i;
1204
1205         if (card->codec_conf == NULL)
1206                 return;
1207
1208         for (i = 0; i < card->num_configs; i++) {
1209                 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1210                 struct device_node *component_of_node = component->dev->of_node;
1211
1212                 if (!component_of_node && component->dev->parent)
1213                         component_of_node = component->dev->parent->of_node;
1214
1215                 if (map->of_node && component_of_node != map->of_node)
1216                         continue;
1217                 if (map->dev_name && strcmp(component->name, map->dev_name))
1218                         continue;
1219                 component->name_prefix = map->name_prefix;
1220                 break;
1221         }
1222 }
1223
1224 static int soc_probe_component(struct snd_soc_card *card,
1225         struct snd_soc_component *component)
1226 {
1227         struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1228         struct snd_soc_dai *dai;
1229         int ret;
1230
1231         if (!strcmp(component->name, "snd-soc-dummy"))
1232                 return 0;
1233
1234         if (component->card) {
1235                 if (component->card != card) {
1236                         dev_err(component->dev,
1237                                 "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1238                                 card->name, component->card->name);
1239                         return -ENODEV;
1240                 }
1241                 return 0;
1242         }
1243
1244         if (!try_module_get(component->dev->driver->owner))
1245                 return -ENODEV;
1246
1247         component->card = card;
1248         dapm->card = card;
1249         soc_set_name_prefix(card, component);
1250
1251         soc_init_component_debugfs(component);
1252
1253         if (component->driver->dapm_widgets) {
1254                 ret = snd_soc_dapm_new_controls(dapm,
1255                                         component->driver->dapm_widgets,
1256                                         component->driver->num_dapm_widgets);
1257
1258                 if (ret != 0) {
1259                         dev_err(component->dev,
1260                                 "Failed to create new controls %d\n", ret);
1261                         goto err_probe;
1262                 }
1263         }
1264
1265         list_for_each_entry(dai, &component->dai_list, list) {
1266                 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1267                 if (ret != 0) {
1268                         dev_err(component->dev,
1269                                 "Failed to create DAI widgets %d\n", ret);
1270                         goto err_probe;
1271                 }
1272         }
1273
1274         if (component->probe) {
1275                 ret = component->probe(component);
1276                 if (ret < 0) {
1277                         dev_err(component->dev,
1278                                 "ASoC: failed to probe component %d\n", ret);
1279                         goto err_probe;
1280                 }
1281
1282                 WARN(dapm->idle_bias_off &&
1283                         dapm->bias_level != SND_SOC_BIAS_OFF,
1284                         "codec %s can not start from non-off bias with idle_bias_off==1\n",
1285                         component->name);
1286         }
1287
1288         /* machine specific init */
1289         if (component->init) {
1290                 ret = component->init(component);
1291                 if (ret < 0) {
1292                         dev_err(component->dev,
1293                                 "Failed to do machine specific init %d\n", ret);
1294                         goto err_probe;
1295                 }
1296         }
1297
1298         if (component->driver->controls)
1299                 snd_soc_add_component_controls(component,
1300                                                component->driver->controls,
1301                                                component->driver->num_controls);
1302         if (component->driver->dapm_routes)
1303                 snd_soc_dapm_add_routes(dapm,
1304                                         component->driver->dapm_routes,
1305                                         component->driver->num_dapm_routes);
1306
1307         list_add(&dapm->list, &card->dapm_list);
1308         list_add(&component->card_list, &card->component_dev_list);
1309
1310         return 0;
1311
1312 err_probe:
1313         soc_cleanup_component_debugfs(component);
1314         component->card = NULL;
1315         module_put(component->dev->driver->owner);
1316
1317         return ret;
1318 }
1319
1320 static void rtd_release(struct device *dev)
1321 {
1322         kfree(dev);
1323 }
1324
1325 static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1326         const char *name)
1327 {
1328         int ret = 0;
1329
1330         /* register the rtd device */
1331         rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1332         if (!rtd->dev)
1333                 return -ENOMEM;
1334         device_initialize(rtd->dev);
1335         rtd->dev->parent = rtd->card->dev;
1336         rtd->dev->release = rtd_release;
1337         rtd->dev->groups = soc_dev_attr_groups;
1338         dev_set_name(rtd->dev, "%s", name);
1339         dev_set_drvdata(rtd->dev, rtd);
1340         mutex_init(&rtd->pcm_mutex);
1341         INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1342         INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1343         INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1344         INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1345         ret = device_add(rtd->dev);
1346         if (ret < 0) {
1347                 /* calling put_device() here to free the rtd->dev */
1348                 put_device(rtd->dev);
1349                 dev_err(rtd->card->dev,
1350                         "ASoC: failed to register runtime device: %d\n", ret);
1351                 return ret;
1352         }
1353         rtd->dev_registered = 1;
1354         return 0;
1355 }
1356
1357 static int soc_probe_link_components(struct snd_soc_card *card,
1358                         struct snd_soc_pcm_runtime *rtd,
1359                                      int order)
1360 {
1361         struct snd_soc_component *component;
1362         struct snd_soc_rtdcom_list *rtdcom;
1363         int ret;
1364
1365         for_each_rtdcom(rtd, rtdcom) {
1366                 component = rtdcom->component;
1367
1368                 if (component->driver->probe_order == order) {
1369                         ret = soc_probe_component(card, component);
1370                         if (ret < 0)
1371                                 return ret;
1372                 }
1373         }
1374
1375         return 0;
1376 }
1377
1378 static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1379 {
1380         if (dai->probed ||
1381             dai->driver->probe_order != order)
1382                 return 0;
1383
1384         if (dai->driver->probe) {
1385                 int ret = dai->driver->probe(dai);
1386                 if (ret < 0) {
1387                         dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n",
1388                                 dai->name, ret);
1389                         return ret;
1390                 }
1391         }
1392
1393         dai->probed = 1;
1394
1395         return 0;
1396 }
1397
1398 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
1399                                 struct snd_soc_pcm_runtime *rtd)
1400 {
1401         int i, ret = 0;
1402
1403         for (i = 0; i < num_dais; ++i) {
1404                 struct snd_soc_dai_driver *drv = dais[i]->driver;
1405
1406                 if (!rtd->dai_link->no_pcm && drv->pcm_new)
1407                         ret = drv->pcm_new(rtd, dais[i]);
1408                 if (ret < 0) {
1409                         dev_err(dais[i]->dev,
1410                                 "ASoC: Failed to bind %s with pcm device\n",
1411                                 dais[i]->name);
1412                         return ret;
1413                 }
1414         }
1415
1416         return 0;
1417 }
1418
1419 static int soc_link_dai_widgets(struct snd_soc_card *card,
1420                                 struct snd_soc_dai_link *dai_link,
1421                                 struct snd_soc_pcm_runtime *rtd)
1422 {
1423         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1424         struct snd_soc_dai *codec_dai = rtd->codec_dai;
1425         struct snd_soc_dapm_widget *sink, *source;
1426         int ret;
1427
1428         if (rtd->num_codecs > 1)
1429                 dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
1430
1431         /* link the DAI widgets */
1432         sink = codec_dai->playback_widget;
1433         source = cpu_dai->capture_widget;
1434         if (sink && source) {
1435                 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1436                                            dai_link->num_params,
1437                                            source, sink);
1438                 if (ret != 0) {
1439                         dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1440                                 sink->name, source->name, ret);
1441                         return ret;
1442                 }
1443         }
1444
1445         sink = cpu_dai->playback_widget;
1446         source = codec_dai->capture_widget;
1447         if (sink && source) {
1448                 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1449                                            dai_link->num_params,
1450                                            source, sink);
1451                 if (ret != 0) {
1452                         dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1453                                 sink->name, source->name, ret);
1454                         return ret;
1455                 }
1456         }
1457
1458         return 0;
1459 }
1460
1461 static int soc_probe_link_dais(struct snd_soc_card *card,
1462                 struct snd_soc_pcm_runtime *rtd, int order)
1463 {
1464         struct snd_soc_dai_link *dai_link = rtd->dai_link;
1465         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1466         int i, ret;
1467
1468         dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1469                         card->name, rtd->num, order);
1470
1471         /* set default power off timeout */
1472         rtd->pmdown_time = pmdown_time;
1473
1474         ret = soc_probe_dai(cpu_dai, order);
1475         if (ret)
1476                 return ret;
1477
1478         /* probe the CODEC DAI */
1479         for (i = 0; i < rtd->num_codecs; i++) {
1480                 ret = soc_probe_dai(rtd->codec_dais[i], order);
1481                 if (ret)
1482                         return ret;
1483         }
1484
1485         /* complete DAI probe during last probe */
1486         if (order != SND_SOC_COMP_ORDER_LAST)
1487                 return 0;
1488
1489         /* do machine specific initialization */
1490         if (dai_link->init) {
1491                 ret = dai_link->init(rtd);
1492                 if (ret < 0) {
1493                         dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1494                                 dai_link->name, ret);
1495                         return ret;
1496                 }
1497         }
1498
1499         if (dai_link->dai_fmt)
1500                 snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1501
1502         ret = soc_post_component_init(rtd, dai_link->name);
1503         if (ret)
1504                 return ret;
1505
1506 #ifdef CONFIG_DEBUG_FS
1507         /* add DPCM sysfs entries */
1508         if (dai_link->dynamic)
1509                 soc_dpcm_debugfs_add(rtd);
1510 #endif
1511
1512         if (cpu_dai->driver->compress_new) {
1513                 /*create compress_device"*/
1514                 ret = cpu_dai->driver->compress_new(rtd, rtd->num);
1515                 if (ret < 0) {
1516                         dev_err(card->dev, "ASoC: can't create compress %s\n",
1517                                          dai_link->stream_name);
1518                         return ret;
1519                 }
1520         } else {
1521
1522                 if (!dai_link->params) {
1523                         /* create the pcm */
1524                         ret = soc_new_pcm(rtd, rtd->num);
1525                         if (ret < 0) {
1526                                 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1527                                        dai_link->stream_name, ret);
1528                                 return ret;
1529                         }
1530                         ret = soc_link_dai_pcm_new(&cpu_dai, 1, rtd);
1531                         if (ret < 0)
1532                                 return ret;
1533                         ret = soc_link_dai_pcm_new(rtd->codec_dais,
1534                                                    rtd->num_codecs, rtd);
1535                         if (ret < 0)
1536                                 return ret;
1537                 } else {
1538                         INIT_DELAYED_WORK(&rtd->delayed_work,
1539                                                 codec2codec_close_delayed_work);
1540
1541                         /* link the DAI widgets */
1542                         ret = soc_link_dai_widgets(card, dai_link, rtd);
1543                         if (ret)
1544                                 return ret;
1545                 }
1546         }
1547
1548         return 0;
1549 }
1550
1551 static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1552 {
1553         struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1554         struct snd_soc_component *component;
1555         const char *name;
1556         struct device_node *codec_of_node;
1557
1558         if (aux_dev->codec_of_node || aux_dev->codec_name) {
1559                 /* codecs, usually analog devices */
1560                 name = aux_dev->codec_name;
1561                 codec_of_node = aux_dev->codec_of_node;
1562                 component = soc_find_component(codec_of_node, name);
1563                 if (!component) {
1564                         if (codec_of_node)
1565                                 name = of_node_full_name(codec_of_node);
1566                         goto err_defer;
1567                 }
1568         } else if (aux_dev->name) {
1569                 /* generic components */
1570                 name = aux_dev->name;
1571                 component = soc_find_component(NULL, name);
1572                 if (!component)
1573                         goto err_defer;
1574         } else {
1575                 dev_err(card->dev, "ASoC: Invalid auxiliary device\n");
1576                 return -EINVAL;
1577         }
1578
1579         component->init = aux_dev->init;
1580         list_add(&component->card_aux_list, &card->aux_comp_list);
1581
1582         return 0;
1583
1584 err_defer:
1585         dev_err(card->dev, "ASoC: %s not registered\n", name);
1586         return -EPROBE_DEFER;
1587 }
1588
1589 static int soc_probe_aux_devices(struct snd_soc_card *card)
1590 {
1591         struct snd_soc_component *comp;
1592         int order;
1593         int ret;
1594
1595         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1596                 order++) {
1597                 list_for_each_entry(comp, &card->aux_comp_list, card_aux_list) {
1598                         if (comp->driver->probe_order == order) {
1599                                 ret = soc_probe_component(card, comp);
1600                                 if (ret < 0) {
1601                                         dev_err(card->dev,
1602                                                 "ASoC: failed to probe aux component %s %d\n",
1603                                                 comp->name, ret);
1604                                         return ret;
1605                                 }
1606                         }
1607                 }
1608         }
1609
1610         return 0;
1611 }
1612
1613 static void soc_remove_aux_devices(struct snd_soc_card *card)
1614 {
1615         struct snd_soc_component *comp, *_comp;
1616         int order;
1617
1618         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1619                 order++) {
1620                 list_for_each_entry_safe(comp, _comp,
1621                         &card->aux_comp_list, card_aux_list) {
1622
1623                         if (comp->driver->remove_order == order) {
1624                                 soc_remove_component(comp);
1625                                 /* remove it from the card's aux_comp_list */
1626                                 list_del(&comp->card_aux_list);
1627                         }
1628                 }
1629         }
1630 }
1631
1632 /**
1633  * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1634  * @rtd: The runtime for which the DAI link format should be changed
1635  * @dai_fmt: The new DAI link format
1636  *
1637  * This function updates the DAI link format for all DAIs connected to the DAI
1638  * link for the specified runtime.
1639  *
1640  * Note: For setups with a static format set the dai_fmt field in the
1641  * corresponding snd_dai_link struct instead of using this function.
1642  *
1643  * Returns 0 on success, otherwise a negative error code.
1644  */
1645 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1646         unsigned int dai_fmt)
1647 {
1648         struct snd_soc_dai **codec_dais = rtd->codec_dais;
1649         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1650         unsigned int i;
1651         int ret;
1652
1653         for (i = 0; i < rtd->num_codecs; i++) {
1654                 struct snd_soc_dai *codec_dai = codec_dais[i];
1655
1656                 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1657                 if (ret != 0 && ret != -ENOTSUPP) {
1658                         dev_warn(codec_dai->dev,
1659                                  "ASoC: Failed to set DAI format: %d\n", ret);
1660                         return ret;
1661                 }
1662         }
1663
1664         /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
1665         /* the component which has non_legacy_dai_naming is Codec */
1666         if (cpu_dai->codec ||
1667             cpu_dai->component->driver->non_legacy_dai_naming) {
1668                 unsigned int inv_dai_fmt;
1669
1670                 inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1671                 switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1672                 case SND_SOC_DAIFMT_CBM_CFM:
1673                         inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1674                         break;
1675                 case SND_SOC_DAIFMT_CBM_CFS:
1676                         inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1677                         break;
1678                 case SND_SOC_DAIFMT_CBS_CFM:
1679                         inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1680                         break;
1681                 case SND_SOC_DAIFMT_CBS_CFS:
1682                         inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1683                         break;
1684                 }
1685
1686                 dai_fmt = inv_dai_fmt;
1687         }
1688
1689         ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1690         if (ret != 0 && ret != -ENOTSUPP) {
1691                 dev_warn(cpu_dai->dev,
1692                          "ASoC: Failed to set DAI format: %d\n", ret);
1693                 return ret;
1694         }
1695
1696         return 0;
1697 }
1698 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1699
1700
1701 #ifdef CONFIG_DMI
1702 /* Trim special characters, and replace '-' with '_' since '-' is used to
1703  * separate different DMI fields in the card long name. Only number and
1704  * alphabet characters and a few separator characters are kept.
1705  */
1706 static void cleanup_dmi_name(char *name)
1707 {
1708         int i, j = 0;
1709
1710         for (i = 0; name[i]; i++) {
1711                 if (isalnum(name[i]) || (name[i] == '.')
1712                     || (name[i] == '_'))
1713                         name[j++] = name[i];
1714                 else if (name[i] == '-')
1715                         name[j++] = '_';
1716         }
1717
1718         name[j] = '\0';
1719 }
1720
1721 /* Check if a DMI field is valid, i.e. not containing any string
1722  * in the black list.
1723  */
1724 static int is_dmi_valid(const char *field)
1725 {
1726         int i = 0;
1727
1728         while (dmi_blacklist[i]) {
1729                 if (strstr(field, dmi_blacklist[i]))
1730                         return 0;
1731                 i++;
1732         }
1733
1734         return 1;
1735 }
1736
1737 /**
1738  * snd_soc_set_dmi_name() - Register DMI names to card
1739  * @card: The card to register DMI names
1740  * @flavour: The flavour "differentiator" for the card amongst its peers.
1741  *
1742  * An Intel machine driver may be used by many different devices but are
1743  * difficult for userspace to differentiate, since machine drivers ususally
1744  * use their own name as the card short name and leave the card long name
1745  * blank. To differentiate such devices and fix bugs due to lack of
1746  * device-specific configurations, this function allows DMI info to be used
1747  * as the sound card long name, in the format of
1748  * "vendor-product-version-board"
1749  * (Character '-' is used to separate different DMI fields here).
1750  * This will help the user space to load the device-specific Use Case Manager
1751  * (UCM) configurations for the card.
1752  *
1753  * Possible card long names may be:
1754  * DellInc.-XPS139343-01-0310JH
1755  * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
1756  * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
1757  *
1758  * This function also supports flavoring the card longname to provide
1759  * the extra differentiation, like "vendor-product-version-board-flavor".
1760  *
1761  * We only keep number and alphabet characters and a few separator characters
1762  * in the card long name since UCM in the user space uses the card long names
1763  * as card configuration directory names and AudoConf cannot support special
1764  * charactors like SPACE.
1765  *
1766  * Returns 0 on success, otherwise a negative error code.
1767  */
1768 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
1769 {
1770         const char *vendor, *product, *product_version, *board;
1771         size_t longname_buf_size = sizeof(card->snd_card->longname);
1772         size_t len;
1773
1774         if (card->long_name)
1775                 return 0; /* long name already set by driver or from DMI */
1776
1777         /* make up dmi long name as: vendor.product.version.board */
1778         vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1779         if (!vendor || !is_dmi_valid(vendor)) {
1780                 dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
1781                 return 0;
1782         }
1783
1784
1785         snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
1786                          "%s", vendor);
1787         cleanup_dmi_name(card->dmi_longname);
1788
1789         product = dmi_get_system_info(DMI_PRODUCT_NAME);
1790         if (product && is_dmi_valid(product)) {
1791                 len = strlen(card->dmi_longname);
1792                 snprintf(card->dmi_longname + len,
1793                          longname_buf_size - len,
1794                          "-%s", product);
1795
1796                 len++;  /* skip the separator "-" */
1797                 if (len < longname_buf_size)
1798                         cleanup_dmi_name(card->dmi_longname + len);
1799
1800                 /* some vendors like Lenovo may only put a self-explanatory
1801                  * name in the product version field
1802                  */
1803                 product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
1804                 if (product_version && is_dmi_valid(product_version)) {
1805                         len = strlen(card->dmi_longname);
1806                         snprintf(card->dmi_longname + len,
1807                                  longname_buf_size - len,
1808                                  "-%s", product_version);
1809
1810                         len++;
1811                         if (len < longname_buf_size)
1812                                 cleanup_dmi_name(card->dmi_longname + len);
1813                 }
1814         }
1815
1816         board = dmi_get_system_info(DMI_BOARD_NAME);
1817         if (board && is_dmi_valid(board)) {
1818                 len = strlen(card->dmi_longname);
1819                 snprintf(card->dmi_longname + len,
1820                          longname_buf_size - len,
1821                          "-%s", board);
1822
1823                 len++;
1824                 if (len < longname_buf_size)
1825                         cleanup_dmi_name(card->dmi_longname + len);
1826         } else if (!product) {
1827                 /* fall back to using legacy name */
1828                 dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
1829                 return 0;
1830         }
1831
1832         /* Add flavour to dmi long name */
1833         if (flavour) {
1834                 len = strlen(card->dmi_longname);
1835                 snprintf(card->dmi_longname + len,
1836                          longname_buf_size - len,
1837                          "-%s", flavour);
1838
1839                 len++;
1840                 if (len < longname_buf_size)
1841                         cleanup_dmi_name(card->dmi_longname + len);
1842         }
1843
1844         /* set the card long name */
1845         card->long_name = card->dmi_longname;
1846
1847         return 0;
1848 }
1849 EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
1850 #endif /* CONFIG_DMI */
1851
1852 static int snd_soc_instantiate_card(struct snd_soc_card *card)
1853 {
1854         struct snd_soc_pcm_runtime *rtd;
1855         struct snd_soc_dai_link *dai_link;
1856         int ret, i, order;
1857
1858         mutex_lock(&client_mutex);
1859         mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1860
1861         /* bind DAIs */
1862         for (i = 0; i < card->num_links; i++) {
1863                 ret = soc_bind_dai_link(card, &card->dai_link[i]);
1864                 if (ret != 0)
1865                         goto base_error;
1866         }
1867
1868         /* bind aux_devs too */
1869         for (i = 0; i < card->num_aux_devs; i++) {
1870                 ret = soc_bind_aux_dev(card, i);
1871                 if (ret != 0)
1872                         goto base_error;
1873         }
1874
1875         /* add predefined DAI links to the list */
1876         for (i = 0; i < card->num_links; i++)
1877                 snd_soc_add_dai_link(card, card->dai_link+i);
1878
1879         /* card bind complete so register a sound card */
1880         ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1881                         card->owner, 0, &card->snd_card);
1882         if (ret < 0) {
1883                 dev_err(card->dev,
1884                         "ASoC: can't create sound card for card %s: %d\n",
1885                         card->name, ret);
1886                 goto base_error;
1887         }
1888
1889         soc_init_card_debugfs(card);
1890
1891         card->dapm.bias_level = SND_SOC_BIAS_OFF;
1892         card->dapm.dev = card->dev;
1893         card->dapm.card = card;
1894         list_add(&card->dapm.list, &card->dapm_list);
1895
1896 #ifdef CONFIG_DEBUG_FS
1897         snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1898 #endif
1899
1900 #ifdef CONFIG_PM_SLEEP
1901         /* deferred resume work */
1902         INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1903 #endif
1904
1905         if (card->dapm_widgets)
1906                 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1907                                           card->num_dapm_widgets);
1908
1909         if (card->of_dapm_widgets)
1910                 snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
1911                                           card->num_of_dapm_widgets);
1912
1913         /* initialise the sound card only once */
1914         if (card->probe) {
1915                 ret = card->probe(card);
1916                 if (ret < 0)
1917                         goto card_probe_error;
1918         }
1919
1920         /* probe all components used by DAI links on this card */
1921         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1922                         order++) {
1923                 list_for_each_entry(rtd, &card->rtd_list, list) {
1924                         ret = soc_probe_link_components(card, rtd, order);
1925                         if (ret < 0) {
1926                                 dev_err(card->dev,
1927                                         "ASoC: failed to instantiate card %d\n",
1928                                         ret);
1929                                 goto probe_dai_err;
1930                         }
1931                 }
1932         }
1933
1934         /* probe auxiliary components */
1935         ret = soc_probe_aux_devices(card);
1936         if (ret < 0)
1937                 goto probe_dai_err;
1938
1939         /* Find new DAI links added during probing components and bind them.
1940          * Components with topology may bring new DAIs and DAI links.
1941          */
1942         list_for_each_entry(dai_link, &card->dai_link_list, list) {
1943                 if (soc_is_dai_link_bound(card, dai_link))
1944                         continue;
1945
1946                 ret = soc_init_dai_link(card, dai_link);
1947                 if (ret)
1948                         goto probe_dai_err;
1949                 ret = soc_bind_dai_link(card, dai_link);
1950                 if (ret)
1951                         goto probe_dai_err;
1952         }
1953
1954         /* probe all DAI links on this card */
1955         for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1956                         order++) {
1957                 list_for_each_entry(rtd, &card->rtd_list, list) {
1958                         ret = soc_probe_link_dais(card, rtd, order);
1959                         if (ret < 0) {
1960                                 dev_err(card->dev,
1961                                         "ASoC: failed to instantiate card %d\n",
1962                                         ret);
1963                                 goto probe_dai_err;
1964                         }
1965                 }
1966         }
1967
1968         snd_soc_dapm_link_dai_widgets(card);
1969         snd_soc_dapm_connect_dai_link_widgets(card);
1970
1971         if (card->controls)
1972                 snd_soc_add_card_controls(card, card->controls, card->num_controls);
1973
1974         if (card->dapm_routes)
1975                 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1976                                         card->num_dapm_routes);
1977
1978         if (card->of_dapm_routes)
1979                 snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
1980                                         card->num_of_dapm_routes);
1981
1982         /* try to set some sane longname if DMI is available */
1983         snd_soc_set_dmi_name(card, NULL);
1984
1985         snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1986                  "%s", card->name);
1987         snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1988                  "%s", card->long_name ? card->long_name : card->name);
1989         snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1990                  "%s", card->driver_name ? card->driver_name : card->name);
1991         for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1992                 switch (card->snd_card->driver[i]) {
1993                 case '_':
1994                 case '-':
1995                 case '\0':
1996                         break;
1997                 default:
1998                         if (!isalnum(card->snd_card->driver[i]))
1999                                 card->snd_card->driver[i] = '_';
2000                         break;
2001                 }
2002         }
2003
2004         if (card->late_probe) {
2005                 ret = card->late_probe(card);
2006                 if (ret < 0) {
2007                         dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
2008                                 card->name, ret);
2009                         goto probe_aux_dev_err;
2010                 }
2011         }
2012
2013         snd_soc_dapm_new_widgets(card);
2014
2015         ret = snd_card_register(card->snd_card);
2016         if (ret < 0) {
2017                 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
2018                                 ret);
2019                 goto probe_aux_dev_err;
2020         }
2021
2022         card->instantiated = 1;
2023         snd_soc_dapm_sync(&card->dapm);
2024         mutex_unlock(&card->mutex);
2025         mutex_unlock(&client_mutex);
2026
2027         return 0;
2028
2029 probe_aux_dev_err:
2030         soc_remove_aux_devices(card);
2031
2032 probe_dai_err:
2033         soc_remove_dai_links(card);
2034
2035 card_probe_error:
2036         if (card->remove)
2037                 card->remove(card);
2038
2039         snd_soc_dapm_free(&card->dapm);
2040         soc_cleanup_card_debugfs(card);
2041         snd_card_free(card->snd_card);
2042
2043 base_error:
2044         soc_remove_pcm_runtimes(card);
2045         mutex_unlock(&card->mutex);
2046         mutex_unlock(&client_mutex);
2047
2048         return ret;
2049 }
2050
2051 /* probes a new socdev */
2052 static int soc_probe(struct platform_device *pdev)
2053 {
2054         struct snd_soc_card *card = platform_get_drvdata(pdev);
2055
2056         /*
2057          * no card, so machine driver should be registering card
2058          * we should not be here in that case so ret error
2059          */
2060         if (!card)
2061                 return -EINVAL;
2062
2063         dev_warn(&pdev->dev,
2064                  "ASoC: machine %s should use snd_soc_register_card()\n",
2065                  card->name);
2066
2067         /* Bodge while we unpick instantiation */
2068         card->dev = &pdev->dev;
2069
2070         return snd_soc_register_card(card);
2071 }
2072
2073 static int soc_cleanup_card_resources(struct snd_soc_card *card)
2074 {
2075         struct snd_soc_pcm_runtime *rtd;
2076
2077         /* make sure any delayed work runs */
2078         list_for_each_entry(rtd, &card->rtd_list, list)
2079                 flush_delayed_work(&rtd->delayed_work);
2080
2081         /* free the ALSA card at first; this syncs with pending operations */
2082         snd_card_free(card->snd_card);
2083
2084         /* remove and free each DAI */
2085         soc_remove_dai_links(card);
2086         soc_remove_pcm_runtimes(card);
2087
2088         /* remove auxiliary devices */
2089         soc_remove_aux_devices(card);
2090
2091         snd_soc_dapm_free(&card->dapm);
2092         soc_cleanup_card_debugfs(card);
2093
2094         /* remove the card */
2095         if (card->remove)
2096                 card->remove(card);
2097
2098         return 0;
2099 }
2100
2101 /* removes a socdev */
2102 static int soc_remove(struct platform_device *pdev)
2103 {
2104         struct snd_soc_card *card = platform_get_drvdata(pdev);
2105
2106         snd_soc_unregister_card(card);
2107         return 0;
2108 }
2109
2110 int snd_soc_poweroff(struct device *dev)
2111 {
2112         struct snd_soc_card *card = dev_get_drvdata(dev);
2113         struct snd_soc_pcm_runtime *rtd;
2114
2115         if (!card->instantiated)
2116                 return 0;
2117
2118         /* Flush out pmdown_time work - we actually do want to run it
2119          * now, we're shutting down so no imminent restart. */
2120         list_for_each_entry(rtd, &card->rtd_list, list)
2121                 flush_delayed_work(&rtd->delayed_work);
2122
2123         snd_soc_dapm_shutdown(card);
2124
2125         /* deactivate pins to sleep state */
2126         list_for_each_entry(rtd, &card->rtd_list, list) {
2127                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2128                 int i;
2129
2130                 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2131                 for (i = 0; i < rtd->num_codecs; i++) {
2132                         struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
2133                         pinctrl_pm_select_sleep_state(codec_dai->dev);
2134                 }
2135         }
2136
2137         return 0;
2138 }
2139 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
2140
2141 const struct dev_pm_ops snd_soc_pm_ops = {
2142         .suspend = snd_soc_suspend,
2143         .resume = snd_soc_resume,
2144         .freeze = snd_soc_suspend,
2145         .thaw = snd_soc_resume,
2146         .poweroff = snd_soc_poweroff,
2147         .restore = snd_soc_resume,
2148 };
2149 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
2150
2151 /* ASoC platform driver */
2152 static struct platform_driver soc_driver = {
2153         .driver         = {
2154                 .name           = "soc-audio",
2155                 .pm             = &snd_soc_pm_ops,
2156         },
2157         .probe          = soc_probe,
2158         .remove         = soc_remove,
2159 };
2160
2161 /**
2162  * snd_soc_cnew - create new control
2163  * @_template: control template
2164  * @data: control private data
2165  * @long_name: control long name
2166  * @prefix: control name prefix
2167  *
2168  * Create a new mixer control from a template control.
2169  *
2170  * Returns 0 for success, else error.
2171  */
2172 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2173                                   void *data, const char *long_name,
2174                                   const char *prefix)
2175 {
2176         struct snd_kcontrol_new template;
2177         struct snd_kcontrol *kcontrol;
2178         char *name = NULL;
2179
2180         memcpy(&template, _template, sizeof(template));
2181         template.index = 0;
2182
2183         if (!long_name)
2184                 long_name = template.name;
2185
2186         if (prefix) {
2187                 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2188                 if (!name)
2189                         return NULL;
2190
2191                 template.name = name;
2192         } else {
2193                 template.name = long_name;
2194         }
2195
2196         kcontrol = snd_ctl_new1(&template, data);
2197
2198         kfree(name);
2199
2200         return kcontrol;
2201 }
2202 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2203
2204 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2205         const struct snd_kcontrol_new *controls, int num_controls,
2206         const char *prefix, void *data)
2207 {
2208         int err, i;
2209
2210         for (i = 0; i < num_controls; i++) {
2211                 const struct snd_kcontrol_new *control = &controls[i];
2212                 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2213                                                      control->name, prefix));
2214                 if (err < 0) {
2215                         dev_err(dev, "ASoC: Failed to add %s: %d\n",
2216                                 control->name, err);
2217                         return err;
2218                 }
2219         }
2220
2221         return 0;
2222 }
2223
2224 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2225                                                const char *name)
2226 {
2227         struct snd_card *card = soc_card->snd_card;
2228         struct snd_kcontrol *kctl;
2229
2230         if (unlikely(!name))
2231                 return NULL;
2232
2233         list_for_each_entry(kctl, &card->controls, list)
2234                 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2235                         return kctl;
2236         return NULL;
2237 }
2238 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2239
2240 /**
2241  * snd_soc_add_component_controls - Add an array of controls to a component.
2242  *
2243  * @component: Component to add controls to
2244  * @controls: Array of controls to add
2245  * @num_controls: Number of elements in the array
2246  *
2247  * Return: 0 for success, else error.
2248  */
2249 int snd_soc_add_component_controls(struct snd_soc_component *component,
2250         const struct snd_kcontrol_new *controls, unsigned int num_controls)
2251 {
2252         struct snd_card *card = component->card->snd_card;
2253
2254         return snd_soc_add_controls(card, component->dev, controls,
2255                         num_controls, component->name_prefix, component);
2256 }
2257 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
2258
2259 /**
2260  * snd_soc_add_codec_controls - add an array of controls to a codec.
2261  * Convenience function to add a list of controls. Many codecs were
2262  * duplicating this code.
2263  *
2264  * @codec: codec to add controls to
2265  * @controls: array of controls to add
2266  * @num_controls: number of elements in the array
2267  *
2268  * Return 0 for success, else error.
2269  */
2270 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2271         const struct snd_kcontrol_new *controls, unsigned int num_controls)
2272 {
2273         return snd_soc_add_component_controls(&codec->component, controls,
2274                 num_controls);
2275 }
2276 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2277
2278 /**
2279  * snd_soc_add_card_controls - add an array of controls to a SoC card.
2280  * Convenience function to add a list of controls.
2281  *
2282  * @soc_card: SoC card to add controls to
2283  * @controls: array of controls to add
2284  * @num_controls: number of elements in the array
2285  *
2286  * Return 0 for success, else error.
2287  */
2288 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2289         const struct snd_kcontrol_new *controls, int num_controls)
2290 {
2291         struct snd_card *card = soc_card->snd_card;
2292
2293         return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2294                         NULL, soc_card);
2295 }
2296 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2297
2298 /**
2299  * snd_soc_add_dai_controls - add an array of controls to a DAI.
2300  * Convienience function to add a list of controls.
2301  *
2302  * @dai: DAI to add controls to
2303  * @controls: array of controls to add
2304  * @num_controls: number of elements in the array
2305  *
2306  * Return 0 for success, else error.
2307  */
2308 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2309         const struct snd_kcontrol_new *controls, int num_controls)
2310 {
2311         struct snd_card *card = dai->component->card->snd_card;
2312
2313         return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2314                         NULL, dai);
2315 }
2316 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2317
2318 /**
2319  * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2320  * @dai: DAI
2321  * @clk_id: DAI specific clock ID
2322  * @freq: new clock frequency in Hz
2323  * @dir: new clock direction - input/output.
2324  *
2325  * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2326  */
2327 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2328         unsigned int freq, int dir)
2329 {
2330         if (dai->driver->ops->set_sysclk)
2331                 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2332
2333         return snd_soc_component_set_sysclk(dai->component, clk_id, 0,
2334                                             freq, dir);
2335 }
2336 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2337
2338 /**
2339  * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2340  * @codec: CODEC
2341  * @clk_id: DAI specific clock ID
2342  * @source: Source for the clock
2343  * @freq: new clock frequency in Hz
2344  * @dir: new clock direction - input/output.
2345  *
2346  * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2347  */
2348 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2349                              int source, unsigned int freq, int dir)
2350 {
2351         if (codec->driver->set_sysclk)
2352                 return codec->driver->set_sysclk(codec, clk_id, source,
2353                                                  freq, dir);
2354         else
2355                 return -ENOTSUPP;
2356 }
2357 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2358
2359 /**
2360  * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
2361  * @component: COMPONENT
2362  * @clk_id: DAI specific clock ID
2363  * @source: Source for the clock
2364  * @freq: new clock frequency in Hz
2365  * @dir: new clock direction - input/output.
2366  *
2367  * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2368  */
2369 int snd_soc_component_set_sysclk(struct snd_soc_component *component, int clk_id,
2370                              int source, unsigned int freq, int dir)
2371 {
2372         /* will be removed */
2373         if (component->set_sysclk)
2374                 return component->set_sysclk(component, clk_id, source,
2375                                              freq, dir);
2376
2377         if (component->driver->set_sysclk)
2378                 return component->driver->set_sysclk(component, clk_id, source,
2379                                                  freq, dir);
2380
2381         return -ENOTSUPP;
2382 }
2383 EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
2384
2385 /**
2386  * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2387  * @dai: DAI
2388  * @div_id: DAI specific clock divider ID
2389  * @div: new clock divisor.
2390  *
2391  * Configures the clock dividers. This is used to derive the best DAI bit and
2392  * frame clocks from the system or master clock. It's best to set the DAI bit
2393  * and frame clocks as low as possible to save system power.
2394  */
2395 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2396         int div_id, int div)
2397 {
2398         if (dai->driver->ops->set_clkdiv)
2399                 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2400         else
2401                 return -EINVAL;
2402 }
2403 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2404
2405 /**
2406  * snd_soc_dai_set_pll - configure DAI PLL.
2407  * @dai: DAI
2408  * @pll_id: DAI specific PLL ID
2409  * @source: DAI specific source for the PLL
2410  * @freq_in: PLL input clock frequency in Hz
2411  * @freq_out: requested PLL output clock frequency in Hz
2412  *
2413  * Configures and enables PLL to generate output clock based on input clock.
2414  */
2415 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2416         unsigned int freq_in, unsigned int freq_out)
2417 {
2418         if (dai->driver->ops->set_pll)
2419                 return dai->driver->ops->set_pll(dai, pll_id, source,
2420                                          freq_in, freq_out);
2421
2422         return snd_soc_component_set_pll(dai->component, pll_id, source,
2423                                          freq_in, freq_out);
2424 }
2425 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2426
2427 /*
2428  * snd_soc_codec_set_pll - configure codec PLL.
2429  * @codec: CODEC
2430  * @pll_id: DAI specific PLL ID
2431  * @source: DAI specific source for the PLL
2432  * @freq_in: PLL input clock frequency in Hz
2433  * @freq_out: requested PLL output clock frequency in Hz
2434  *
2435  * Configures and enables PLL to generate output clock based on input clock.
2436  */
2437 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2438                           unsigned int freq_in, unsigned int freq_out)
2439 {
2440         if (codec->driver->set_pll)
2441                 return codec->driver->set_pll(codec, pll_id, source,
2442                                               freq_in, freq_out);
2443         else
2444                 return -EINVAL;
2445 }
2446 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2447
2448 /*
2449  * snd_soc_component_set_pll - configure component PLL.
2450  * @component: COMPONENT
2451  * @pll_id: DAI specific PLL ID
2452  * @source: DAI specific source for the PLL
2453  * @freq_in: PLL input clock frequency in Hz
2454  * @freq_out: requested PLL output clock frequency in Hz
2455  *
2456  * Configures and enables PLL to generate output clock based on input clock.
2457  */
2458 int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
2459                               int source, unsigned int freq_in,
2460                               unsigned int freq_out)
2461 {
2462         /* will be removed */
2463         if (component->set_pll)
2464                 return component->set_pll(component, pll_id, source,
2465                                               freq_in, freq_out);
2466
2467         if (component->driver->set_pll)
2468                 return component->driver->set_pll(component, pll_id, source,
2469                                               freq_in, freq_out);
2470
2471         return -EINVAL;
2472 }
2473 EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
2474
2475 /**
2476  * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
2477  * @dai: DAI
2478  * @ratio: Ratio of BCLK to Sample rate.
2479  *
2480  * Configures the DAI for a preset BCLK to sample rate ratio.
2481  */
2482 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2483 {
2484         if (dai->driver->ops->set_bclk_ratio)
2485                 return dai->driver->ops->set_bclk_ratio(dai, ratio);
2486         else
2487                 return -EINVAL;
2488 }
2489 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
2490
2491 /**
2492  * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2493  * @dai: DAI
2494  * @fmt: SND_SOC_DAIFMT_* format value.
2495  *
2496  * Configures the DAI hardware format and clocking.
2497  */
2498 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2499 {
2500         if (dai->driver == NULL)
2501                 return -EINVAL;
2502         if (dai->driver->ops->set_fmt == NULL)
2503                 return -ENOTSUPP;
2504         return dai->driver->ops->set_fmt(dai, fmt);
2505 }
2506 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2507
2508 /**
2509  * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
2510  * @slots: Number of slots in use.
2511  * @tx_mask: bitmask representing active TX slots.
2512  * @rx_mask: bitmask representing active RX slots.
2513  *
2514  * Generates the TDM tx and rx slot default masks for DAI.
2515  */
2516 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2517                                           unsigned int *tx_mask,
2518                                           unsigned int *rx_mask)
2519 {
2520         if (*tx_mask || *rx_mask)
2521                 return 0;
2522
2523         if (!slots)
2524                 return -EINVAL;
2525
2526         *tx_mask = (1 << slots) - 1;
2527         *rx_mask = (1 << slots) - 1;
2528
2529         return 0;
2530 }
2531
2532 /**
2533  * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
2534  * @dai: The DAI to configure
2535  * @tx_mask: bitmask representing active TX slots.
2536  * @rx_mask: bitmask representing active RX slots.
2537  * @slots: Number of slots in use.
2538  * @slot_width: Width in bits for each slot.
2539  *
2540  * This function configures the specified DAI for TDM operation. @slot contains
2541  * the total number of slots of the TDM stream and @slot_with the width of each
2542  * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
2543  * active slots of the TDM stream for the specified DAI, i.e. which slots the
2544  * DAI should write to or read from. If a bit is set the corresponding slot is
2545  * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
2546  * the first slot, bit 1 to the second slot and so on. The first active slot
2547  * maps to the first channel of the DAI, the second active slot to the second
2548  * channel and so on.
2549  *
2550  * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
2551  * @rx_mask and @slot_width will be ignored.
2552  *
2553  * Returns 0 on success, a negative error code otherwise.
2554  */
2555 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2556         unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2557 {
2558         if (dai->driver->ops->xlate_tdm_slot_mask)
2559                 dai->driver->ops->xlate_tdm_slot_mask(slots,
2560                                                 &tx_mask, &rx_mask);
2561         else
2562                 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
2563
2564         dai->tx_mask = tx_mask;
2565         dai->rx_mask = rx_mask;
2566
2567         if (dai->driver->ops->set_tdm_slot)
2568                 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2569                                 slots, slot_width);
2570         else
2571                 return -ENOTSUPP;
2572 }
2573 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2574
2575 /**
2576  * snd_soc_dai_set_channel_map - configure DAI audio channel map
2577  * @dai: DAI
2578  * @tx_num: how many TX channels
2579  * @tx_slot: pointer to an array which imply the TX slot number channel
2580  *           0~num-1 uses
2581  * @rx_num: how many RX channels
2582  * @rx_slot: pointer to an array which imply the RX slot number channel
2583  *           0~num-1 uses
2584  *
2585  * configure the relationship between channel number and TDM slot number.
2586  */
2587 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2588         unsigned int tx_num, unsigned int *tx_slot,
2589         unsigned int rx_num, unsigned int *rx_slot)
2590 {
2591         if (dai->driver->ops->set_channel_map)
2592                 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2593                         rx_num, rx_slot);
2594         else
2595                 return -EINVAL;
2596 }
2597 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2598
2599 /**
2600  * snd_soc_dai_set_tristate - configure DAI system or master clock.
2601  * @dai: DAI
2602  * @tristate: tristate enable
2603  *
2604  * Tristates the DAI so that others can use it.
2605  */
2606 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2607 {
2608         if (dai->driver->ops->set_tristate)
2609                 return dai->driver->ops->set_tristate(dai, tristate);
2610         else
2611                 return -EINVAL;
2612 }
2613 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2614
2615 /**
2616  * snd_soc_dai_digital_mute - configure DAI system or master clock.
2617  * @dai: DAI
2618  * @mute: mute enable
2619  * @direction: stream to mute
2620  *
2621  * Mutes the DAI DAC.
2622  */
2623 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
2624                              int direction)
2625 {
2626         if (!dai->driver)
2627                 return -ENOTSUPP;
2628
2629         if (dai->driver->ops->mute_stream)
2630                 return dai->driver->ops->mute_stream(dai, mute, direction);
2631         else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
2632                  dai->driver->ops->digital_mute)
2633                 return dai->driver->ops->digital_mute(dai, mute);
2634         else
2635                 return -ENOTSUPP;
2636 }
2637 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2638
2639 /**
2640  * snd_soc_register_card - Register a card with the ASoC core
2641  *
2642  * @card: Card to register
2643  *
2644  */
2645 int snd_soc_register_card(struct snd_soc_card *card)
2646 {
2647         int i, ret;
2648         struct snd_soc_pcm_runtime *rtd;
2649
2650         if (!card->name || !card->dev)
2651                 return -EINVAL;
2652
2653         for (i = 0; i < card->num_links; i++) {
2654                 struct snd_soc_dai_link *link = &card->dai_link[i];
2655
2656                 ret = soc_init_dai_link(card, link);
2657                 if (ret) {
2658                         dev_err(card->dev, "ASoC: failed to init link %s\n",
2659                                 link->name);
2660                         return ret;
2661                 }
2662         }
2663
2664         dev_set_drvdata(card->dev, card);
2665
2666         snd_soc_initialize_card_lists(card);
2667
2668         INIT_LIST_HEAD(&card->dai_link_list);
2669         card->num_dai_links = 0;
2670
2671         INIT_LIST_HEAD(&card->rtd_list);
2672         card->num_rtd = 0;
2673
2674         INIT_LIST_HEAD(&card->dapm_dirty);
2675         INIT_LIST_HEAD(&card->dobj_list);
2676         card->instantiated = 0;
2677         mutex_init(&card->mutex);
2678         mutex_init(&card->dapm_mutex);
2679
2680         ret = snd_soc_instantiate_card(card);
2681         if (ret != 0)
2682                 return ret;
2683
2684         /* deactivate pins to sleep state */
2685         list_for_each_entry(rtd, &card->rtd_list, list)  {
2686                 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2687                 int j;
2688
2689                 for (j = 0; j < rtd->num_codecs; j++) {
2690                         struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
2691                         if (!codec_dai->active)
2692                                 pinctrl_pm_select_sleep_state(codec_dai->dev);
2693                 }
2694
2695                 if (!cpu_dai->active)
2696                         pinctrl_pm_select_sleep_state(cpu_dai->dev);
2697         }
2698
2699         return ret;
2700 }
2701 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2702
2703 /**
2704  * snd_soc_unregister_card - Unregister a card with the ASoC core
2705  *
2706  * @card: Card to unregister
2707  *
2708  */
2709 int snd_soc_unregister_card(struct snd_soc_card *card)
2710 {
2711         if (card->instantiated) {
2712                 card->instantiated = false;
2713                 snd_soc_dapm_shutdown(card);
2714                 soc_cleanup_card_resources(card);
2715                 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2716         }
2717
2718         return 0;
2719 }
2720 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2721
2722 /*
2723  * Simplify DAI link configuration by removing ".-1" from device names
2724  * and sanitizing names.
2725  */
2726 static char *fmt_single_name(struct device *dev, int *id)
2727 {
2728         char *found, name[NAME_SIZE];
2729         int id1, id2;
2730
2731         if (dev_name(dev) == NULL)
2732                 return NULL;
2733
2734         strlcpy(name, dev_name(dev), NAME_SIZE);
2735
2736         /* are we a "%s.%d" name (platform and SPI components) */
2737         found = strstr(name, dev->driver->name);
2738         if (found) {
2739                 /* get ID */
2740                 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2741
2742                         /* discard ID from name if ID == -1 */
2743                         if (*id == -1)
2744                                 found[strlen(dev->driver->name)] = '\0';
2745                 }
2746
2747         } else {
2748                 /* I2C component devices are named "bus-addr"  */
2749                 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2750                         char tmp[NAME_SIZE];
2751
2752                         /* create unique ID number from I2C addr and bus */
2753                         *id = ((id1 & 0xffff) << 16) + id2;
2754
2755                         /* sanitize component name for DAI link creation */
2756                         snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2757                         strlcpy(name, tmp, NAME_SIZE);
2758                 } else
2759                         *id = 0;
2760         }
2761
2762         return kstrdup(name, GFP_KERNEL);
2763 }
2764
2765 /*
2766  * Simplify DAI link naming for single devices with multiple DAIs by removing
2767  * any ".-1" and using the DAI name (instead of device name).
2768  */
2769 static inline char *fmt_multiple_name(struct device *dev,
2770                 struct snd_soc_dai_driver *dai_drv)
2771 {
2772         if (dai_drv->name == NULL) {
2773                 dev_err(dev,
2774                         "ASoC: error - multiple DAI %s registered with no name\n",
2775                         dev_name(dev));
2776                 return NULL;
2777         }
2778
2779         return kstrdup(dai_drv->name, GFP_KERNEL);
2780 }
2781
2782 /**
2783  * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
2784  *
2785  * @component: The component for which the DAIs should be unregistered
2786  */
2787 static void snd_soc_unregister_dais(struct snd_soc_component *component)
2788 {
2789         struct snd_soc_dai *dai, *_dai;
2790
2791         list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
2792                 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
2793                         dai->name);
2794                 list_del(&dai->list);
2795                 kfree(dai->name);
2796                 kfree(dai);
2797         }
2798 }
2799
2800 /* Create a DAI and add it to the component's DAI list */
2801 static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
2802         struct snd_soc_dai_driver *dai_drv,
2803         bool legacy_dai_naming)
2804 {
2805         struct device *dev = component->dev;
2806         struct snd_soc_dai *dai;
2807
2808         dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
2809
2810         dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2811         if (dai == NULL)
2812                 return NULL;
2813
2814         /*
2815          * Back in the old days when we still had component-less DAIs,
2816          * instead of having a static name, component-less DAIs would
2817          * inherit the name of the parent device so it is possible to
2818          * register multiple instances of the DAI. We still need to keep
2819          * the same naming style even though those DAIs are not
2820          * component-less anymore.
2821          */
2822         if (legacy_dai_naming &&
2823            (dai_drv->id == 0 || dai_drv->name == NULL)) {
2824                 dai->name = fmt_single_name(dev, &dai->id);
2825         } else {
2826                 dai->name = fmt_multiple_name(dev, dai_drv);
2827                 if (dai_drv->id)
2828                         dai->id = dai_drv->id;
2829                 else
2830                         dai->id = component->num_dai;
2831         }
2832         if (dai->name == NULL) {
2833                 kfree(dai);
2834                 return NULL;
2835         }
2836
2837         dai->component = component;
2838         dai->dev = dev;
2839         dai->driver = dai_drv;
2840         if (!dai->driver->ops)
2841                 dai->driver->ops = &null_dai_ops;
2842
2843         list_add_tail(&dai->list, &component->dai_list);
2844         component->num_dai++;
2845
2846         dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
2847         return dai;
2848 }
2849
2850 /**
2851  * snd_soc_register_dais - Register a DAI with the ASoC core
2852  *
2853  * @component: The component the DAIs are registered for
2854  * @dai_drv: DAI driver to use for the DAIs
2855  * @count: Number of DAIs
2856  * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
2857  *                     parent's name.
2858  */
2859 static int snd_soc_register_dais(struct snd_soc_component *component,
2860         struct snd_soc_dai_driver *dai_drv, size_t count,
2861         bool legacy_dai_naming)
2862 {
2863         struct device *dev = component->dev;
2864         struct snd_soc_dai *dai;
2865         unsigned int i;
2866         int ret;
2867
2868         dev_dbg(dev, "ASoC: dai register %s #%zu\n", dev_name(dev), count);
2869
2870         for (i = 0; i < count; i++) {
2871
2872                 dai = soc_add_dai(component, dai_drv + i,
2873                                 count == 1 && legacy_dai_naming);
2874                 if (dai == NULL) {
2875                         ret = -ENOMEM;
2876                         goto err;
2877                 }
2878         }
2879
2880         return 0;
2881
2882 err:
2883         snd_soc_unregister_dais(component);
2884
2885         return ret;
2886 }
2887
2888 /**
2889  * snd_soc_register_dai - Register a DAI dynamically & create its widgets
2890  *
2891  * @component: The component the DAIs are registered for
2892  * @dai_drv: DAI driver to use for the DAI
2893  *
2894  * Topology can use this API to register DAIs when probing a component.
2895  * These DAIs's widgets will be freed in the card cleanup and the DAIs
2896  * will be freed in the component cleanup.
2897  */
2898 int snd_soc_register_dai(struct snd_soc_component *component,
2899         struct snd_soc_dai_driver *dai_drv)
2900 {
2901         struct snd_soc_dapm_context *dapm =
2902                 snd_soc_component_get_dapm(component);
2903         struct snd_soc_dai *dai;
2904         int ret;
2905
2906         if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
2907                 dev_err(component->dev, "Invalid dai type %d\n",
2908                         dai_drv->dobj.type);
2909                 return -EINVAL;
2910         }
2911
2912         lockdep_assert_held(&client_mutex);
2913         dai = soc_add_dai(component, dai_drv, false);
2914         if (!dai)
2915                 return -ENOMEM;
2916
2917         /* Create the DAI widgets here. After adding DAIs, topology may
2918          * also add routes that need these widgets as source or sink.
2919          */
2920         ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
2921         if (ret != 0) {
2922                 dev_err(component->dev,
2923                         "Failed to create DAI widgets %d\n", ret);
2924         }
2925
2926         return ret;
2927 }
2928 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2929
2930 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
2931         enum snd_soc_dapm_type type, int subseq)
2932 {
2933         struct snd_soc_component *component = dapm->component;
2934
2935         component->driver->seq_notifier(component, type, subseq);
2936 }
2937
2938 static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
2939         int event)
2940 {
2941         struct snd_soc_component *component = dapm->component;
2942
2943         return component->driver->stream_event(component, event);
2944 }
2945
2946 static int snd_soc_component_drv_pcm_new(struct snd_soc_component *component,
2947                                         struct snd_soc_pcm_runtime *rtd)
2948 {
2949         if (component->driver->pcm_new)
2950                 return component->driver->pcm_new(rtd);
2951
2952         return 0;
2953 }
2954
2955 static void snd_soc_component_drv_pcm_free(struct snd_soc_component *component,
2956                                           struct snd_pcm *pcm)
2957 {
2958         if (component->driver->pcm_free)
2959                 component->driver->pcm_free(pcm);
2960 }
2961
2962 static int snd_soc_component_set_bias_level(struct snd_soc_dapm_context *dapm,
2963                                         enum snd_soc_bias_level level)
2964 {
2965         struct snd_soc_component *component = dapm->component;
2966
2967         return component->driver->set_bias_level(component, level);
2968 }
2969
2970 static int snd_soc_component_initialize(struct snd_soc_component *component,
2971         const struct snd_soc_component_driver *driver, struct device *dev)
2972 {
2973         struct snd_soc_dapm_context *dapm;
2974
2975         component->name = fmt_single_name(dev, &component->id);
2976         if (!component->name) {
2977                 dev_err(dev, "ASoC: Failed to allocate name\n");
2978                 return -ENOMEM;
2979         }
2980
2981         component->dev = dev;
2982         component->driver = driver;
2983         component->probe = component->driver->probe;
2984         component->remove = component->driver->remove;
2985         component->suspend = component->driver->suspend;
2986         component->resume = component->driver->resume;
2987         component->set_sysclk = component->driver->set_sysclk;
2988         component->set_pll = component->driver->set_pll;
2989         component->set_jack = component->driver->set_jack;
2990         component->pcm_new = snd_soc_component_drv_pcm_new;
2991         component->pcm_free = snd_soc_component_drv_pcm_free;
2992
2993         dapm = snd_soc_component_get_dapm(component);
2994         dapm->dev = dev;
2995         dapm->component = component;
2996         dapm->bias_level = SND_SOC_BIAS_OFF;
2997         dapm->idle_bias_off = !driver->idle_bias_on;
2998         dapm->suspend_bias_off = driver->suspend_bias_off;
2999         if (driver->seq_notifier)
3000                 dapm->seq_notifier = snd_soc_component_seq_notifier;
3001         if (driver->stream_event)
3002                 dapm->stream_event = snd_soc_component_stream_event;
3003         if (driver->set_bias_level)
3004                 dapm->set_bias_level = snd_soc_component_set_bias_level;
3005
3006         INIT_LIST_HEAD(&component->dai_list);
3007         mutex_init(&component->io_mutex);
3008
3009         return 0;
3010 }
3011
3012 static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
3013 {
3014         int val_bytes = regmap_get_val_bytes(component->regmap);
3015
3016         /* Errors are legitimate for non-integer byte multiples */
3017         if (val_bytes > 0)
3018                 component->val_bytes = val_bytes;
3019 }
3020
3021 #ifdef CONFIG_REGMAP
3022
3023 /**
3024  * snd_soc_component_init_regmap() - Initialize regmap instance for the component
3025  * @component: The component for which to initialize the regmap instance
3026  * @regmap: The regmap instance that should be used by the component
3027  *
3028  * This function allows deferred assignment of the regmap instance that is
3029  * associated with the component. Only use this if the regmap instance is not
3030  * yet ready when the component is registered. The function must also be called
3031  * before the first IO attempt of the component.
3032  */
3033 void snd_soc_component_init_regmap(struct snd_soc_component *component,
3034         struct regmap *regmap)
3035 {
3036         component->regmap = regmap;
3037         snd_soc_component_setup_regmap(component);
3038 }
3039 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
3040
3041 /**
3042  * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component
3043  * @component: The component for which to de-initialize the regmap instance
3044  *
3045  * Calls regmap_exit() on the regmap instance associated to the component and
3046  * removes the regmap instance from the component.
3047  *
3048  * This function should only be used if snd_soc_component_init_regmap() was used
3049  * to initialize the regmap instance.
3050  */
3051 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
3052 {
3053         regmap_exit(component->regmap);
3054         component->regmap = NULL;
3055 }
3056 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
3057
3058 #endif
3059
3060 static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
3061 {
3062         if (!component->write && !component->read) {
3063                 if (!component->regmap)
3064                         component->regmap = dev_get_regmap(component->dev, NULL);
3065                 if (component->regmap)
3066                         snd_soc_component_setup_regmap(component);
3067         }
3068
3069         list_add(&component->list, &component_list);
3070         INIT_LIST_HEAD(&component->dobj_list);
3071 }
3072
3073 static void snd_soc_component_add(struct snd_soc_component *component)
3074 {
3075         mutex_lock(&client_mutex);
3076         snd_soc_component_add_unlocked(component);
3077         mutex_unlock(&client_mutex);
3078 }
3079
3080 static void snd_soc_component_cleanup(struct snd_soc_component *component)
3081 {
3082         snd_soc_unregister_dais(component);
3083         kfree(component->name);
3084 }
3085
3086 static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
3087 {
3088         struct snd_soc_card *card = component->card;
3089
3090         if (card)
3091                 snd_soc_unregister_card(card);
3092
3093         list_del(&component->list);
3094 }
3095
3096 #define ENDIANNESS_MAP(name) \
3097         (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
3098 static u64 endianness_format_map[] = {
3099         ENDIANNESS_MAP(S16_),
3100         ENDIANNESS_MAP(U16_),
3101         ENDIANNESS_MAP(S24_),
3102         ENDIANNESS_MAP(U24_),
3103         ENDIANNESS_MAP(S32_),
3104         ENDIANNESS_MAP(U32_),
3105         ENDIANNESS_MAP(S24_3),
3106         ENDIANNESS_MAP(U24_3),
3107         ENDIANNESS_MAP(S20_3),
3108         ENDIANNESS_MAP(U20_3),
3109         ENDIANNESS_MAP(S18_3),
3110         ENDIANNESS_MAP(U18_3),
3111         ENDIANNESS_MAP(FLOAT_),
3112         ENDIANNESS_MAP(FLOAT64_),
3113         ENDIANNESS_MAP(IEC958_SUBFRAME_),
3114 };
3115
3116 /*
3117  * Fix up the DAI formats for endianness: codecs don't actually see
3118  * the endianness of the data but we're using the CPU format
3119  * definitions which do need to include endianness so we ensure that
3120  * codec DAIs always have both big and little endian variants set.
3121  */
3122 static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
3123 {
3124         int i;
3125
3126         for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
3127                 if (stream->formats & endianness_format_map[i])
3128                         stream->formats |= endianness_format_map[i];
3129 }
3130
3131 int snd_soc_add_component(struct device *dev,
3132                         struct snd_soc_component *component,
3133                         const struct snd_soc_component_driver *component_driver,
3134                         struct snd_soc_dai_driver *dai_drv,
3135                         int num_dai)
3136 {
3137         int ret;
3138         int i;
3139
3140         ret = snd_soc_component_initialize(component, component_driver, dev);
3141         if (ret)
3142                 goto err_free;
3143
3144         component->ignore_pmdown_time = true;
3145         component->registered_as_component = true;
3146
3147         if (component_driver->endianness) {
3148                 for (i = 0; i < num_dai; i++) {
3149                         convert_endianness_formats(&dai_drv[i].playback);
3150                         convert_endianness_formats(&dai_drv[i].capture);
3151                 }
3152         }
3153
3154         ret = snd_soc_register_dais(component, dai_drv, num_dai,
3155                                     !component_driver->non_legacy_dai_naming);
3156         if (ret < 0) {
3157                 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3158                 goto err_cleanup;
3159         }
3160
3161         snd_soc_component_add(component);
3162
3163         return 0;
3164
3165 err_cleanup:
3166         snd_soc_component_cleanup(component);
3167 err_free:
3168         return ret;
3169 }
3170 EXPORT_SYMBOL_GPL(snd_soc_add_component);
3171
3172 int snd_soc_register_component(struct device *dev,
3173                         const struct snd_soc_component_driver *component_driver,
3174                         struct snd_soc_dai_driver *dai_drv,
3175                         int num_dai)
3176 {
3177         struct snd_soc_component *component;
3178
3179         component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
3180         if (!component)
3181                 return -ENOMEM;
3182
3183         return snd_soc_add_component(dev, component, component_driver,
3184                                      dai_drv, num_dai);
3185 }
3186 EXPORT_SYMBOL_GPL(snd_soc_register_component);
3187
3188 /**
3189  * snd_soc_unregister_component - Unregister all related component
3190  * from the ASoC core
3191  *
3192  * @dev: The device to unregister
3193  */
3194 static int __snd_soc_unregister_component(struct device *dev)
3195 {
3196         struct snd_soc_component *component;
3197         int found = 0;
3198
3199         mutex_lock(&client_mutex);
3200         list_for_each_entry(component, &component_list, list) {
3201                 if (dev != component->dev ||
3202                     !component->registered_as_component)
3203                         continue;
3204
3205                 snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
3206                 snd_soc_component_del_unlocked(component);
3207                 found = 1;
3208                 break;
3209         }
3210         mutex_unlock(&client_mutex);
3211
3212         if (found) {
3213                 snd_soc_component_cleanup(component);
3214         }
3215
3216         return found;
3217 }
3218
3219 void snd_soc_unregister_component(struct device *dev)
3220 {
3221         while (__snd_soc_unregister_component(dev));
3222 }
3223 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3224
3225 struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
3226                                                    const char *driver_name)
3227 {
3228         struct snd_soc_component *component;
3229         struct snd_soc_component *ret;
3230
3231         ret = NULL;
3232         mutex_lock(&client_mutex);
3233         list_for_each_entry(component, &component_list, list) {
3234                 if (dev != component->dev)
3235                         continue;
3236
3237                 if (driver_name &&
3238                     (driver_name != component->driver->name) &&
3239                     (strcmp(component->driver->name, driver_name) != 0))
3240                         continue;
3241
3242                 ret = component;
3243                 break;
3244         }
3245         mutex_unlock(&client_mutex);
3246
3247         return ret;
3248 }
3249 EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
3250
3251 static int snd_soc_codec_drv_probe(struct snd_soc_component *component)
3252 {
3253         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3254
3255         return codec->driver->probe(codec);
3256 }
3257
3258 static void snd_soc_codec_drv_remove(struct snd_soc_component *component)
3259 {
3260         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3261
3262         codec->driver->remove(codec);
3263 }
3264
3265 static int snd_soc_codec_drv_suspend(struct snd_soc_component *component)
3266 {
3267         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3268
3269         return codec->driver->suspend(codec);
3270 }
3271
3272 static int snd_soc_codec_drv_resume(struct snd_soc_component *component)
3273 {
3274         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3275
3276         return codec->driver->resume(codec);
3277 }
3278
3279 static int snd_soc_codec_drv_write(struct snd_soc_component *component,
3280         unsigned int reg, unsigned int val)
3281 {
3282         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3283
3284         return codec->driver->write(codec, reg, val);
3285 }
3286
3287 static int snd_soc_codec_drv_read(struct snd_soc_component *component,
3288         unsigned int reg, unsigned int *val)
3289 {
3290         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3291
3292         *val = codec->driver->read(codec, reg);
3293
3294         return 0;
3295 }
3296
3297 static int snd_soc_codec_set_sysclk_(struct snd_soc_component *component,
3298                           int clk_id, int source, unsigned int freq, int dir)
3299 {
3300         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3301
3302         return snd_soc_codec_set_sysclk(codec, clk_id, source, freq, dir);
3303 }
3304
3305 static int snd_soc_codec_set_pll_(struct snd_soc_component *component,
3306                                   int pll_id, int source, unsigned int freq_in,
3307                                   unsigned int freq_out)
3308 {
3309         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3310
3311         return snd_soc_codec_set_pll(codec, pll_id, source, freq_in, freq_out);
3312 }
3313
3314 static int snd_soc_codec_set_jack_(struct snd_soc_component *component,
3315                                struct snd_soc_jack *jack, void *data)
3316 {
3317         struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3318
3319         return snd_soc_codec_set_jack(codec, jack, data);
3320 }
3321
3322 static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm,
3323         enum snd_soc_bias_level level)
3324 {
3325         struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
3326
3327         return codec->driver->set_bias_level(codec, level);
3328 }
3329
3330 /**
3331  * snd_soc_register_codec - Register a codec with the ASoC core
3332  *
3333  * @dev: The parent device for this codec
3334  * @codec_drv: Codec driver
3335  * @dai_drv: The associated DAI driver
3336  * @num_dai: Number of DAIs
3337  */
3338 int snd_soc_register_codec(struct device *dev,
3339                            const struct snd_soc_codec_driver *codec_drv,
3340                            struct snd_soc_dai_driver *dai_drv,
3341                            int num_dai)
3342 {
3343         struct snd_soc_dapm_context *dapm;
3344         struct snd_soc_codec *codec;
3345         struct snd_soc_dai *dai;
3346         int ret, i;
3347
3348         dev_dbg(dev, "codec register %s\n", dev_name(dev));
3349
3350         codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3351         if (codec == NULL)
3352                 return -ENOMEM;
3353
3354         codec->component.codec = codec;
3355
3356         ret = snd_soc_component_initialize(&codec->component,
3357                         &codec_drv->component_driver, dev);
3358         if (ret)
3359                 goto err_free;
3360
3361         if (codec_drv->probe)
3362                 codec->component.probe = snd_soc_codec_drv_probe;
3363         if (codec_drv->remove)
3364                 codec->component.remove = snd_soc_codec_drv_remove;
3365         if (codec_drv->suspend)
3366                 codec->component.suspend = snd_soc_codec_drv_suspend;
3367         if (codec_drv->resume)
3368                 codec->component.resume = snd_soc_codec_drv_resume;
3369         if (codec_drv->write)
3370                 codec->component.write = snd_soc_codec_drv_write;
3371         if (codec_drv->read)
3372                 codec->component.read = snd_soc_codec_drv_read;
3373         if (codec_drv->set_sysclk)
3374                 codec->component.set_sysclk = snd_soc_codec_set_sysclk_;
3375         if (codec_drv->set_pll)
3376                 codec->component.set_pll = snd_soc_codec_set_pll_;
3377         if (codec_drv->set_jack)
3378                 codec->component.set_jack = snd_soc_codec_set_jack_;
3379         codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
3380
3381         dapm = snd_soc_codec_get_dapm(codec);
3382         dapm->idle_bias_off = codec_drv->idle_bias_off;
3383         dapm->suspend_bias_off = codec_drv->suspend_bias_off;
3384         if (codec_drv->seq_notifier)
3385                 dapm->seq_notifier = codec_drv->seq_notifier;
3386         if (codec_drv->set_bias_level)
3387                 dapm->set_bias_level = snd_soc_codec_set_bias_level;
3388         codec->dev = dev;
3389         codec->driver = codec_drv;
3390
3391 #ifdef CONFIG_DEBUG_FS
3392         codec->component.debugfs_prefix = "codec";
3393 #endif
3394
3395         for (i = 0; i < num_dai; i++) {
3396                 convert_endianness_formats(&dai_drv[i].playback);
3397                 convert_endianness_formats(&dai_drv[i].capture);
3398         }
3399
3400         ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);
3401         if (ret < 0) {
3402                 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3403                 goto err_cleanup;
3404         }
3405
3406         list_for_each_entry(dai, &codec->component.dai_list, list)
3407                 dai->codec = codec;
3408
3409         mutex_lock(&client_mutex);
3410         snd_soc_component_add_unlocked(&codec->component);
3411         list_add(&codec->list, &codec_list);
3412         mutex_unlock(&client_mutex);
3413
3414         dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n",
3415                 codec->component.name);
3416         return 0;
3417
3418 err_cleanup:
3419         snd_soc_component_cleanup(&codec->component);
3420 err_free:
3421         kfree(codec);
3422         return ret;
3423 }
3424 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3425
3426 /**
3427  * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3428  *
3429  * @dev: codec to unregister
3430  */
3431 void snd_soc_unregister_codec(struct device *dev)
3432 {
3433         struct snd_soc_codec *codec;
3434
3435         mutex_lock(&client_mutex);
3436         list_for_each_entry(codec, &codec_list, list) {
3437                 if (dev == codec->dev)
3438                         goto found;
3439         }
3440         mutex_unlock(&client_mutex);
3441         return;
3442
3443 found:
3444         list_del(&codec->list);
3445         snd_soc_component_del_unlocked(&codec->component);
3446         mutex_unlock(&client_mutex);
3447
3448         dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n",
3449                         codec->component.name);
3450
3451         snd_soc_component_cleanup(&codec->component);
3452         kfree(codec);
3453 }
3454 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3455
3456 /* Retrieve a card's name from device tree */
3457 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3458                                const char *propname)
3459 {
3460         struct device_node *np;
3461         int ret;
3462
3463         if (!card->dev) {
3464                 pr_err("card->dev is not set before calling %s\n", __func__);
3465                 return -EINVAL;
3466         }
3467
3468         np = card->dev->of_node;
3469
3470         ret = of_property_read_string_index(np, propname, 0, &card->name);
3471         /*
3472          * EINVAL means the property does not exist. This is fine providing
3473          * card->name was previously set, which is checked later in
3474          * snd_soc_register_card.
3475          */
3476         if (ret < 0 && ret != -EINVAL) {
3477                 dev_err(card->dev,
3478                         "ASoC: Property '%s' could not be read: %d\n",
3479                         propname, ret);
3480                 return ret;
3481         }
3482
3483         return 0;
3484 }
3485 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3486
3487 static const struct snd_soc_dapm_widget simple_widgets[] = {
3488         SND_SOC_DAPM_MIC("Microphone", NULL),
3489         SND_SOC_DAPM_LINE("Line", NULL),
3490         SND_SOC_DAPM_HP("Headphone", NULL),
3491         SND_SOC_DAPM_SPK("Speaker", NULL),
3492 };
3493
3494 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
3495                                           const char *propname)
3496 {
3497         struct device_node *np = card->dev->of_node;
3498         struct snd_soc_dapm_widget *widgets;
3499         const char *template, *wname;
3500         int i, j, num_widgets, ret;
3501
3502         num_widgets = of_property_count_strings(np, propname);
3503         if (num_widgets < 0) {
3504                 dev_err(card->dev,
3505                         "ASoC: Property '%s' does not exist\n", propname);
3506                 return -EINVAL;
3507         }
3508         if (num_widgets & 1) {
3509                 dev_err(card->dev,
3510                         "ASoC: Property '%s' length is not even\n", propname);
3511                 return -EINVAL;
3512         }
3513
3514         num_widgets /= 2;
3515         if (!num_widgets) {
3516                 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
3517                         propname);
3518                 return -EINVAL;
3519         }
3520
3521         widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
3522                                GFP_KERNEL);
3523         if (!widgets) {
3524                 dev_err(card->dev,
3525                         "ASoC: Could not allocate memory for widgets\n");
3526                 return -ENOMEM;
3527         }
3528
3529         for (i = 0; i < num_widgets; i++) {
3530                 ret = of_property_read_string_index(np, propname,
3531                         2 * i, &template);
3532                 if (ret) {
3533                         dev_err(card->dev,
3534                                 "ASoC: Property '%s' index %d read error:%d\n",
3535                                 propname, 2 * i, ret);
3536                         return -EINVAL;
3537                 }
3538
3539                 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
3540                         if (!strncmp(template, simple_widgets[j].name,
3541                                      strlen(simple_widgets[j].name))) {
3542                                 widgets[i] = simple_widgets[j];
3543                                 break;
3544                         }
3545                 }
3546
3547                 if (j >= ARRAY_SIZE(simple_widgets)) {
3548                         dev_err(card->dev,
3549                                 "ASoC: DAPM widget '%s' is not supported\n",
3550                                 template);
3551                         return -EINVAL;
3552                 }
3553
3554                 ret = of_property_read_string_index(np, propname,
3555                                                     (2 * i) + 1,
3556                                                     &wname);
3557                 if (ret) {
3558                         dev_err(card->dev,
3559                                 "ASoC: Property '%s' index %d read error:%d\n",
3560                                 propname, (2 * i) + 1, ret);
3561                         return -EINVAL;
3562                 }
3563
3564                 widgets[i].name = wname;
3565         }
3566
3567         card->of_dapm_widgets = widgets;
3568         card->num_of_dapm_widgets = num_widgets;
3569
3570         return 0;
3571 }
3572 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
3573
3574 static int snd_soc_of_get_slot_mask(struct device_node *np,
3575                                     const char *prop_name,
3576                                     unsigned int *mask)
3577 {
3578         u32 val;
3579         const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
3580         int i;
3581
3582         if (!of_slot_mask)
3583                 return 0;
3584         val /= sizeof(u32);
3585         for (i = 0; i < val; i++)
3586                 if (be32_to_cpup(&of_slot_mask[i]))
3587                         *mask |= (1 << i);
3588
3589         return val;
3590 }
3591
3592 int snd_soc_of_parse_tdm_slot(struct device_node *np,
3593                               unsigned int *tx_mask,
3594                               unsigned int *rx_mask,
3595                               unsigned int *slots,
3596                               unsigned int *slot_width)
3597 {
3598         u32 val;
3599         int ret;
3600
3601         if (tx_mask)
3602                 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
3603         if (rx_mask)
3604                 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
3605
3606         if (of_property_read_bool(np, "dai-tdm-slot-num")) {
3607                 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
3608                 if (ret)
3609                         return ret;
3610
3611                 if (slots)
3612                         *slots = val;
3613         }
3614
3615         if (of_property_read_bool(np, "dai-tdm-slot-width")) {
3616                 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
3617                 if (ret)
3618                         return ret;
3619
3620                 if (slot_width)
3621                         *slot_width = val;
3622         }
3623
3624         return 0;
3625 }
3626 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
3627
3628 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
3629                                    struct snd_soc_codec_conf *codec_conf,
3630                                    struct device_node *of_node,
3631                                    const char *propname)
3632 {
3633         struct device_node *np = card->dev->of_node;
3634         const char *str;
3635         int ret;
3636
3637         ret = of_property_read_string(np, propname, &str);
3638         if (ret < 0) {
3639                 /* no prefix is not error */
3640                 return;
3641         }
3642
3643         codec_conf->of_node     = of_node;
3644         codec_conf->name_prefix = str;
3645 }
3646 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_prefix);
3647
3648 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3649                                    const char *propname)
3650 {
3651         struct device_node *np = card->dev->of_node;
3652         int num_routes;
3653         struct snd_soc_dapm_route *routes;
3654         int i, ret;
3655
3656         num_routes = of_property_count_strings(np, propname);
3657         if (num_routes < 0 || num_routes & 1) {
3658                 dev_err(card->dev,
3659                         "ASoC: Property '%s' does not exist or its length is not even\n",
3660                         propname);
3661                 return -EINVAL;
3662         }
3663         num_routes /= 2;
3664         if (!num_routes) {
3665                 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
3666                         propname);
3667                 return -EINVAL;
3668         }
3669
3670         routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3671                               GFP_KERNEL);
3672         if (!routes) {
3673                 dev_err(card->dev,
3674                         "ASoC: Could not allocate DAPM route table\n");
3675                 return -EINVAL;
3676         }
3677
3678         for (i = 0; i < num_routes; i++) {
3679                 ret = of_property_read_string_index(np, propname,
3680                         2 * i, &routes[i].sink);
3681                 if (ret) {
3682                         dev_err(card->dev,
3683                                 "ASoC: Property '%s' index %d could not be read: %d\n",
3684                                 propname, 2 * i, ret);
3685                         return -EINVAL;
3686                 }
3687                 ret = of_property_read_string_index(np, propname,
3688                         (2 * i) + 1, &routes[i].source);
3689                 if (ret) {
3690                         dev_err(card->dev,
3691                                 "ASoC: Property '%s' index %d could not be read: %d\n",
3692                                 propname, (2 * i) + 1, ret);
3693                         return -EINVAL;
3694                 }
3695         }
3696
3697         card->num_of_dapm_routes = num_routes;
3698         card->of_dapm_routes = routes;
3699
3700         return 0;
3701 }
3702 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3703
3704 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
3705                                      const char *prefix,
3706                                      struct device_node **bitclkmaster,
3707                                      struct device_node **framemaster)
3708 {
3709         int ret, i;
3710         char prop[128];
3711         unsigned int format = 0;
3712         int bit, frame;
3713         const char *str;
3714         struct {
3715                 char *name;
3716                 unsigned int val;
3717         } of_fmt_table[] = {
3718                 { "i2s",        SND_SOC_DAIFMT_I2S },
3719                 { "right_j",    SND_SOC_DAIFMT_RIGHT_J },
3720                 { "left_j",     SND_SOC_DAIFMT_LEFT_J },
3721                 { "dsp_a",      SND_SOC_DAIFMT_DSP_A },
3722                 { "dsp_b",      SND_SOC_DAIFMT_DSP_B },
3723                 { "ac97",       SND_SOC_DAIFMT_AC97 },
3724                 { "pdm",        SND_SOC_DAIFMT_PDM},
3725                 { "msb",        SND_SOC_DAIFMT_MSB },
3726                 { "lsb",        SND_SOC_DAIFMT_LSB },
3727         };
3728
3729         if (!prefix)
3730                 prefix = "";
3731
3732         /*
3733          * check "dai-format = xxx"
3734          * or    "[prefix]format = xxx"
3735          * SND_SOC_DAIFMT_FORMAT_MASK area
3736          */
3737         ret = of_property_read_string(np, "dai-format", &str);
3738         if (ret < 0) {
3739                 snprintf(prop, sizeof(prop), "%sformat", prefix);
3740                 ret = of_property_read_string(np, prop, &str);
3741         }
3742         if (ret == 0) {
3743                 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
3744                         if (strcmp(str, of_fmt_table[i].name) == 0) {
3745                                 format |= of_fmt_table[i].val;
3746                                 break;
3747                         }
3748                 }
3749         }
3750
3751         /*
3752          * check "[prefix]continuous-clock"
3753          * SND_SOC_DAIFMT_CLOCK_MASK area
3754          */
3755         snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
3756         if (of_property_read_bool(np, prop))
3757                 format |= SND_SOC_DAIFMT_CONT;
3758         else
3759                 format |= SND_SOC_DAIFMT_GATED;
3760
3761         /*
3762          * check "[prefix]bitclock-inversion"
3763          * check "[prefix]frame-inversion"
3764          * SND_SOC_DAIFMT_INV_MASK area
3765          */
3766         snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
3767         bit = !!of_get_property(np, prop, NULL);
3768
3769         snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
3770         frame = !!of_get_property(np, prop, NULL);
3771
3772         switch ((bit << 4) + frame) {
3773         case 0x11:
3774                 format |= SND_SOC_DAIFMT_IB_IF;
3775                 break;
3776         case 0x10:
3777                 format |= SND_SOC_DAIFMT_IB_NF;
3778                 break;
3779         case 0x01:
3780                 format |= SND_SOC_DAIFMT_NB_IF;
3781                 break;
3782         default:
3783                 /* SND_SOC_DAIFMT_NB_NF is default */
3784                 break;
3785         }
3786
3787         /*
3788          * check "[prefix]bitclock-master"
3789          * check "[prefix]frame-master"
3790          * SND_SOC_DAIFMT_MASTER_MASK area
3791          */
3792         snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
3793         bit = !!of_get_property(np, prop, NULL);
3794         if (bit && bitclkmaster)
3795                 *bitclkmaster = of_parse_phandle(np, prop, 0);
3796
3797         snprintf(prop, sizeof(prop), "%sframe-master", prefix);
3798         frame = !!of_get_property(np, prop, NULL);
3799         if (frame && framemaster)
3800                 *framemaster = of_parse_phandle(np, prop, 0);
3801
3802         switch ((bit << 4) + frame) {
3803         case 0x11:
3804                 format |= SND_SOC_DAIFMT_CBM_CFM;
3805                 break;
3806         case 0x10:
3807                 format |= SND_SOC_DAIFMT_CBM_CFS;
3808                 break;
3809         case 0x01:
3810                 format |= SND_SOC_DAIFMT_CBS_CFM;
3811                 break;
3812         default:
3813                 format |= SND_SOC_DAIFMT_CBS_CFS;
3814                 break;
3815         }
3816
3817         return format;
3818 }
3819 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
3820
3821 int snd_soc_get_dai_id(struct device_node *ep)
3822 {
3823         struct snd_soc_component *pos;
3824         struct device_node *node;
3825         int ret;
3826
3827         node = of_graph_get_port_parent(ep);
3828
3829         /*
3830          * For example HDMI case, HDMI has video/sound port,
3831          * but ALSA SoC needs sound port number only.
3832          * Thus counting HDMI DT port/endpoint doesn't work.
3833          * Then, it should have .of_xlate_dai_id
3834          */
3835         ret = -ENOTSUPP;
3836         mutex_lock(&client_mutex);
3837         list_for_each_entry(pos, &component_list, list) {
3838                 struct device_node *component_of_node = pos->dev->of_node;
3839
3840                 if (!component_of_node && pos->dev->parent)
3841                         component_of_node = pos->dev->parent->of_node;
3842
3843                 if (component_of_node != node)
3844                         continue;
3845
3846                 if (pos->driver->of_xlate_dai_id)
3847                         ret = pos->driver->of_xlate_dai_id(pos, ep);
3848
3849                 break;
3850         }
3851         mutex_unlock(&client_mutex);
3852
3853         of_node_put(node);
3854
3855         return ret;
3856 }
3857 EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
3858
3859 int snd_soc_get_dai_name(struct of_phandle_args *args,
3860                                 const char **dai_name)
3861 {
3862         struct snd_soc_component *pos;
3863         struct device_node *component_of_node;
3864         int ret = -EPROBE_DEFER;
3865
3866         mutex_lock(&client_mutex);
3867         list_for_each_entry(pos, &component_list, list) {
3868                 component_of_node = pos->dev->of_node;
3869                 if (!component_of_node && pos->dev->parent)
3870                         component_of_node = pos->dev->parent->of_node;
3871
3872                 if (component_of_node != args->np)
3873                         continue;
3874
3875                 if (pos->driver->of_xlate_dai_name) {
3876                         ret = pos->driver->of_xlate_dai_name(pos,
3877                                                              args,
3878                                                              dai_name);
3879                 } else {
3880                         struct snd_soc_dai *dai;
3881                         int id = -1;
3882
3883                         switch (args->args_count) {
3884                         case 0:
3885                                 id = 0; /* same as dai_drv[0] */
3886                                 break;
3887                         case 1:
3888                                 id = args->args[0];
3889                                 break;
3890                         default:
3891                                 /* not supported */
3892                                 break;
3893                         }
3894
3895                         if (id < 0 || id >= pos->num_dai) {
3896                                 ret = -EINVAL;
3897                                 continue;
3898                         }
3899
3900                         ret = 0;
3901
3902                         /* find target DAI */
3903                         list_for_each_entry(dai, &pos->dai_list, list) {
3904                                 if (id == 0)
3905                                         break;
3906                                 id--;
3907                         }
3908
3909                         *dai_name = dai->driver->name;
3910                         if (!*dai_name)
3911                                 *dai_name = pos->name;
3912                 }
3913
3914                 break;
3915         }
3916         mutex_unlock(&client_mutex);
3917         return ret;
3918 }
3919 EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
3920
3921 int snd_soc_of_get_dai_name(struct device_node *of_node,
3922                             const char **dai_name)
3923 {
3924         struct of_phandle_args args;
3925         int ret;
3926
3927         ret = of_parse_phandle_with_args(of_node, "sound-dai",
3928                                          "#sound-dai-cells", 0, &args);
3929         if (ret)
3930                 return ret;
3931
3932         ret = snd_soc_get_dai_name(&args, dai_name);
3933
3934         of_node_put(args.np);
3935
3936         return ret;
3937 }
3938 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
3939
3940 /*
3941  * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
3942  * @dai_link: DAI link
3943  *
3944  * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
3945  */
3946 void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
3947 {
3948         struct snd_soc_dai_link_component *component = dai_link->codecs;
3949         int index;
3950
3951         for (index = 0; index < dai_link->num_codecs; index++, component++) {
3952                 if (!component->of_node)
3953                         break;
3954                 of_node_put(component->of_node);
3955                 component->of_node = NULL;
3956         }
3957 }
3958 EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
3959
3960 /*
3961  * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
3962  * @dev: Card device
3963  * @of_node: Device node
3964  * @dai_link: DAI link
3965  *
3966  * Builds an array of CODEC DAI components from the DAI link property
3967  * 'sound-dai'.
3968  * The array is set in the DAI link and the number of DAIs is set accordingly.
3969  * The device nodes in the array (of_node) must be dereferenced by calling
3970  * snd_soc_of_put_dai_link_codecs() on @dai_link.
3971  *
3972  * Returns 0 for success
3973  */
3974 int snd_soc_of_get_dai_link_codecs(struct device *dev,
3975                                    struct device_node *of_node,
3976                                    struct snd_soc_dai_link *dai_link)
3977 {
3978         struct of_phandle_args args;
3979         struct snd_soc_dai_link_component *component;
3980         char *name;
3981         int index, num_codecs, ret;
3982
3983         /* Count the number of CODECs */
3984         name = "sound-dai";
3985         num_codecs = of_count_phandle_with_args(of_node, name,
3986                                                 "#sound-dai-cells");
3987         if (num_codecs <= 0) {
3988                 if (num_codecs == -ENOENT)
3989                         dev_err(dev, "No 'sound-dai' property\n");
3990                 else
3991                         dev_err(dev, "Bad phandle in 'sound-dai'\n");
3992                 return num_codecs;
3993         }
3994         component = devm_kzalloc(dev,
3995                                  sizeof *component * num_codecs,
3996                                  GFP_KERNEL);
3997         if (!component)
3998                 return -ENOMEM;
3999         dai_link->codecs = component;
4000         dai_link->num_codecs = num_codecs;
4001
4002         /* Parse the list */
4003         for (index = 0, component = dai_link->codecs;
4004              index < dai_link->num_codecs;
4005              index++, component++) {
4006                 ret = of_parse_phandle_with_args(of_node, name,
4007                                                  "#sound-dai-cells",
4008                                                   index, &args);
4009                 if (ret)
4010                         goto err;
4011                 component->of_node = args.np;
4012                 ret = snd_soc_get_dai_name(&args, &component->dai_name);
4013                 if (ret < 0)
4014                         goto err;
4015         }
4016         return 0;
4017 err:
4018         snd_soc_of_put_dai_link_codecs(dai_link);
4019         dai_link->codecs = NULL;
4020         dai_link->num_codecs = 0;
4021         return ret;
4022 }
4023 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
4024
4025 static int __init snd_soc_init(void)
4026 {
4027         snd_soc_debugfs_init();
4028         snd_soc_util_init();
4029
4030         return platform_driver_register(&soc_driver);
4031 }
4032 module_init(snd_soc_init);
4033
4034 static void __exit snd_soc_exit(void)
4035 {
4036         snd_soc_util_exit();
4037         snd_soc_debugfs_exit();
4038
4039         platform_driver_unregister(&soc_driver);
4040 }
4041 module_exit(snd_soc_exit);
4042
4043 /* Module information */
4044 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4045 MODULE_DESCRIPTION("ALSA SoC Core");
4046 MODULE_LICENSE("GPL");
4047 MODULE_ALIAS("platform:soc-audio");