treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / sound / soc / soc-core.c
blob068d809c349a2fc05da5db90802207232b95681f
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // soc-core.c -- ALSA SoC Audio Layer
4 //
5 // Copyright 2005 Wolfson Microelectronics PLC.
6 // Copyright 2005 Openedhand Ltd.
7 // Copyright (C) 2010 Slimlogic Ltd.
8 // Copyright (C) 2010 Texas Instruments Inc.
9 //
10 // Author: Liam Girdwood <lrg@slimlogic.co.uk>
11 // with code, comments and ideas from :-
12 // Richard Purdie <richard@openedhand.com>
14 // TODO:
15 // o Add hw rules to enforce rates, etc.
16 // o More testing with other codecs/machines.
17 // o Add more codecs and platforms to ensure good API coverage.
18 // o Support TDM on PCM and I2S
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/pm.h>
25 #include <linux/bitops.h>
26 #include <linux/debugfs.h>
27 #include <linux/platform_device.h>
28 #include <linux/pinctrl/consumer.h>
29 #include <linux/ctype.h>
30 #include <linux/slab.h>
31 #include <linux/of.h>
32 #include <linux/of_graph.h>
33 #include <linux/dmi.h>
34 #include <sound/core.h>
35 #include <sound/jack.h>
36 #include <sound/pcm.h>
37 #include <sound/pcm_params.h>
38 #include <sound/soc.h>
39 #include <sound/soc-dpcm.h>
40 #include <sound/soc-topology.h>
41 #include <sound/initval.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/asoc.h>
46 #define NAME_SIZE 32
48 static DEFINE_MUTEX(client_mutex);
49 static LIST_HEAD(component_list);
50 static LIST_HEAD(unbind_card_list);
52 #define for_each_component(component) \
53 list_for_each_entry(component, &component_list, list)
56 * This is used if driver don't need to have CPU/Codec/Platform
57 * dai_link. see soc.h
59 struct snd_soc_dai_link_component null_dailink_component[0];
60 EXPORT_SYMBOL_GPL(null_dailink_component);
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.
67 static int pmdown_time = 5000;
68 module_param(pmdown_time, int, 0);
69 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71 static ssize_t pmdown_time_show(struct device *dev,
72 struct device_attribute *attr, char *buf)
74 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
76 return sprintf(buf, "%ld\n", rtd->pmdown_time);
79 static ssize_t pmdown_time_set(struct device *dev,
80 struct device_attribute *attr,
81 const char *buf, size_t count)
83 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
84 int ret;
86 ret = kstrtol(buf, 10, &rtd->pmdown_time);
87 if (ret)
88 return ret;
90 return count;
93 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
95 static struct attribute *soc_dev_attrs[] = {
96 &dev_attr_pmdown_time.attr,
97 NULL
100 static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
101 struct attribute *attr, int idx)
103 struct device *dev = kobj_to_dev(kobj);
104 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
106 if (!rtd)
107 return 0;
109 if (attr == &dev_attr_pmdown_time.attr)
110 return attr->mode; /* always visible */
111 return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
114 static const struct attribute_group soc_dapm_dev_group = {
115 .attrs = soc_dapm_dev_attrs,
116 .is_visible = soc_dev_attr_is_visible,
119 static const struct attribute_group soc_dev_group = {
120 .attrs = soc_dev_attrs,
121 .is_visible = soc_dev_attr_is_visible,
124 static const struct attribute_group *soc_dev_attr_groups[] = {
125 &soc_dapm_dev_group,
126 &soc_dev_group,
127 NULL
130 #ifdef CONFIG_DEBUG_FS
131 struct dentry *snd_soc_debugfs_root;
132 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
134 static void soc_init_component_debugfs(struct snd_soc_component *component)
136 if (!component->card->debugfs_card_root)
137 return;
139 if (component->debugfs_prefix) {
140 char *name;
142 name = kasprintf(GFP_KERNEL, "%s:%s",
143 component->debugfs_prefix, component->name);
144 if (name) {
145 component->debugfs_root = debugfs_create_dir(name,
146 component->card->debugfs_card_root);
147 kfree(name);
149 } else {
150 component->debugfs_root = debugfs_create_dir(component->name,
151 component->card->debugfs_card_root);
154 snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
155 component->debugfs_root);
158 static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
160 if (!component->debugfs_root)
161 return;
162 debugfs_remove_recursive(component->debugfs_root);
163 component->debugfs_root = NULL;
166 static int dai_list_show(struct seq_file *m, void *v)
168 struct snd_soc_component *component;
169 struct snd_soc_dai *dai;
171 mutex_lock(&client_mutex);
173 for_each_component(component)
174 for_each_component_dais(component, dai)
175 seq_printf(m, "%s\n", dai->name);
177 mutex_unlock(&client_mutex);
179 return 0;
181 DEFINE_SHOW_ATTRIBUTE(dai_list);
183 static int component_list_show(struct seq_file *m, void *v)
185 struct snd_soc_component *component;
187 mutex_lock(&client_mutex);
189 for_each_component(component)
190 seq_printf(m, "%s\n", component->name);
192 mutex_unlock(&client_mutex);
194 return 0;
196 DEFINE_SHOW_ATTRIBUTE(component_list);
198 static void soc_init_card_debugfs(struct snd_soc_card *card)
200 card->debugfs_card_root = debugfs_create_dir(card->name,
201 snd_soc_debugfs_root);
203 debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root,
204 &card->pop_time);
206 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
209 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
211 debugfs_remove_recursive(card->debugfs_card_root);
212 card->debugfs_card_root = NULL;
215 static void snd_soc_debugfs_init(void)
217 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
219 debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
220 &dai_list_fops);
222 debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL,
223 &component_list_fops);
226 static void snd_soc_debugfs_exit(void)
228 debugfs_remove_recursive(snd_soc_debugfs_root);
231 #else
233 static inline void soc_init_component_debugfs(
234 struct snd_soc_component *component)
238 static inline void soc_cleanup_component_debugfs(
239 struct snd_soc_component *component)
243 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
247 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
251 static inline void snd_soc_debugfs_init(void)
255 static inline void snd_soc_debugfs_exit(void)
259 #endif
261 static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
262 struct snd_soc_component *component)
264 struct snd_soc_component *comp;
265 int i;
267 for_each_rtd_components(rtd, i, comp) {
268 /* already connected */
269 if (comp == component)
270 return 0;
273 /* see for_each_rtd_components */
274 rtd->components[rtd->num_components] = component;
275 rtd->num_components++;
277 return 0;
280 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
281 const char *driver_name)
283 struct snd_soc_component *component;
284 int i;
286 if (!driver_name)
287 return NULL;
290 * NOTE
292 * snd_soc_rtdcom_lookup() will find component from rtd by using
293 * specified driver name.
294 * But, if many components which have same driver name are connected
295 * to 1 rtd, this function will return 1st found component.
297 for_each_rtd_components(rtd, i, component) {
298 const char *component_name = component->driver->name;
300 if (!component_name)
301 continue;
303 if ((component_name == driver_name) ||
304 strcmp(component_name, driver_name) == 0)
305 return component;
308 return NULL;
310 EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
312 static struct snd_soc_component
313 *snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
315 struct snd_soc_component *component;
316 struct snd_soc_component *found_component;
318 found_component = NULL;
319 for_each_component(component) {
320 if ((dev == component->dev) &&
321 (!driver_name ||
322 (driver_name == component->driver->name) ||
323 (strcmp(component->driver->name, driver_name) == 0))) {
324 found_component = component;
325 break;
329 return found_component;
332 struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
333 const char *driver_name)
335 struct snd_soc_component *component;
337 mutex_lock(&client_mutex);
338 component = snd_soc_lookup_component_nolocked(dev, driver_name);
339 mutex_unlock(&client_mutex);
341 return component;
343 EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
345 struct snd_soc_pcm_runtime
346 *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
347 struct snd_soc_dai_link *dai_link)
349 struct snd_soc_pcm_runtime *rtd;
351 for_each_card_rtds(card, rtd) {
352 if (rtd->dai_link == dai_link)
353 return rtd;
355 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link->name);
356 return NULL;
358 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
361 * Power down the audio subsystem pmdown_time msecs after close is called.
362 * This is to ensure there are no pops or clicks in between any music tracks
363 * due to DAPM power cycling.
365 void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
367 struct snd_soc_dai *codec_dai = rtd->codec_dai;
369 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
371 dev_dbg(rtd->dev,
372 "ASoC: pop wq checking: %s status: %s waiting: %s\n",
373 codec_dai->driver->playback.stream_name,
374 codec_dai->playback_active ? "active" : "inactive",
375 rtd->pop_wait ? "yes" : "no");
377 /* are we waiting on this codec DAI stream */
378 if (rtd->pop_wait == 1) {
379 rtd->pop_wait = 0;
380 snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
381 SND_SOC_DAPM_STREAM_STOP);
384 mutex_unlock(&rtd->card->pcm_mutex);
386 EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
388 static void soc_release_rtd_dev(struct device *dev)
390 /* "dev" means "rtd->dev" */
391 kfree(dev);
394 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
396 if (!rtd)
397 return;
399 list_del(&rtd->list);
401 if (delayed_work_pending(&rtd->delayed_work))
402 flush_delayed_work(&rtd->delayed_work);
403 snd_soc_pcm_component_free(rtd);
406 * we don't need to call kfree() for rtd->dev
407 * see
408 * soc_release_rtd_dev()
410 * We don't need rtd->dev NULL check, because
411 * it is alloced *before* rtd.
412 * see
413 * soc_new_pcm_runtime()
415 device_unregister(rtd->dev);
418 static void close_delayed_work(struct work_struct *work) {
419 struct snd_soc_pcm_runtime *rtd =
420 container_of(work, struct snd_soc_pcm_runtime,
421 delayed_work.work);
423 if (rtd->close_delayed_work_func)
424 rtd->close_delayed_work_func(rtd);
427 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
428 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
430 struct snd_soc_pcm_runtime *rtd;
431 struct snd_soc_component *component;
432 struct device *dev;
433 int ret;
436 * for rtd->dev
438 dev = kzalloc(sizeof(struct device), GFP_KERNEL);
439 if (!dev)
440 return NULL;
442 dev->parent = card->dev;
443 dev->release = soc_release_rtd_dev;
444 dev->groups = soc_dev_attr_groups;
446 dev_set_name(dev, "%s", dai_link->name);
448 ret = device_register(dev);
449 if (ret < 0) {
450 put_device(dev); /* soc_release_rtd_dev */
451 return NULL;
455 * for rtd
457 rtd = devm_kzalloc(dev,
458 sizeof(*rtd) +
459 sizeof(*component) * (dai_link->num_cpus +
460 dai_link->num_codecs +
461 dai_link->num_platforms),
462 GFP_KERNEL);
463 if (!rtd)
464 goto free_rtd;
466 rtd->dev = dev;
467 INIT_LIST_HEAD(&rtd->list);
468 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
469 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
470 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
471 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
472 dev_set_drvdata(dev, rtd);
473 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
476 * for rtd->codec_dais
478 rtd->codec_dais = devm_kcalloc(dev, dai_link->num_codecs,
479 sizeof(struct snd_soc_dai *),
480 GFP_KERNEL);
481 if (!rtd->codec_dais)
482 goto free_rtd;
485 * rtd remaining settings
487 rtd->card = card;
488 rtd->dai_link = dai_link;
490 /* see for_each_card_rtds */
491 list_add_tail(&rtd->list, &card->rtd_list);
492 rtd->num = card->num_rtd;
493 card->num_rtd++;
495 return rtd;
497 free_rtd:
498 soc_free_pcm_runtime(rtd);
499 return NULL;
502 static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card)
504 struct snd_soc_pcm_runtime *rtd;
506 for_each_card_rtds(card, rtd)
507 flush_delayed_work(&rtd->delayed_work);
510 #ifdef CONFIG_PM_SLEEP
511 /* powers down audio subsystem for suspend */
512 int snd_soc_suspend(struct device *dev)
514 struct snd_soc_card *card = dev_get_drvdata(dev);
515 struct snd_soc_component *component;
516 struct snd_soc_pcm_runtime *rtd;
517 int i;
519 /* If the card is not initialized yet there is nothing to do */
520 if (!card->instantiated)
521 return 0;
524 * Due to the resume being scheduled into a workqueue we could
525 * suspend before that's finished - wait for it to complete.
527 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
529 /* we're going to block userspace touching us until resume completes */
530 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
532 /* mute any active DACs */
533 for_each_card_rtds(card, rtd) {
534 struct snd_soc_dai *dai;
536 if (rtd->dai_link->ignore_suspend)
537 continue;
539 for_each_rtd_codec_dai(rtd, i, dai) {
540 if (dai->playback_active)
541 snd_soc_dai_digital_mute(dai, 1,
542 SNDRV_PCM_STREAM_PLAYBACK);
546 /* suspend all pcms */
547 for_each_card_rtds(card, rtd) {
548 if (rtd->dai_link->ignore_suspend)
549 continue;
551 snd_pcm_suspend_all(rtd->pcm);
554 if (card->suspend_pre)
555 card->suspend_pre(card);
557 /* close any waiting streams */
558 snd_soc_flush_all_delayed_work(card);
560 for_each_card_rtds(card, rtd) {
562 if (rtd->dai_link->ignore_suspend)
563 continue;
565 snd_soc_dapm_stream_event(rtd,
566 SNDRV_PCM_STREAM_PLAYBACK,
567 SND_SOC_DAPM_STREAM_SUSPEND);
569 snd_soc_dapm_stream_event(rtd,
570 SNDRV_PCM_STREAM_CAPTURE,
571 SND_SOC_DAPM_STREAM_SUSPEND);
574 /* Recheck all endpoints too, their state is affected by suspend */
575 dapm_mark_endpoints_dirty(card);
576 snd_soc_dapm_sync(&card->dapm);
578 /* suspend all COMPONENTs */
579 for_each_card_rtds(card, rtd) {
581 if (rtd->dai_link->ignore_suspend)
582 continue;
584 for_each_rtd_components(rtd, i, component) {
585 struct snd_soc_dapm_context *dapm =
586 snd_soc_component_get_dapm(component);
589 * ignore if component was already suspended
591 if (snd_soc_component_is_suspended(component))
592 continue;
595 * If there are paths active then the COMPONENT will be
596 * held with bias _ON and should not be suspended.
598 switch (snd_soc_dapm_get_bias_level(dapm)) {
599 case SND_SOC_BIAS_STANDBY:
601 * If the COMPONENT is capable of idle
602 * bias off then being in STANDBY
603 * means it's doing something,
604 * otherwise fall through.
606 if (dapm->idle_bias_off) {
607 dev_dbg(component->dev,
608 "ASoC: idle_bias_off CODEC on over suspend\n");
609 break;
611 /* fall through */
613 case SND_SOC_BIAS_OFF:
614 snd_soc_component_suspend(component);
615 if (component->regmap)
616 regcache_mark_dirty(component->regmap);
617 /* deactivate pins to sleep state */
618 pinctrl_pm_select_sleep_state(component->dev);
619 break;
620 default:
621 dev_dbg(component->dev,
622 "ASoC: COMPONENT is on over suspend\n");
623 break;
628 if (card->suspend_post)
629 card->suspend_post(card);
631 return 0;
633 EXPORT_SYMBOL_GPL(snd_soc_suspend);
636 * deferred resume work, so resume can complete before we finished
637 * setting our codec back up, which can be very slow on I2C
639 static void soc_resume_deferred(struct work_struct *work)
641 struct snd_soc_card *card =
642 container_of(work, struct snd_soc_card,
643 deferred_resume_work);
644 struct snd_soc_pcm_runtime *rtd;
645 struct snd_soc_component *component;
646 int i;
649 * our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
650 * so userspace apps are blocked from touching us
653 dev_dbg(card->dev, "ASoC: starting resume work\n");
655 /* Bring us up into D2 so that DAPM starts enabling things */
656 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
658 if (card->resume_pre)
659 card->resume_pre(card);
661 for_each_card_components(card, component) {
662 if (snd_soc_component_is_suspended(component))
663 snd_soc_component_resume(component);
666 for_each_card_rtds(card, rtd) {
668 if (rtd->dai_link->ignore_suspend)
669 continue;
671 snd_soc_dapm_stream_event(rtd,
672 SNDRV_PCM_STREAM_PLAYBACK,
673 SND_SOC_DAPM_STREAM_RESUME);
675 snd_soc_dapm_stream_event(rtd,
676 SNDRV_PCM_STREAM_CAPTURE,
677 SND_SOC_DAPM_STREAM_RESUME);
680 /* unmute any active DACs */
681 for_each_card_rtds(card, rtd) {
682 struct snd_soc_dai *dai;
684 if (rtd->dai_link->ignore_suspend)
685 continue;
687 for_each_rtd_codec_dai(rtd, i, dai) {
688 if (dai->playback_active)
689 snd_soc_dai_digital_mute(dai, 0,
690 SNDRV_PCM_STREAM_PLAYBACK);
694 if (card->resume_post)
695 card->resume_post(card);
697 dev_dbg(card->dev, "ASoC: resume work completed\n");
699 /* Recheck all endpoints too, their state is affected by suspend */
700 dapm_mark_endpoints_dirty(card);
701 snd_soc_dapm_sync(&card->dapm);
703 /* userspace can access us now we are back as we were before */
704 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
707 /* powers up audio subsystem after a suspend */
708 int snd_soc_resume(struct device *dev)
710 struct snd_soc_card *card = dev_get_drvdata(dev);
711 struct snd_soc_component *component;
713 /* If the card is not initialized yet there is nothing to do */
714 if (!card->instantiated)
715 return 0;
717 /* activate pins from sleep state */
718 for_each_card_components(card, component)
719 if (component->active)
720 pinctrl_pm_select_default_state(component->dev);
722 dev_dbg(dev, "ASoC: Scheduling resume work\n");
723 if (!schedule_work(&card->deferred_resume_work))
724 dev_err(dev, "ASoC: resume work item may be lost\n");
726 return 0;
728 EXPORT_SYMBOL_GPL(snd_soc_resume);
730 static void soc_resume_init(struct snd_soc_card *card)
732 /* deferred resume work */
733 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
735 #else
736 #define snd_soc_suspend NULL
737 #define snd_soc_resume NULL
738 static inline void soc_resume_init(struct snd_soc_card *card)
741 #endif
743 static const struct snd_soc_dai_ops null_dai_ops = {
746 static struct device_node
747 *soc_component_to_node(struct snd_soc_component *component)
749 struct device_node *of_node;
751 of_node = component->dev->of_node;
752 if (!of_node && component->dev->parent)
753 of_node = component->dev->parent->of_node;
755 return of_node;
758 static int snd_soc_is_matching_component(
759 const struct snd_soc_dai_link_component *dlc,
760 struct snd_soc_component *component)
762 struct device_node *component_of_node;
764 if (!dlc)
765 return 0;
767 component_of_node = soc_component_to_node(component);
769 if (dlc->of_node && component_of_node != dlc->of_node)
770 return 0;
771 if (dlc->name && strcmp(component->name, dlc->name))
772 return 0;
774 return 1;
777 static struct snd_soc_component *soc_find_component(
778 const struct snd_soc_dai_link_component *dlc)
780 struct snd_soc_component *component;
782 lockdep_assert_held(&client_mutex);
785 * NOTE
787 * It returns *1st* found component, but some driver
788 * has few components by same of_node/name
789 * ex)
790 * CPU component and generic DMAEngine component
792 for_each_component(component)
793 if (snd_soc_is_matching_component(dlc, component))
794 return component;
796 return NULL;
800 * snd_soc_find_dai - Find a registered DAI
802 * @dlc: name of the DAI or the DAI driver and optional component info to match
804 * This function will search all registered components and their DAIs to
805 * find the DAI of the same name. The component's of_node and name
806 * should also match if being specified.
808 * Return: pointer of DAI, or NULL if not found.
810 struct snd_soc_dai *snd_soc_find_dai(
811 const struct snd_soc_dai_link_component *dlc)
813 struct snd_soc_component *component;
814 struct snd_soc_dai *dai;
816 lockdep_assert_held(&client_mutex);
818 /* Find CPU DAI from registered DAIs */
819 for_each_component(component) {
820 if (!snd_soc_is_matching_component(dlc, component))
821 continue;
822 for_each_component_dais(component, dai) {
823 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
824 && (!dai->driver->name
825 || strcmp(dai->driver->name, dlc->dai_name)))
826 continue;
828 return dai;
832 return NULL;
834 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
836 static int soc_dai_link_sanity_check(struct snd_soc_card *card,
837 struct snd_soc_dai_link *link)
839 int i;
840 struct snd_soc_dai_link_component *codec, *platform;
842 for_each_link_codecs(link, i, codec) {
844 * Codec must be specified by 1 of name or OF node,
845 * not both or neither.
847 if (!!codec->name == !!codec->of_node) {
848 dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
849 link->name);
850 return -EINVAL;
853 /* Codec DAI name must be specified */
854 if (!codec->dai_name) {
855 dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
856 link->name);
857 return -EINVAL;
861 * Defer card registration if codec component is not added to
862 * component list.
864 if (!soc_find_component(codec))
865 return -EPROBE_DEFER;
868 for_each_link_platforms(link, i, platform) {
870 * Platform may be specified by either name or OF node, but it
871 * can be left unspecified, then no components will be inserted
872 * in the rtdcom list
874 if (!!platform->name == !!platform->of_node) {
875 dev_err(card->dev,
876 "ASoC: Neither/both platform name/of_node are set for %s\n",
877 link->name);
878 return -EINVAL;
882 * Defer card registration if platform component is not added to
883 * component list.
885 if (!soc_find_component(platform))
886 return -EPROBE_DEFER;
889 /* FIXME */
890 if (link->num_cpus > 1) {
891 dev_err(card->dev,
892 "ASoC: multi cpu is not yet supported %s\n",
893 link->name);
894 return -EINVAL;
898 * CPU device may be specified by either name or OF node, but
899 * can be left unspecified, and will be matched based on DAI
900 * name alone..
902 if (link->cpus->name && link->cpus->of_node) {
903 dev_err(card->dev,
904 "ASoC: Neither/both cpu name/of_node are set for %s\n",
905 link->name);
906 return -EINVAL;
910 * Defer card registration if cpu dai component is not added to
911 * component list.
913 if ((link->cpus->of_node || link->cpus->name) &&
914 !soc_find_component(link->cpus))
915 return -EPROBE_DEFER;
918 * At least one of CPU DAI name or CPU device name/node must be
919 * specified
921 if (!link->cpus->dai_name &&
922 !(link->cpus->name || link->cpus->of_node)) {
923 dev_err(card->dev,
924 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
925 link->name);
926 return -EINVAL;
929 return 0;
933 * snd_soc_remove_pcm_runtime - Remove a pcm_runtime from card
934 * @card: The ASoC card to which the pcm_runtime has
935 * @rtd: The pcm_runtime to remove
937 * This function removes a pcm_runtime from the ASoC card.
939 void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
940 struct snd_soc_pcm_runtime *rtd)
942 lockdep_assert_held(&client_mutex);
945 * Notify the machine driver for extra destruction
947 if (card->remove_dai_link)
948 card->remove_dai_link(card, rtd->dai_link);
950 soc_free_pcm_runtime(rtd);
952 EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
955 * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
956 * @card: The ASoC card to which the pcm_runtime is added
957 * @dai_link: The DAI link to find pcm_runtime
959 * This function adds a pcm_runtime ASoC card by using dai_link.
961 * Note: Topology can use this API to add pcm_runtime when probing the
962 * topology component. And machine drivers can still define static
963 * DAI links in dai_link array.
965 int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
966 struct snd_soc_dai_link *dai_link)
968 struct snd_soc_pcm_runtime *rtd;
969 struct snd_soc_dai_link_component *codec, *platform;
970 struct snd_soc_component *component;
971 int i, ret;
973 lockdep_assert_held(&client_mutex);
976 * Notify the machine driver for extra initialization
978 if (card->add_dai_link)
979 card->add_dai_link(card, dai_link);
981 if (dai_link->ignore)
982 return 0;
984 dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
986 ret = soc_dai_link_sanity_check(card, dai_link);
987 if (ret < 0)
988 return ret;
990 rtd = soc_new_pcm_runtime(card, dai_link);
991 if (!rtd)
992 return -ENOMEM;
994 /* FIXME: we need multi CPU support in the future */
995 rtd->cpu_dai = snd_soc_find_dai(dai_link->cpus);
996 if (!rtd->cpu_dai) {
997 dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
998 dai_link->cpus->dai_name);
999 goto _err_defer;
1001 snd_soc_rtd_add_component(rtd, rtd->cpu_dai->component);
1003 /* Find CODEC from registered CODECs */
1004 rtd->num_codecs = dai_link->num_codecs;
1005 for_each_link_codecs(dai_link, i, codec) {
1006 rtd->codec_dais[i] = snd_soc_find_dai(codec);
1007 if (!rtd->codec_dais[i]) {
1008 dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
1009 codec->dai_name);
1010 goto _err_defer;
1013 snd_soc_rtd_add_component(rtd, rtd->codec_dais[i]->component);
1016 /* Single codec links expect codec and codec_dai in runtime data */
1017 rtd->codec_dai = rtd->codec_dais[0];
1019 /* Find PLATFORM from registered PLATFORMs */
1020 for_each_link_platforms(dai_link, i, platform) {
1021 for_each_component(component) {
1022 if (!snd_soc_is_matching_component(platform, component))
1023 continue;
1025 snd_soc_rtd_add_component(rtd, component);
1029 return 0;
1031 _err_defer:
1032 snd_soc_remove_pcm_runtime(card, rtd);
1033 return -EPROBE_DEFER;
1035 EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);
1037 static int soc_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
1038 struct snd_soc_pcm_runtime *rtd)
1040 int i, ret = 0;
1042 for (i = 0; i < num_dais; ++i) {
1043 struct snd_soc_dai_driver *drv = dais[i]->driver;
1045 if (drv->pcm_new)
1046 ret = drv->pcm_new(rtd, dais[i]);
1047 if (ret < 0) {
1048 dev_err(dais[i]->dev,
1049 "ASoC: Failed to bind %s with pcm device\n",
1050 dais[i]->name);
1051 return ret;
1055 return 0;
1058 static int soc_init_pcm_runtime(struct snd_soc_card *card,
1059 struct snd_soc_pcm_runtime *rtd)
1061 struct snd_soc_dai_link *dai_link = rtd->dai_link;
1062 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1063 struct snd_soc_component *component;
1064 int ret, num, i;
1066 /* set default power off timeout */
1067 rtd->pmdown_time = pmdown_time;
1069 /* do machine specific initialization */
1070 if (dai_link->init) {
1071 ret = dai_link->init(rtd);
1072 if (ret < 0) {
1073 dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1074 dai_link->name, ret);
1075 return ret;
1079 if (dai_link->dai_fmt) {
1080 ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1081 if (ret)
1082 return ret;
1085 /* add DPCM sysfs entries */
1086 soc_dpcm_debugfs_add(rtd);
1088 num = rtd->num;
1091 * most drivers will register their PCMs using DAI link ordering but
1092 * topology based drivers can use the DAI link id field to set PCM
1093 * device number and then use rtd + a base offset of the BEs.
1095 for_each_rtd_components(rtd, i, component) {
1096 if (!component->driver->use_dai_pcm_id)
1097 continue;
1099 if (rtd->dai_link->no_pcm)
1100 num += component->driver->be_pcm_base;
1101 else
1102 num = rtd->dai_link->id;
1105 /* create compress_device if possible */
1106 ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
1107 if (ret != -ENOTSUPP) {
1108 if (ret < 0)
1109 dev_err(card->dev, "ASoC: can't create compress %s\n",
1110 dai_link->stream_name);
1111 return ret;
1114 /* create the pcm */
1115 ret = soc_new_pcm(rtd, num);
1116 if (ret < 0) {
1117 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1118 dai_link->stream_name, ret);
1119 return ret;
1121 ret = soc_dai_pcm_new(&cpu_dai, 1, rtd);
1122 if (ret < 0)
1123 return ret;
1124 ret = soc_dai_pcm_new(rtd->codec_dais,
1125 rtd->num_codecs, rtd);
1126 return ret;
1129 static void soc_set_name_prefix(struct snd_soc_card *card,
1130 struct snd_soc_component *component)
1132 struct device_node *of_node = soc_component_to_node(component);
1133 const char *str;
1134 int ret, i;
1136 for (i = 0; i < card->num_configs; i++) {
1137 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1139 if (snd_soc_is_matching_component(&map->dlc, component)) {
1140 component->name_prefix = map->name_prefix;
1141 return;
1146 * If there is no configuration table or no match in the table,
1147 * check if a prefix is provided in the node
1149 ret = of_property_read_string(of_node, "sound-name-prefix", &str);
1150 if (ret < 0)
1151 return;
1153 component->name_prefix = str;
1156 static void soc_remove_component(struct snd_soc_component *component,
1157 int probed)
1160 if (!component->card)
1161 return;
1163 if (probed)
1164 snd_soc_component_remove(component);
1166 /* For framework level robustness */
1167 snd_soc_component_set_jack(component, NULL, NULL);
1169 list_del_init(&component->card_list);
1170 snd_soc_dapm_free(snd_soc_component_get_dapm(component));
1171 soc_cleanup_component_debugfs(component);
1172 component->card = NULL;
1173 snd_soc_component_module_put_when_remove(component);
1176 static int soc_probe_component(struct snd_soc_card *card,
1177 struct snd_soc_component *component)
1179 struct snd_soc_dapm_context *dapm =
1180 snd_soc_component_get_dapm(component);
1181 struct snd_soc_dai *dai;
1182 int probed = 0;
1183 int ret;
1185 if (!strcmp(component->name, "snd-soc-dummy"))
1186 return 0;
1188 if (component->card) {
1189 if (component->card != card) {
1190 dev_err(component->dev,
1191 "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1192 card->name, component->card->name);
1193 return -ENODEV;
1195 return 0;
1198 ret = snd_soc_component_module_get_when_probe(component);
1199 if (ret < 0)
1200 return ret;
1202 component->card = card;
1203 soc_set_name_prefix(card, component);
1205 soc_init_component_debugfs(component);
1207 snd_soc_dapm_init(dapm, card, component);
1209 ret = snd_soc_dapm_new_controls(dapm,
1210 component->driver->dapm_widgets,
1211 component->driver->num_dapm_widgets);
1213 if (ret != 0) {
1214 dev_err(component->dev,
1215 "Failed to create new controls %d\n", ret);
1216 goto err_probe;
1219 for_each_component_dais(component, dai) {
1220 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1221 if (ret != 0) {
1222 dev_err(component->dev,
1223 "Failed to create DAI widgets %d\n", ret);
1224 goto err_probe;
1228 ret = snd_soc_component_probe(component);
1229 if (ret < 0) {
1230 dev_err(component->dev,
1231 "ASoC: failed to probe component %d\n", ret);
1232 goto err_probe;
1234 WARN(dapm->idle_bias_off &&
1235 dapm->bias_level != SND_SOC_BIAS_OFF,
1236 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1237 component->name);
1238 probed = 1;
1240 /* machine specific init */
1241 if (component->init) {
1242 ret = component->init(component);
1243 if (ret < 0) {
1244 dev_err(component->dev,
1245 "Failed to do machine specific init %d\n", ret);
1246 goto err_probe;
1250 ret = snd_soc_add_component_controls(component,
1251 component->driver->controls,
1252 component->driver->num_controls);
1253 if (ret < 0)
1254 goto err_probe;
1256 ret = snd_soc_dapm_add_routes(dapm,
1257 component->driver->dapm_routes,
1258 component->driver->num_dapm_routes);
1259 if (ret < 0)
1260 goto err_probe;
1262 /* see for_each_card_components */
1263 list_add(&component->card_list, &card->component_dev_list);
1265 err_probe:
1266 if (ret < 0)
1267 soc_remove_component(component, probed);
1269 return ret;
1272 static void soc_remove_dai(struct snd_soc_dai *dai, int order)
1274 int err;
1276 if (!dai || !dai->probed || !dai->driver ||
1277 dai->driver->remove_order != order)
1278 return;
1280 err = snd_soc_dai_remove(dai);
1281 if (err < 0)
1282 dev_err(dai->dev,
1283 "ASoC: failed to remove %s: %d\n",
1284 dai->name, err);
1286 dai->probed = 0;
1289 static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1291 int ret;
1293 if (dai->probed ||
1294 dai->driver->probe_order != order)
1295 return 0;
1297 ret = snd_soc_dai_probe(dai);
1298 if (ret < 0) {
1299 dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n",
1300 dai->name, ret);
1301 return ret;
1304 dai->probed = 1;
1306 return 0;
1309 static void soc_remove_link_dais(struct snd_soc_card *card)
1311 int i;
1312 struct snd_soc_dai *codec_dai;
1313 struct snd_soc_pcm_runtime *rtd;
1314 int order;
1316 for_each_comp_order(order) {
1317 for_each_card_rtds(card, rtd) {
1318 /* remove the CODEC DAI */
1319 for_each_rtd_codec_dai(rtd, i, codec_dai)
1320 soc_remove_dai(codec_dai, order);
1322 soc_remove_dai(rtd->cpu_dai, order);
1327 static int soc_probe_link_dais(struct snd_soc_card *card)
1329 struct snd_soc_dai *codec_dai;
1330 struct snd_soc_pcm_runtime *rtd;
1331 int i, order, ret;
1333 for_each_comp_order(order) {
1334 for_each_card_rtds(card, rtd) {
1336 dev_dbg(card->dev,
1337 "ASoC: probe %s dai link %d late %d\n",
1338 card->name, rtd->num, order);
1340 ret = soc_probe_dai(rtd->cpu_dai, order);
1341 if (ret)
1342 return ret;
1344 /* probe the CODEC DAI */
1345 for_each_rtd_codec_dai(rtd, i, codec_dai) {
1346 ret = soc_probe_dai(codec_dai, order);
1347 if (ret)
1348 return ret;
1353 return 0;
1356 static void soc_remove_link_components(struct snd_soc_card *card)
1358 struct snd_soc_component *component;
1359 struct snd_soc_pcm_runtime *rtd;
1360 int i, order;
1362 for_each_comp_order(order) {
1363 for_each_card_rtds(card, rtd) {
1364 for_each_rtd_components(rtd, i, component) {
1365 if (component->driver->remove_order != order)
1366 continue;
1368 soc_remove_component(component, 1);
1374 static int soc_probe_link_components(struct snd_soc_card *card)
1376 struct snd_soc_component *component;
1377 struct snd_soc_pcm_runtime *rtd;
1378 int i, ret, order;
1380 for_each_comp_order(order) {
1381 for_each_card_rtds(card, rtd) {
1382 for_each_rtd_components(rtd, i, component) {
1383 if (component->driver->probe_order != order)
1384 continue;
1386 ret = soc_probe_component(card, component);
1387 if (ret < 0)
1388 return ret;
1393 return 0;
1396 static void soc_unbind_aux_dev(struct snd_soc_card *card)
1398 struct snd_soc_component *component, *_component;
1400 for_each_card_auxs_safe(card, component, _component) {
1401 component->init = NULL;
1402 list_del(&component->card_aux_list);
1406 static int soc_bind_aux_dev(struct snd_soc_card *card)
1408 struct snd_soc_component *component;
1409 struct snd_soc_aux_dev *aux;
1410 int i;
1412 for_each_card_pre_auxs(card, i, aux) {
1413 /* codecs, usually analog devices */
1414 component = soc_find_component(&aux->dlc);
1415 if (!component)
1416 return -EPROBE_DEFER;
1418 component->init = aux->init;
1419 /* see for_each_card_auxs */
1420 list_add(&component->card_aux_list, &card->aux_comp_list);
1422 return 0;
1425 static int soc_probe_aux_devices(struct snd_soc_card *card)
1427 struct snd_soc_component *component;
1428 int order;
1429 int ret;
1431 for_each_comp_order(order) {
1432 for_each_card_auxs(card, component) {
1433 if (component->driver->probe_order != order)
1434 continue;
1436 ret = soc_probe_component(card, component);
1437 if (ret < 0)
1438 return ret;
1442 return 0;
1445 static void soc_remove_aux_devices(struct snd_soc_card *card)
1447 struct snd_soc_component *comp, *_comp;
1448 int order;
1450 for_each_comp_order(order) {
1451 for_each_card_auxs_safe(card, comp, _comp) {
1452 if (comp->driver->remove_order == order)
1453 soc_remove_component(comp, 1);
1459 * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1460 * @rtd: The runtime for which the DAI link format should be changed
1461 * @dai_fmt: The new DAI link format
1463 * This function updates the DAI link format for all DAIs connected to the DAI
1464 * link for the specified runtime.
1466 * Note: For setups with a static format set the dai_fmt field in the
1467 * corresponding snd_dai_link struct instead of using this function.
1469 * Returns 0 on success, otherwise a negative error code.
1471 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1472 unsigned int dai_fmt)
1474 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1475 struct snd_soc_dai *codec_dai;
1476 unsigned int i;
1477 int ret;
1479 for_each_rtd_codec_dai(rtd, i, codec_dai) {
1480 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1481 if (ret != 0 && ret != -ENOTSUPP) {
1482 dev_warn(codec_dai->dev,
1483 "ASoC: Failed to set DAI format: %d\n", ret);
1484 return ret;
1489 * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
1490 * the component which has non_legacy_dai_naming is Codec
1492 if (cpu_dai->component->driver->non_legacy_dai_naming) {
1493 unsigned int inv_dai_fmt;
1495 inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1496 switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1497 case SND_SOC_DAIFMT_CBM_CFM:
1498 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1499 break;
1500 case SND_SOC_DAIFMT_CBM_CFS:
1501 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1502 break;
1503 case SND_SOC_DAIFMT_CBS_CFM:
1504 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1505 break;
1506 case SND_SOC_DAIFMT_CBS_CFS:
1507 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1508 break;
1511 dai_fmt = inv_dai_fmt;
1514 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1515 if (ret != 0 && ret != -ENOTSUPP) {
1516 dev_warn(cpu_dai->dev,
1517 "ASoC: Failed to set DAI format: %d\n", ret);
1518 return ret;
1521 return 0;
1523 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1525 #ifdef CONFIG_DMI
1527 * If a DMI filed contain strings in this blacklist (e.g.
1528 * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
1529 * as invalid and dropped when setting the card long name from DMI info.
1531 static const char * const dmi_blacklist[] = {
1532 "To be filled by OEM",
1533 "TBD by OEM",
1534 "Default String",
1535 "Board Manufacturer",
1536 "Board Vendor Name",
1537 "Board Product Name",
1538 NULL, /* terminator */
1542 * Trim special characters, and replace '-' with '_' since '-' is used to
1543 * separate different DMI fields in the card long name. Only number and
1544 * alphabet characters and a few separator characters are kept.
1546 static void cleanup_dmi_name(char *name)
1548 int i, j = 0;
1550 for (i = 0; name[i]; i++) {
1551 if (isalnum(name[i]) || (name[i] == '.')
1552 || (name[i] == '_'))
1553 name[j++] = name[i];
1554 else if (name[i] == '-')
1555 name[j++] = '_';
1558 name[j] = '\0';
1562 * Check if a DMI field is valid, i.e. not containing any string
1563 * in the black list.
1565 static int is_dmi_valid(const char *field)
1567 int i = 0;
1569 while (dmi_blacklist[i]) {
1570 if (strstr(field, dmi_blacklist[i]))
1571 return 0;
1572 i++;
1575 return 1;
1579 * Append a string to card->dmi_longname with character cleanups.
1581 static void append_dmi_string(struct snd_soc_card *card, const char *str)
1583 char *dst = card->dmi_longname;
1584 size_t dst_len = sizeof(card->dmi_longname);
1585 size_t len;
1587 len = strlen(dst);
1588 snprintf(dst + len, dst_len - len, "-%s", str);
1590 len++; /* skip the separator "-" */
1591 if (len < dst_len)
1592 cleanup_dmi_name(dst + len);
1596 * snd_soc_set_dmi_name() - Register DMI names to card
1597 * @card: The card to register DMI names
1598 * @flavour: The flavour "differentiator" for the card amongst its peers.
1600 * An Intel machine driver may be used by many different devices but are
1601 * difficult for userspace to differentiate, since machine drivers ususally
1602 * use their own name as the card short name and leave the card long name
1603 * blank. To differentiate such devices and fix bugs due to lack of
1604 * device-specific configurations, this function allows DMI info to be used
1605 * as the sound card long name, in the format of
1606 * "vendor-product-version-board"
1607 * (Character '-' is used to separate different DMI fields here).
1608 * This will help the user space to load the device-specific Use Case Manager
1609 * (UCM) configurations for the card.
1611 * Possible card long names may be:
1612 * DellInc.-XPS139343-01-0310JH
1613 * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
1614 * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
1616 * This function also supports flavoring the card longname to provide
1617 * the extra differentiation, like "vendor-product-version-board-flavor".
1619 * We only keep number and alphabet characters and a few separator characters
1620 * in the card long name since UCM in the user space uses the card long names
1621 * as card configuration directory names and AudoConf cannot support special
1622 * charactors like SPACE.
1624 * Returns 0 on success, otherwise a negative error code.
1626 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
1628 const char *vendor, *product, *product_version, *board;
1630 if (card->long_name)
1631 return 0; /* long name already set by driver or from DMI */
1633 /* make up dmi long name as: vendor-product-version-board */
1634 vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1635 if (!vendor || !is_dmi_valid(vendor)) {
1636 dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
1637 return 0;
1640 snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
1641 cleanup_dmi_name(card->dmi_longname);
1643 product = dmi_get_system_info(DMI_PRODUCT_NAME);
1644 if (product && is_dmi_valid(product)) {
1645 append_dmi_string(card, product);
1648 * some vendors like Lenovo may only put a self-explanatory
1649 * name in the product version field
1651 product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
1652 if (product_version && is_dmi_valid(product_version))
1653 append_dmi_string(card, product_version);
1656 board = dmi_get_system_info(DMI_BOARD_NAME);
1657 if (board && is_dmi_valid(board)) {
1658 if (!product || strcasecmp(board, product))
1659 append_dmi_string(card, board);
1660 } else if (!product) {
1661 /* fall back to using legacy name */
1662 dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
1663 return 0;
1666 /* Add flavour to dmi long name */
1667 if (flavour)
1668 append_dmi_string(card, flavour);
1670 /* set the card long name */
1671 card->long_name = card->dmi_longname;
1673 return 0;
1675 EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
1676 #endif /* CONFIG_DMI */
1678 static void soc_check_tplg_fes(struct snd_soc_card *card)
1680 struct snd_soc_component *component;
1681 const struct snd_soc_component_driver *comp_drv;
1682 struct snd_soc_dai_link *dai_link;
1683 int i;
1685 for_each_component(component) {
1687 /* does this component override BEs ? */
1688 if (!component->driver->ignore_machine)
1689 continue;
1691 /* for this machine ? */
1692 if (!strcmp(component->driver->ignore_machine,
1693 card->dev->driver->name))
1694 goto match;
1695 if (strcmp(component->driver->ignore_machine,
1696 dev_name(card->dev)))
1697 continue;
1698 match:
1699 /* machine matches, so override the rtd data */
1700 for_each_card_prelinks(card, i, dai_link) {
1702 /* ignore this FE */
1703 if (dai_link->dynamic) {
1704 dai_link->ignore = true;
1705 continue;
1708 dev_info(card->dev, "info: override BE DAI link %s\n",
1709 card->dai_link[i].name);
1711 /* override platform component */
1712 if (!dai_link->platforms) {
1713 dev_err(card->dev, "init platform error");
1714 continue;
1716 dai_link->platforms->name = component->name;
1718 /* convert non BE into BE */
1719 dai_link->no_pcm = 1;
1720 dai_link->dpcm_playback = 1;
1721 dai_link->dpcm_capture = 1;
1723 /* override any BE fixups */
1724 dai_link->be_hw_params_fixup =
1725 component->driver->be_hw_params_fixup;
1728 * most BE links don't set stream name, so set it to
1729 * dai link name if it's NULL to help bind widgets.
1731 if (!dai_link->stream_name)
1732 dai_link->stream_name = dai_link->name;
1735 /* Inform userspace we are using alternate topology */
1736 if (component->driver->topology_name_prefix) {
1738 /* topology shortname created? */
1739 if (!card->topology_shortname_created) {
1740 comp_drv = component->driver;
1742 snprintf(card->topology_shortname, 32, "%s-%s",
1743 comp_drv->topology_name_prefix,
1744 card->name);
1745 card->topology_shortname_created = true;
1748 /* use topology shortname */
1749 card->name = card->topology_shortname;
1754 #define soc_setup_card_name(name, name1, name2, norm) \
1755 __soc_setup_card_name(name, sizeof(name), name1, name2, norm)
1756 static void __soc_setup_card_name(char *name, int len,
1757 const char *name1, const char *name2,
1758 int normalization)
1760 int i;
1762 snprintf(name, len, "%s", name1 ? name1 : name2);
1764 if (!normalization)
1765 return;
1768 * Name normalization
1770 * The driver name is somewhat special, as it's used as a key for
1771 * searches in the user-space.
1773 * ex)
1774 * "abcd??efg" -> "abcd__efg"
1776 for (i = 0; i < len; i++) {
1777 switch (name[i]) {
1778 case '_':
1779 case '-':
1780 case '\0':
1781 break;
1782 default:
1783 if (!isalnum(name[i]))
1784 name[i] = '_';
1785 break;
1790 static void soc_cleanup_card_resources(struct snd_soc_card *card,
1791 int card_probed)
1793 struct snd_soc_pcm_runtime *rtd, *n;
1795 if (card->snd_card)
1796 snd_card_disconnect_sync(card->snd_card);
1798 snd_soc_dapm_shutdown(card);
1800 /* remove and free each DAI */
1801 soc_remove_link_dais(card);
1802 soc_remove_link_components(card);
1804 for_each_card_rtds_safe(card, rtd, n)
1805 snd_soc_remove_pcm_runtime(card, rtd);
1807 /* remove auxiliary devices */
1808 soc_remove_aux_devices(card);
1809 soc_unbind_aux_dev(card);
1811 snd_soc_dapm_free(&card->dapm);
1812 soc_cleanup_card_debugfs(card);
1814 /* remove the card */
1815 if (card_probed && card->remove)
1816 card->remove(card);
1818 if (card->snd_card) {
1819 snd_card_free(card->snd_card);
1820 card->snd_card = NULL;
1824 static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
1826 if (card->instantiated) {
1827 int card_probed = 1;
1829 card->instantiated = false;
1830 snd_soc_flush_all_delayed_work(card);
1832 soc_cleanup_card_resources(card, card_probed);
1833 if (!unregister)
1834 list_add(&card->list, &unbind_card_list);
1835 } else {
1836 if (unregister)
1837 list_del(&card->list);
1841 static int snd_soc_bind_card(struct snd_soc_card *card)
1843 struct snd_soc_pcm_runtime *rtd;
1844 struct snd_soc_component *component;
1845 struct snd_soc_dai_link *dai_link;
1846 int ret, i, card_probed = 0;
1848 mutex_lock(&client_mutex);
1849 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1851 snd_soc_dapm_init(&card->dapm, card, NULL);
1853 /* check whether any platform is ignore machine FE and using topology */
1854 soc_check_tplg_fes(card);
1856 /* bind aux_devs too */
1857 ret = soc_bind_aux_dev(card);
1858 if (ret < 0)
1859 goto probe_end;
1861 /* add predefined DAI links to the list */
1862 card->num_rtd = 0;
1863 for_each_card_prelinks(card, i, dai_link) {
1864 ret = snd_soc_add_pcm_runtime(card, dai_link);
1865 if (ret < 0)
1866 goto probe_end;
1869 /* card bind complete so register a sound card */
1870 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1871 card->owner, 0, &card->snd_card);
1872 if (ret < 0) {
1873 dev_err(card->dev,
1874 "ASoC: can't create sound card for card %s: %d\n",
1875 card->name, ret);
1876 goto probe_end;
1879 soc_init_card_debugfs(card);
1881 soc_resume_init(card);
1883 ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1884 card->num_dapm_widgets);
1885 if (ret < 0)
1886 goto probe_end;
1888 ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
1889 card->num_of_dapm_widgets);
1890 if (ret < 0)
1891 goto probe_end;
1893 /* initialise the sound card only once */
1894 if (card->probe) {
1895 ret = card->probe(card);
1896 if (ret < 0)
1897 goto probe_end;
1898 card_probed = 1;
1901 /* probe all components used by DAI links on this card */
1902 ret = soc_probe_link_components(card);
1903 if (ret < 0) {
1904 dev_err(card->dev,
1905 "ASoC: failed to instantiate card %d\n", ret);
1906 goto probe_end;
1909 /* probe auxiliary components */
1910 ret = soc_probe_aux_devices(card);
1911 if (ret < 0) {
1912 dev_err(card->dev,
1913 "ASoC: failed to probe aux component %d\n", ret);
1914 goto probe_end;
1917 /* probe all DAI links on this card */
1918 ret = soc_probe_link_dais(card);
1919 if (ret < 0) {
1920 dev_err(card->dev,
1921 "ASoC: failed to instantiate card %d\n", ret);
1922 goto probe_end;
1925 for_each_card_rtds(card, rtd) {
1926 ret = soc_init_pcm_runtime(card, rtd);
1927 if (ret < 0)
1928 goto probe_end;
1931 snd_soc_dapm_link_dai_widgets(card);
1932 snd_soc_dapm_connect_dai_link_widgets(card);
1934 ret = snd_soc_add_card_controls(card, card->controls,
1935 card->num_controls);
1936 if (ret < 0)
1937 goto probe_end;
1939 ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1940 card->num_dapm_routes);
1941 if (ret < 0)
1942 goto probe_end;
1944 ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
1945 card->num_of_dapm_routes);
1946 if (ret < 0)
1947 goto probe_end;
1949 /* try to set some sane longname if DMI is available */
1950 snd_soc_set_dmi_name(card, NULL);
1952 soc_setup_card_name(card->snd_card->shortname,
1953 card->name, NULL, 0);
1954 soc_setup_card_name(card->snd_card->longname,
1955 card->long_name, card->name, 0);
1956 soc_setup_card_name(card->snd_card->driver,
1957 card->driver_name, card->name, 1);
1959 if (card->components) {
1960 /* the current implementation of snd_component_add() accepts */
1961 /* multiple components in the string separated by space, */
1962 /* but the string collision (identical string) check might */
1963 /* not work correctly */
1964 ret = snd_component_add(card->snd_card, card->components);
1965 if (ret < 0) {
1966 dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n",
1967 card->name, ret);
1968 goto probe_end;
1972 if (card->late_probe) {
1973 ret = card->late_probe(card);
1974 if (ret < 0) {
1975 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
1976 card->name, ret);
1977 goto probe_end;
1980 card_probed = 1;
1982 snd_soc_dapm_new_widgets(card);
1984 ret = snd_card_register(card->snd_card);
1985 if (ret < 0) {
1986 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
1987 ret);
1988 goto probe_end;
1991 card->instantiated = 1;
1992 dapm_mark_endpoints_dirty(card);
1993 snd_soc_dapm_sync(&card->dapm);
1995 /* deactivate pins to sleep state */
1996 for_each_card_components(card, component)
1997 if (!component->active)
1998 pinctrl_pm_select_sleep_state(component->dev);
2000 probe_end:
2001 if (ret < 0)
2002 soc_cleanup_card_resources(card, card_probed);
2004 mutex_unlock(&card->mutex);
2005 mutex_unlock(&client_mutex);
2007 return ret;
2010 /* probes a new socdev */
2011 static int soc_probe(struct platform_device *pdev)
2013 struct snd_soc_card *card = platform_get_drvdata(pdev);
2016 * no card, so machine driver should be registering card
2017 * we should not be here in that case so ret error
2019 if (!card)
2020 return -EINVAL;
2022 dev_warn(&pdev->dev,
2023 "ASoC: machine %s should use snd_soc_register_card()\n",
2024 card->name);
2026 /* Bodge while we unpick instantiation */
2027 card->dev = &pdev->dev;
2029 return snd_soc_register_card(card);
2032 /* removes a socdev */
2033 static int soc_remove(struct platform_device *pdev)
2035 struct snd_soc_card *card = platform_get_drvdata(pdev);
2037 snd_soc_unregister_card(card);
2038 return 0;
2041 int snd_soc_poweroff(struct device *dev)
2043 struct snd_soc_card *card = dev_get_drvdata(dev);
2044 struct snd_soc_component *component;
2046 if (!card->instantiated)
2047 return 0;
2050 * Flush out pmdown_time work - we actually do want to run it
2051 * now, we're shutting down so no imminent restart.
2053 snd_soc_flush_all_delayed_work(card);
2055 snd_soc_dapm_shutdown(card);
2057 /* deactivate pins to sleep state */
2058 for_each_card_components(card, component)
2059 pinctrl_pm_select_sleep_state(component->dev);
2061 return 0;
2063 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
2065 const struct dev_pm_ops snd_soc_pm_ops = {
2066 .suspend = snd_soc_suspend,
2067 .resume = snd_soc_resume,
2068 .freeze = snd_soc_suspend,
2069 .thaw = snd_soc_resume,
2070 .poweroff = snd_soc_poweroff,
2071 .restore = snd_soc_resume,
2073 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
2075 /* ASoC platform driver */
2076 static struct platform_driver soc_driver = {
2077 .driver = {
2078 .name = "soc-audio",
2079 .pm = &snd_soc_pm_ops,
2081 .probe = soc_probe,
2082 .remove = soc_remove,
2086 * snd_soc_cnew - create new control
2087 * @_template: control template
2088 * @data: control private data
2089 * @long_name: control long name
2090 * @prefix: control name prefix
2092 * Create a new mixer control from a template control.
2094 * Returns 0 for success, else error.
2096 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2097 void *data, const char *long_name,
2098 const char *prefix)
2100 struct snd_kcontrol_new template;
2101 struct snd_kcontrol *kcontrol;
2102 char *name = NULL;
2104 memcpy(&template, _template, sizeof(template));
2105 template.index = 0;
2107 if (!long_name)
2108 long_name = template.name;
2110 if (prefix) {
2111 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2112 if (!name)
2113 return NULL;
2115 template.name = name;
2116 } else {
2117 template.name = long_name;
2120 kcontrol = snd_ctl_new1(&template, data);
2122 kfree(name);
2124 return kcontrol;
2126 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2128 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2129 const struct snd_kcontrol_new *controls, int num_controls,
2130 const char *prefix, void *data)
2132 int err, i;
2134 for (i = 0; i < num_controls; i++) {
2135 const struct snd_kcontrol_new *control = &controls[i];
2137 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2138 control->name, prefix));
2139 if (err < 0) {
2140 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2141 control->name, err);
2142 return err;
2146 return 0;
2149 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2150 const char *name)
2152 struct snd_card *card = soc_card->snd_card;
2153 struct snd_kcontrol *kctl;
2155 if (unlikely(!name))
2156 return NULL;
2158 list_for_each_entry(kctl, &card->controls, list)
2159 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2160 return kctl;
2161 return NULL;
2163 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2166 * snd_soc_add_component_controls - Add an array of controls to a component.
2168 * @component: Component to add controls to
2169 * @controls: Array of controls to add
2170 * @num_controls: Number of elements in the array
2172 * Return: 0 for success, else error.
2174 int snd_soc_add_component_controls(struct snd_soc_component *component,
2175 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2177 struct snd_card *card = component->card->snd_card;
2179 return snd_soc_add_controls(card, component->dev, controls,
2180 num_controls, component->name_prefix, component);
2182 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
2185 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2186 * Convenience function to add a list of controls.
2188 * @soc_card: SoC card to add controls to
2189 * @controls: array of controls to add
2190 * @num_controls: number of elements in the array
2192 * Return 0 for success, else error.
2194 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2195 const struct snd_kcontrol_new *controls, int num_controls)
2197 struct snd_card *card = soc_card->snd_card;
2199 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2200 NULL, soc_card);
2202 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2205 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2206 * Convienience function to add a list of controls.
2208 * @dai: DAI to add controls to
2209 * @controls: array of controls to add
2210 * @num_controls: number of elements in the array
2212 * Return 0 for success, else error.
2214 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2215 const struct snd_kcontrol_new *controls, int num_controls)
2217 struct snd_card *card = dai->component->card->snd_card;
2219 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2220 NULL, dai);
2222 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2225 * snd_soc_register_card - Register a card with the ASoC core
2227 * @card: Card to register
2230 int snd_soc_register_card(struct snd_soc_card *card)
2232 if (!card->name || !card->dev)
2233 return -EINVAL;
2235 dev_set_drvdata(card->dev, card);
2237 INIT_LIST_HEAD(&card->widgets);
2238 INIT_LIST_HEAD(&card->paths);
2239 INIT_LIST_HEAD(&card->dapm_list);
2240 INIT_LIST_HEAD(&card->aux_comp_list);
2241 INIT_LIST_HEAD(&card->component_dev_list);
2242 INIT_LIST_HEAD(&card->list);
2243 INIT_LIST_HEAD(&card->rtd_list);
2244 INIT_LIST_HEAD(&card->dapm_dirty);
2245 INIT_LIST_HEAD(&card->dobj_list);
2247 card->instantiated = 0;
2248 mutex_init(&card->mutex);
2249 mutex_init(&card->dapm_mutex);
2250 mutex_init(&card->pcm_mutex);
2251 spin_lock_init(&card->dpcm_lock);
2253 return snd_soc_bind_card(card);
2255 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2258 * snd_soc_unregister_card - Unregister a card with the ASoC core
2260 * @card: Card to unregister
2263 int snd_soc_unregister_card(struct snd_soc_card *card)
2265 mutex_lock(&client_mutex);
2266 snd_soc_unbind_card(card, true);
2267 mutex_unlock(&client_mutex);
2268 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2270 return 0;
2272 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2275 * Simplify DAI link configuration by removing ".-1" from device names
2276 * and sanitizing names.
2278 static char *fmt_single_name(struct device *dev, int *id)
2280 char *found, name[NAME_SIZE];
2281 int id1, id2;
2283 if (dev_name(dev) == NULL)
2284 return NULL;
2286 strlcpy(name, dev_name(dev), NAME_SIZE);
2288 /* are we a "%s.%d" name (platform and SPI components) */
2289 found = strstr(name, dev->driver->name);
2290 if (found) {
2291 /* get ID */
2292 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2294 /* discard ID from name if ID == -1 */
2295 if (*id == -1)
2296 found[strlen(dev->driver->name)] = '\0';
2299 } else {
2300 /* I2C component devices are named "bus-addr" */
2301 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2302 char tmp[NAME_SIZE];
2304 /* create unique ID number from I2C addr and bus */
2305 *id = ((id1 & 0xffff) << 16) + id2;
2307 /* sanitize component name for DAI link creation */
2308 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name,
2309 name);
2310 strlcpy(name, tmp, NAME_SIZE);
2311 } else
2312 *id = 0;
2315 return devm_kstrdup(dev, name, GFP_KERNEL);
2319 * Simplify DAI link naming for single devices with multiple DAIs by removing
2320 * any ".-1" and using the DAI name (instead of device name).
2322 static inline char *fmt_multiple_name(struct device *dev,
2323 struct snd_soc_dai_driver *dai_drv)
2325 if (dai_drv->name == NULL) {
2326 dev_err(dev,
2327 "ASoC: error - multiple DAI %s registered with no name\n",
2328 dev_name(dev));
2329 return NULL;
2332 return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
2335 void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2337 dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
2338 list_del(&dai->list);
2340 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2343 * snd_soc_register_dai - Register a DAI dynamically & create its widgets
2345 * @component: The component the DAIs are registered for
2346 * @dai_drv: DAI driver to use for the DAI
2347 * @legacy_dai_naming: if %true, use legacy single-name format;
2348 * if %false, use multiple-name format;
2350 * Topology can use this API to register DAIs when probing a component.
2351 * These DAIs's widgets will be freed in the card cleanup and the DAIs
2352 * will be freed in the component cleanup.
2354 struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
2355 struct snd_soc_dai_driver *dai_drv,
2356 bool legacy_dai_naming)
2358 struct device *dev = component->dev;
2359 struct snd_soc_dai *dai;
2361 dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
2363 lockdep_assert_held(&client_mutex);
2365 dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
2366 if (dai == NULL)
2367 return NULL;
2370 * Back in the old days when we still had component-less DAIs,
2371 * instead of having a static name, component-less DAIs would
2372 * inherit the name of the parent device so it is possible to
2373 * register multiple instances of the DAI. We still need to keep
2374 * the same naming style even though those DAIs are not
2375 * component-less anymore.
2377 if (legacy_dai_naming &&
2378 (dai_drv->id == 0 || dai_drv->name == NULL)) {
2379 dai->name = fmt_single_name(dev, &dai->id);
2380 } else {
2381 dai->name = fmt_multiple_name(dev, dai_drv);
2382 if (dai_drv->id)
2383 dai->id = dai_drv->id;
2384 else
2385 dai->id = component->num_dai;
2387 if (!dai->name)
2388 return NULL;
2390 dai->component = component;
2391 dai->dev = dev;
2392 dai->driver = dai_drv;
2393 if (!dai->driver->ops)
2394 dai->driver->ops = &null_dai_ops;
2396 /* see for_each_component_dais */
2397 list_add_tail(&dai->list, &component->dai_list);
2398 component->num_dai++;
2400 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
2401 return dai;
2405 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
2407 * @component: The component for which the DAIs should be unregistered
2409 static void snd_soc_unregister_dais(struct snd_soc_component *component)
2411 struct snd_soc_dai *dai, *_dai;
2413 for_each_component_dais_safe(component, dai, _dai)
2414 snd_soc_unregister_dai(dai);
2418 * snd_soc_register_dais - Register a DAI with the ASoC core
2420 * @component: The component the DAIs are registered for
2421 * @dai_drv: DAI driver to use for the DAIs
2422 * @count: Number of DAIs
2424 static int snd_soc_register_dais(struct snd_soc_component *component,
2425 struct snd_soc_dai_driver *dai_drv,
2426 size_t count)
2428 struct snd_soc_dai *dai;
2429 unsigned int i;
2430 int ret;
2432 for (i = 0; i < count; i++) {
2433 dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
2434 !component->driver->non_legacy_dai_naming);
2435 if (dai == NULL) {
2436 ret = -ENOMEM;
2437 goto err;
2441 return 0;
2443 err:
2444 snd_soc_unregister_dais(component);
2446 return ret;
2449 static int snd_soc_component_initialize(struct snd_soc_component *component,
2450 const struct snd_soc_component_driver *driver, struct device *dev)
2452 INIT_LIST_HEAD(&component->dai_list);
2453 INIT_LIST_HEAD(&component->dobj_list);
2454 INIT_LIST_HEAD(&component->card_list);
2455 mutex_init(&component->io_mutex);
2457 component->name = fmt_single_name(dev, &component->id);
2458 if (!component->name) {
2459 dev_err(dev, "ASoC: Failed to allocate name\n");
2460 return -ENOMEM;
2463 component->dev = dev;
2464 component->driver = driver;
2466 return 0;
2469 static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
2471 int val_bytes = regmap_get_val_bytes(component->regmap);
2473 /* Errors are legitimate for non-integer byte multiples */
2474 if (val_bytes > 0)
2475 component->val_bytes = val_bytes;
2478 #ifdef CONFIG_REGMAP
2481 * snd_soc_component_init_regmap() - Initialize regmap instance for the
2482 * component
2483 * @component: The component for which to initialize the regmap instance
2484 * @regmap: The regmap instance that should be used by the component
2486 * This function allows deferred assignment of the regmap instance that is
2487 * associated with the component. Only use this if the regmap instance is not
2488 * yet ready when the component is registered. The function must also be called
2489 * before the first IO attempt of the component.
2491 void snd_soc_component_init_regmap(struct snd_soc_component *component,
2492 struct regmap *regmap)
2494 component->regmap = regmap;
2495 snd_soc_component_setup_regmap(component);
2497 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
2500 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
2501 * component
2502 * @component: The component for which to de-initialize the regmap instance
2504 * Calls regmap_exit() on the regmap instance associated to the component and
2505 * removes the regmap instance from the component.
2507 * This function should only be used if snd_soc_component_init_regmap() was used
2508 * to initialize the regmap instance.
2510 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
2512 regmap_exit(component->regmap);
2513 component->regmap = NULL;
2515 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
2517 #endif
2519 #define ENDIANNESS_MAP(name) \
2520 (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
2521 static u64 endianness_format_map[] = {
2522 ENDIANNESS_MAP(S16_),
2523 ENDIANNESS_MAP(U16_),
2524 ENDIANNESS_MAP(S24_),
2525 ENDIANNESS_MAP(U24_),
2526 ENDIANNESS_MAP(S32_),
2527 ENDIANNESS_MAP(U32_),
2528 ENDIANNESS_MAP(S24_3),
2529 ENDIANNESS_MAP(U24_3),
2530 ENDIANNESS_MAP(S20_3),
2531 ENDIANNESS_MAP(U20_3),
2532 ENDIANNESS_MAP(S18_3),
2533 ENDIANNESS_MAP(U18_3),
2534 ENDIANNESS_MAP(FLOAT_),
2535 ENDIANNESS_MAP(FLOAT64_),
2536 ENDIANNESS_MAP(IEC958_SUBFRAME_),
2540 * Fix up the DAI formats for endianness: codecs don't actually see
2541 * the endianness of the data but we're using the CPU format
2542 * definitions which do need to include endianness so we ensure that
2543 * codec DAIs always have both big and little endian variants set.
2545 static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
2547 int i;
2549 for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
2550 if (stream->formats & endianness_format_map[i])
2551 stream->formats |= endianness_format_map[i];
2554 static void snd_soc_try_rebind_card(void)
2556 struct snd_soc_card *card, *c;
2558 list_for_each_entry_safe(card, c, &unbind_card_list, list)
2559 if (!snd_soc_bind_card(card))
2560 list_del(&card->list);
2563 static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
2565 struct snd_soc_card *card = component->card;
2567 snd_soc_unregister_dais(component);
2569 if (card)
2570 snd_soc_unbind_card(card, false);
2572 list_del(&component->list);
2575 int snd_soc_add_component(struct device *dev,
2576 struct snd_soc_component *component,
2577 const struct snd_soc_component_driver *component_driver,
2578 struct snd_soc_dai_driver *dai_drv,
2579 int num_dai)
2581 int ret;
2582 int i;
2584 mutex_lock(&client_mutex);
2586 ret = snd_soc_component_initialize(component, component_driver, dev);
2587 if (ret)
2588 goto err_free;
2590 if (component_driver->endianness) {
2591 for (i = 0; i < num_dai; i++) {
2592 convert_endianness_formats(&dai_drv[i].playback);
2593 convert_endianness_formats(&dai_drv[i].capture);
2597 ret = snd_soc_register_dais(component, dai_drv, num_dai);
2598 if (ret < 0) {
2599 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
2600 goto err_cleanup;
2603 if (!component->driver->write && !component->driver->read) {
2604 if (!component->regmap)
2605 component->regmap = dev_get_regmap(component->dev,
2606 NULL);
2607 if (component->regmap)
2608 snd_soc_component_setup_regmap(component);
2611 /* see for_each_component */
2612 list_add(&component->list, &component_list);
2614 err_cleanup:
2615 if (ret < 0)
2616 snd_soc_del_component_unlocked(component);
2617 err_free:
2618 mutex_unlock(&client_mutex);
2620 if (ret == 0)
2621 snd_soc_try_rebind_card();
2623 return ret;
2625 EXPORT_SYMBOL_GPL(snd_soc_add_component);
2627 int snd_soc_register_component(struct device *dev,
2628 const struct snd_soc_component_driver *component_driver,
2629 struct snd_soc_dai_driver *dai_drv,
2630 int num_dai)
2632 struct snd_soc_component *component;
2634 component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
2635 if (!component)
2636 return -ENOMEM;
2638 return snd_soc_add_component(dev, component, component_driver,
2639 dai_drv, num_dai);
2641 EXPORT_SYMBOL_GPL(snd_soc_register_component);
2644 * snd_soc_unregister_component - Unregister all related component
2645 * from the ASoC core
2647 * @dev: The device to unregister
2649 void snd_soc_unregister_component(struct device *dev)
2651 struct snd_soc_component *component;
2653 mutex_lock(&client_mutex);
2654 while (1) {
2655 component = snd_soc_lookup_component_nolocked(dev, NULL);
2656 if (!component)
2657 break;
2659 snd_soc_del_component_unlocked(component);
2661 mutex_unlock(&client_mutex);
2663 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
2665 /* Retrieve a card's name from device tree */
2666 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
2667 const char *propname)
2669 struct device_node *np;
2670 int ret;
2672 if (!card->dev) {
2673 pr_err("card->dev is not set before calling %s\n", __func__);
2674 return -EINVAL;
2677 np = card->dev->of_node;
2679 ret = of_property_read_string_index(np, propname, 0, &card->name);
2681 * EINVAL means the property does not exist. This is fine providing
2682 * card->name was previously set, which is checked later in
2683 * snd_soc_register_card.
2685 if (ret < 0 && ret != -EINVAL) {
2686 dev_err(card->dev,
2687 "ASoC: Property '%s' could not be read: %d\n",
2688 propname, ret);
2689 return ret;
2692 return 0;
2694 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
2696 static const struct snd_soc_dapm_widget simple_widgets[] = {
2697 SND_SOC_DAPM_MIC("Microphone", NULL),
2698 SND_SOC_DAPM_LINE("Line", NULL),
2699 SND_SOC_DAPM_HP("Headphone", NULL),
2700 SND_SOC_DAPM_SPK("Speaker", NULL),
2703 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
2704 const char *propname)
2706 struct device_node *np = card->dev->of_node;
2707 struct snd_soc_dapm_widget *widgets;
2708 const char *template, *wname;
2709 int i, j, num_widgets, ret;
2711 num_widgets = of_property_count_strings(np, propname);
2712 if (num_widgets < 0) {
2713 dev_err(card->dev,
2714 "ASoC: Property '%s' does not exist\n", propname);
2715 return -EINVAL;
2717 if (num_widgets & 1) {
2718 dev_err(card->dev,
2719 "ASoC: Property '%s' length is not even\n", propname);
2720 return -EINVAL;
2723 num_widgets /= 2;
2724 if (!num_widgets) {
2725 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
2726 propname);
2727 return -EINVAL;
2730 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
2731 GFP_KERNEL);
2732 if (!widgets) {
2733 dev_err(card->dev,
2734 "ASoC: Could not allocate memory for widgets\n");
2735 return -ENOMEM;
2738 for (i = 0; i < num_widgets; i++) {
2739 ret = of_property_read_string_index(np, propname,
2740 2 * i, &template);
2741 if (ret) {
2742 dev_err(card->dev,
2743 "ASoC: Property '%s' index %d read error:%d\n",
2744 propname, 2 * i, ret);
2745 return -EINVAL;
2748 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
2749 if (!strncmp(template, simple_widgets[j].name,
2750 strlen(simple_widgets[j].name))) {
2751 widgets[i] = simple_widgets[j];
2752 break;
2756 if (j >= ARRAY_SIZE(simple_widgets)) {
2757 dev_err(card->dev,
2758 "ASoC: DAPM widget '%s' is not supported\n",
2759 template);
2760 return -EINVAL;
2763 ret = of_property_read_string_index(np, propname,
2764 (2 * i) + 1,
2765 &wname);
2766 if (ret) {
2767 dev_err(card->dev,
2768 "ASoC: Property '%s' index %d read error:%d\n",
2769 propname, (2 * i) + 1, ret);
2770 return -EINVAL;
2773 widgets[i].name = wname;
2776 card->of_dapm_widgets = widgets;
2777 card->num_of_dapm_widgets = num_widgets;
2779 return 0;
2781 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
2783 int snd_soc_of_get_slot_mask(struct device_node *np,
2784 const char *prop_name,
2785 unsigned int *mask)
2787 u32 val;
2788 const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
2789 int i;
2791 if (!of_slot_mask)
2792 return 0;
2793 val /= sizeof(u32);
2794 for (i = 0; i < val; i++)
2795 if (be32_to_cpup(&of_slot_mask[i]))
2796 *mask |= (1 << i);
2798 return val;
2800 EXPORT_SYMBOL_GPL(snd_soc_of_get_slot_mask);
2802 int snd_soc_of_parse_tdm_slot(struct device_node *np,
2803 unsigned int *tx_mask,
2804 unsigned int *rx_mask,
2805 unsigned int *slots,
2806 unsigned int *slot_width)
2808 u32 val;
2809 int ret;
2811 if (tx_mask)
2812 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
2813 if (rx_mask)
2814 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
2816 if (of_property_read_bool(np, "dai-tdm-slot-num")) {
2817 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
2818 if (ret)
2819 return ret;
2821 if (slots)
2822 *slots = val;
2825 if (of_property_read_bool(np, "dai-tdm-slot-width")) {
2826 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
2827 if (ret)
2828 return ret;
2830 if (slot_width)
2831 *slot_width = val;
2834 return 0;
2836 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
2838 void snd_soc_of_parse_node_prefix(struct device_node *np,
2839 struct snd_soc_codec_conf *codec_conf,
2840 struct device_node *of_node,
2841 const char *propname)
2843 const char *str;
2844 int ret;
2846 ret = of_property_read_string(np, propname, &str);
2847 if (ret < 0) {
2848 /* no prefix is not error */
2849 return;
2852 codec_conf->dlc.of_node = of_node;
2853 codec_conf->name_prefix = str;
2855 EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix);
2857 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
2858 const char *propname)
2860 struct device_node *np = card->dev->of_node;
2861 int num_routes;
2862 struct snd_soc_dapm_route *routes;
2863 int i, ret;
2865 num_routes = of_property_count_strings(np, propname);
2866 if (num_routes < 0 || num_routes & 1) {
2867 dev_err(card->dev,
2868 "ASoC: Property '%s' does not exist or its length is not even\n",
2869 propname);
2870 return -EINVAL;
2872 num_routes /= 2;
2873 if (!num_routes) {
2874 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
2875 propname);
2876 return -EINVAL;
2879 routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes),
2880 GFP_KERNEL);
2881 if (!routes) {
2882 dev_err(card->dev,
2883 "ASoC: Could not allocate DAPM route table\n");
2884 return -EINVAL;
2887 for (i = 0; i < num_routes; i++) {
2888 ret = of_property_read_string_index(np, propname,
2889 2 * i, &routes[i].sink);
2890 if (ret) {
2891 dev_err(card->dev,
2892 "ASoC: Property '%s' index %d could not be read: %d\n",
2893 propname, 2 * i, ret);
2894 return -EINVAL;
2896 ret = of_property_read_string_index(np, propname,
2897 (2 * i) + 1, &routes[i].source);
2898 if (ret) {
2899 dev_err(card->dev,
2900 "ASoC: Property '%s' index %d could not be read: %d\n",
2901 propname, (2 * i) + 1, ret);
2902 return -EINVAL;
2906 card->num_of_dapm_routes = num_routes;
2907 card->of_dapm_routes = routes;
2909 return 0;
2911 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
2913 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
2914 const char *prefix,
2915 struct device_node **bitclkmaster,
2916 struct device_node **framemaster)
2918 int ret, i;
2919 char prop[128];
2920 unsigned int format = 0;
2921 int bit, frame;
2922 const char *str;
2923 struct {
2924 char *name;
2925 unsigned int val;
2926 } of_fmt_table[] = {
2927 { "i2s", SND_SOC_DAIFMT_I2S },
2928 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
2929 { "left_j", SND_SOC_DAIFMT_LEFT_J },
2930 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
2931 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
2932 { "ac97", SND_SOC_DAIFMT_AC97 },
2933 { "pdm", SND_SOC_DAIFMT_PDM},
2934 { "msb", SND_SOC_DAIFMT_MSB },
2935 { "lsb", SND_SOC_DAIFMT_LSB },
2938 if (!prefix)
2939 prefix = "";
2942 * check "dai-format = xxx"
2943 * or "[prefix]format = xxx"
2944 * SND_SOC_DAIFMT_FORMAT_MASK area
2946 ret = of_property_read_string(np, "dai-format", &str);
2947 if (ret < 0) {
2948 snprintf(prop, sizeof(prop), "%sformat", prefix);
2949 ret = of_property_read_string(np, prop, &str);
2951 if (ret == 0) {
2952 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
2953 if (strcmp(str, of_fmt_table[i].name) == 0) {
2954 format |= of_fmt_table[i].val;
2955 break;
2961 * check "[prefix]continuous-clock"
2962 * SND_SOC_DAIFMT_CLOCK_MASK area
2964 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
2965 if (of_property_read_bool(np, prop))
2966 format |= SND_SOC_DAIFMT_CONT;
2967 else
2968 format |= SND_SOC_DAIFMT_GATED;
2971 * check "[prefix]bitclock-inversion"
2972 * check "[prefix]frame-inversion"
2973 * SND_SOC_DAIFMT_INV_MASK area
2975 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
2976 bit = !!of_get_property(np, prop, NULL);
2978 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
2979 frame = !!of_get_property(np, prop, NULL);
2981 switch ((bit << 4) + frame) {
2982 case 0x11:
2983 format |= SND_SOC_DAIFMT_IB_IF;
2984 break;
2985 case 0x10:
2986 format |= SND_SOC_DAIFMT_IB_NF;
2987 break;
2988 case 0x01:
2989 format |= SND_SOC_DAIFMT_NB_IF;
2990 break;
2991 default:
2992 /* SND_SOC_DAIFMT_NB_NF is default */
2993 break;
2997 * check "[prefix]bitclock-master"
2998 * check "[prefix]frame-master"
2999 * SND_SOC_DAIFMT_MASTER_MASK area
3001 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
3002 bit = !!of_get_property(np, prop, NULL);
3003 if (bit && bitclkmaster)
3004 *bitclkmaster = of_parse_phandle(np, prop, 0);
3006 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
3007 frame = !!of_get_property(np, prop, NULL);
3008 if (frame && framemaster)
3009 *framemaster = of_parse_phandle(np, prop, 0);
3011 switch ((bit << 4) + frame) {
3012 case 0x11:
3013 format |= SND_SOC_DAIFMT_CBM_CFM;
3014 break;
3015 case 0x10:
3016 format |= SND_SOC_DAIFMT_CBM_CFS;
3017 break;
3018 case 0x01:
3019 format |= SND_SOC_DAIFMT_CBS_CFM;
3020 break;
3021 default:
3022 format |= SND_SOC_DAIFMT_CBS_CFS;
3023 break;
3026 return format;
3028 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
3030 int snd_soc_get_dai_id(struct device_node *ep)
3032 struct snd_soc_component *component;
3033 struct snd_soc_dai_link_component dlc;
3034 int ret;
3036 dlc.of_node = of_graph_get_port_parent(ep);
3037 dlc.name = NULL;
3039 * For example HDMI case, HDMI has video/sound port,
3040 * but ALSA SoC needs sound port number only.
3041 * Thus counting HDMI DT port/endpoint doesn't work.
3042 * Then, it should have .of_xlate_dai_id
3044 ret = -ENOTSUPP;
3045 mutex_lock(&client_mutex);
3046 component = soc_find_component(&dlc);
3047 if (component)
3048 ret = snd_soc_component_of_xlate_dai_id(component, ep);
3049 mutex_unlock(&client_mutex);
3051 of_node_put(dlc.of_node);
3053 return ret;
3055 EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
3057 int snd_soc_get_dai_name(struct of_phandle_args *args,
3058 const char **dai_name)
3060 struct snd_soc_component *pos;
3061 struct device_node *component_of_node;
3062 int ret = -EPROBE_DEFER;
3064 mutex_lock(&client_mutex);
3065 for_each_component(pos) {
3066 component_of_node = soc_component_to_node(pos);
3068 if (component_of_node != args->np)
3069 continue;
3071 ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
3072 if (ret == -ENOTSUPP) {
3073 struct snd_soc_dai *dai;
3074 int id = -1;
3076 switch (args->args_count) {
3077 case 0:
3078 id = 0; /* same as dai_drv[0] */
3079 break;
3080 case 1:
3081 id = args->args[0];
3082 break;
3083 default:
3084 /* not supported */
3085 break;
3088 if (id < 0 || id >= pos->num_dai) {
3089 ret = -EINVAL;
3090 continue;
3093 ret = 0;
3095 /* find target DAI */
3096 for_each_component_dais(pos, dai) {
3097 if (id == 0)
3098 break;
3099 id--;
3102 *dai_name = dai->driver->name;
3103 if (!*dai_name)
3104 *dai_name = pos->name;
3107 break;
3109 mutex_unlock(&client_mutex);
3110 return ret;
3112 EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
3114 int snd_soc_of_get_dai_name(struct device_node *of_node,
3115 const char **dai_name)
3117 struct of_phandle_args args;
3118 int ret;
3120 ret = of_parse_phandle_with_args(of_node, "sound-dai",
3121 "#sound-dai-cells", 0, &args);
3122 if (ret)
3123 return ret;
3125 ret = snd_soc_get_dai_name(&args, dai_name);
3127 of_node_put(args.np);
3129 return ret;
3131 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
3134 * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
3135 * @dai_link: DAI link
3137 * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
3139 void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
3141 struct snd_soc_dai_link_component *component;
3142 int index;
3144 for_each_link_codecs(dai_link, index, component) {
3145 if (!component->of_node)
3146 break;
3147 of_node_put(component->of_node);
3148 component->of_node = NULL;
3151 EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
3154 * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
3155 * @dev: Card device
3156 * @of_node: Device node
3157 * @dai_link: DAI link
3159 * Builds an array of CODEC DAI components from the DAI link property
3160 * 'sound-dai'.
3161 * The array is set in the DAI link and the number of DAIs is set accordingly.
3162 * The device nodes in the array (of_node) must be dereferenced by calling
3163 * snd_soc_of_put_dai_link_codecs() on @dai_link.
3165 * Returns 0 for success
3167 int snd_soc_of_get_dai_link_codecs(struct device *dev,
3168 struct device_node *of_node,
3169 struct snd_soc_dai_link *dai_link)
3171 struct of_phandle_args args;
3172 struct snd_soc_dai_link_component *component;
3173 char *name;
3174 int index, num_codecs, ret;
3176 /* Count the number of CODECs */
3177 name = "sound-dai";
3178 num_codecs = of_count_phandle_with_args(of_node, name,
3179 "#sound-dai-cells");
3180 if (num_codecs <= 0) {
3181 if (num_codecs == -ENOENT)
3182 dev_err(dev, "No 'sound-dai' property\n");
3183 else
3184 dev_err(dev, "Bad phandle in 'sound-dai'\n");
3185 return num_codecs;
3187 component = devm_kcalloc(dev,
3188 num_codecs, sizeof(*component),
3189 GFP_KERNEL);
3190 if (!component)
3191 return -ENOMEM;
3192 dai_link->codecs = component;
3193 dai_link->num_codecs = num_codecs;
3195 /* Parse the list */
3196 for_each_link_codecs(dai_link, index, component) {
3197 ret = of_parse_phandle_with_args(of_node, name,
3198 "#sound-dai-cells",
3199 index, &args);
3200 if (ret)
3201 goto err;
3202 component->of_node = args.np;
3203 ret = snd_soc_get_dai_name(&args, &component->dai_name);
3204 if (ret < 0)
3205 goto err;
3207 return 0;
3208 err:
3209 snd_soc_of_put_dai_link_codecs(dai_link);
3210 dai_link->codecs = NULL;
3211 dai_link->num_codecs = 0;
3212 return ret;
3214 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
3216 static int __init snd_soc_init(void)
3218 snd_soc_debugfs_init();
3219 snd_soc_util_init();
3221 return platform_driver_register(&soc_driver);
3223 module_init(snd_soc_init);
3225 static void __exit snd_soc_exit(void)
3227 snd_soc_util_exit();
3228 snd_soc_debugfs_exit();
3230 platform_driver_unregister(&soc_driver);
3232 module_exit(snd_soc_exit);
3234 /* Module information */
3235 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3236 MODULE_DESCRIPTION("ALSA SoC Core");
3237 MODULE_LICENSE("GPL");
3238 MODULE_ALIAS("platform:soc-audio");