2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
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.
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
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.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>
37 #include <linux/dmi.h>
38 #include <sound/core.h>
39 #include <sound/jack.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/soc.h>
43 #include <sound/soc-dpcm.h>
44 #include <sound/soc-topology.h>
45 #include <sound/initval.h>
47 #define CREATE_TRACE_POINTS
48 #include <trace/events/asoc.h>
52 #ifdef CONFIG_DEBUG_FS
53 struct dentry *snd_soc_debugfs_root;
54 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
57 static DEFINE_MUTEX(client_mutex);
58 static LIST_HEAD(platform_list);
59 static LIST_HEAD(codec_list);
60 static LIST_HEAD(component_list);
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 /* 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.
75 static const char * const dmi_blacklist[] = {
76 "To be filled by OEM",
82 NULL, /* terminator */
85 /* returns the minimum number of bytes needed to represent
86 * a particular given value */
87 static int min_bytes_needed(unsigned long val)
92 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
95 c = (sizeof val * 8) - c;
103 /* fill buf which is 'len' bytes with a formatted
104 * string of the form 'reg: value\n' */
105 static int format_register_str(struct snd_soc_codec *codec,
106 unsigned int reg, char *buf, size_t len)
108 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
109 int regsize = codec->driver->reg_word_size * 2;
112 /* +2 for ': ' and + 1 for '\n' */
113 if (wordsize + regsize + 2 + 1 != len)
116 sprintf(buf, "%.*x: ", wordsize, reg);
119 ret = snd_soc_read(codec, reg);
121 memset(buf, 'X', regsize);
123 sprintf(buf, "%.*x", regsize, ret);
125 /* no NUL-termination needed */
129 /* codec register dump */
130 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
131 size_t count, loff_t pos)
134 int wordsize, regsize;
139 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
140 regsize = codec->driver->reg_word_size * 2;
142 len = wordsize + regsize + 2 + 1;
144 if (!codec->driver->reg_cache_size)
147 if (codec->driver->reg_cache_step)
148 step = codec->driver->reg_cache_step;
150 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
151 /* only support larger than PAGE_SIZE bytes debugfs
152 * entries for the default case */
154 if (total + len >= count - 1)
156 format_register_str(codec, i, buf + total, len);
162 total = min(total, count - 1);
167 static ssize_t codec_reg_show(struct device *dev,
168 struct device_attribute *attr, char *buf)
170 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
172 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
175 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
177 static ssize_t pmdown_time_show(struct device *dev,
178 struct device_attribute *attr, char *buf)
180 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
182 return sprintf(buf, "%ld\n", rtd->pmdown_time);
185 static ssize_t pmdown_time_set(struct device *dev,
186 struct device_attribute *attr,
187 const char *buf, size_t count)
189 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
192 ret = kstrtol(buf, 10, &rtd->pmdown_time);
199 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
201 static struct attribute *soc_dev_attrs[] = {
202 &dev_attr_codec_reg.attr,
203 &dev_attr_pmdown_time.attr,
207 static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
208 struct attribute *attr, int idx)
210 struct device *dev = kobj_to_dev(kobj);
211 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
213 if (attr == &dev_attr_pmdown_time.attr)
214 return attr->mode; /* always visible */
215 return rtd->codec ? attr->mode : 0; /* enabled only with codec */
218 static const struct attribute_group soc_dapm_dev_group = {
219 .attrs = soc_dapm_dev_attrs,
220 .is_visible = soc_dev_attr_is_visible,
223 static const struct attribute_group soc_dev_roup = {
224 .attrs = soc_dev_attrs,
225 .is_visible = soc_dev_attr_is_visible,
228 static const struct attribute_group *soc_dev_attr_groups[] = {
234 #ifdef CONFIG_DEBUG_FS
235 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
236 size_t count, loff_t *ppos)
239 struct snd_soc_codec *codec = file->private_data;
242 if (*ppos < 0 || !count)
245 buf = kmalloc(count, GFP_KERNEL);
249 ret = soc_codec_reg_show(codec, buf, count, *ppos);
251 if (copy_to_user(user_buf, buf, ret)) {
262 static ssize_t codec_reg_write_file(struct file *file,
263 const char __user *user_buf, size_t count, loff_t *ppos)
268 unsigned long reg, value;
269 struct snd_soc_codec *codec = file->private_data;
272 buf_size = min(count, (sizeof(buf)-1));
273 if (copy_from_user(buf, user_buf, buf_size))
277 while (*start == ' ')
279 reg = simple_strtoul(start, &start, 16);
280 while (*start == ' ')
282 ret = kstrtoul(start, 16, &value);
286 /* Userspace has been fiddling around behind the kernel's back */
287 add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
289 snd_soc_write(codec, reg, value);
293 static const struct file_operations codec_reg_fops = {
295 .read = codec_reg_read_file,
296 .write = codec_reg_write_file,
297 .llseek = default_llseek,
300 static void soc_init_component_debugfs(struct snd_soc_component *component)
302 if (!component->card->debugfs_card_root)
305 if (component->debugfs_prefix) {
308 name = kasprintf(GFP_KERNEL, "%s:%s",
309 component->debugfs_prefix, component->name);
311 component->debugfs_root = debugfs_create_dir(name,
312 component->card->debugfs_card_root);
316 component->debugfs_root = debugfs_create_dir(component->name,
317 component->card->debugfs_card_root);
320 if (!component->debugfs_root) {
321 dev_warn(component->dev,
322 "ASoC: Failed to create component debugfs directory\n");
326 snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
327 component->debugfs_root);
329 if (component->init_debugfs)
330 component->init_debugfs(component);
333 static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
335 debugfs_remove_recursive(component->debugfs_root);
338 static void soc_init_codec_debugfs(struct snd_soc_component *component)
340 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
342 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
343 codec->component.debugfs_root,
344 codec, &codec_reg_fops);
345 if (!codec->debugfs_reg)
347 "ASoC: Failed to create codec register debugfs file\n");
350 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
351 size_t count, loff_t *ppos)
353 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
354 ssize_t len, ret = 0;
355 struct snd_soc_codec *codec;
360 mutex_lock(&client_mutex);
362 list_for_each_entry(codec, &codec_list, list) {
363 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
364 codec->component.name);
367 if (ret > PAGE_SIZE) {
373 mutex_unlock(&client_mutex);
376 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
383 static const struct file_operations codec_list_fops = {
384 .read = codec_list_read_file,
385 .llseek = default_llseek,/* read accesses f_pos */
388 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
389 size_t count, loff_t *ppos)
391 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
392 ssize_t len, ret = 0;
393 struct snd_soc_component *component;
394 struct snd_soc_dai *dai;
399 mutex_lock(&client_mutex);
401 list_for_each_entry(component, &component_list, list) {
402 list_for_each_entry(dai, &component->dai_list, list) {
403 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
407 if (ret > PAGE_SIZE) {
414 mutex_unlock(&client_mutex);
416 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
423 static const struct file_operations dai_list_fops = {
424 .read = dai_list_read_file,
425 .llseek = default_llseek,/* read accesses f_pos */
428 static ssize_t platform_list_read_file(struct file *file,
429 char __user *user_buf,
430 size_t count, loff_t *ppos)
432 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
433 ssize_t len, ret = 0;
434 struct snd_soc_platform *platform;
439 mutex_lock(&client_mutex);
441 list_for_each_entry(platform, &platform_list, list) {
442 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
443 platform->component.name);
446 if (ret > PAGE_SIZE) {
452 mutex_unlock(&client_mutex);
454 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
461 static const struct file_operations platform_list_fops = {
462 .read = platform_list_read_file,
463 .llseek = default_llseek,/* read accesses f_pos */
466 static void soc_init_card_debugfs(struct snd_soc_card *card)
468 if (!snd_soc_debugfs_root)
471 card->debugfs_card_root = debugfs_create_dir(card->name,
472 snd_soc_debugfs_root);
473 if (!card->debugfs_card_root) {
475 "ASoC: Failed to create card debugfs directory\n");
479 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
480 card->debugfs_card_root,
482 if (!card->debugfs_pop_time)
484 "ASoC: Failed to create pop time debugfs file\n");
487 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
489 debugfs_remove_recursive(card->debugfs_card_root);
493 static void snd_soc_debugfs_init(void)
495 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
496 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
497 pr_warn("ASoC: Failed to create debugfs directory\n");
498 snd_soc_debugfs_root = NULL;
502 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
504 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
506 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
508 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
510 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
511 &platform_list_fops))
512 pr_warn("ASoC: Failed to create platform list debugfs file\n");
515 static void snd_soc_debugfs_exit(void)
517 debugfs_remove_recursive(snd_soc_debugfs_root);
522 #define soc_init_codec_debugfs NULL
524 static inline void soc_init_component_debugfs(
525 struct snd_soc_component *component)
529 static inline void soc_cleanup_component_debugfs(
530 struct snd_soc_component *component)
534 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
538 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
542 static inline void snd_soc_debugfs_init(void)
546 static inline void snd_soc_debugfs_exit(void)
552 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
553 const char *dai_link, int stream)
555 struct snd_soc_pcm_runtime *rtd;
557 list_for_each_entry(rtd, &card->rtd_list, list) {
558 if (rtd->dai_link->no_pcm &&
559 !strcmp(rtd->dai_link->name, dai_link))
560 return rtd->pcm->streams[stream].substream;
562 dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
565 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
567 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
568 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
570 struct snd_soc_pcm_runtime *rtd;
572 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
577 rtd->dai_link = dai_link;
578 rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) *
579 dai_link->num_codecs,
581 if (!rtd->codec_dais) {
589 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
591 if (rtd && rtd->codec_dais)
592 kfree(rtd->codec_dais);
596 static void soc_add_pcm_runtime(struct snd_soc_card *card,
597 struct snd_soc_pcm_runtime *rtd)
599 list_add_tail(&rtd->list, &card->rtd_list);
600 rtd->num = card->num_rtd;
604 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
606 struct snd_soc_pcm_runtime *rtd, *_rtd;
608 list_for_each_entry_safe(rtd, _rtd, &card->rtd_list, list) {
609 list_del(&rtd->list);
610 soc_free_pcm_runtime(rtd);
616 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
617 const char *dai_link)
619 struct snd_soc_pcm_runtime *rtd;
621 list_for_each_entry(rtd, &card->rtd_list, list) {
622 if (!strcmp(rtd->dai_link->name, dai_link))
625 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
628 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
630 static void codec2codec_close_delayed_work(struct work_struct *work)
632 /* Currently nothing to do for c2c links
633 * Since c2c links are internal nodes in the DAPM graph and
634 * don't interface with the outside world or application layer
635 * we don't have to do any special handling on close.
639 #ifdef CONFIG_PM_SLEEP
640 /* powers down audio subsystem for suspend */
641 int snd_soc_suspend(struct device *dev)
643 struct snd_soc_card *card = dev_get_drvdata(dev);
644 struct snd_soc_component *component;
645 struct snd_soc_pcm_runtime *rtd;
648 /* If the card is not initialized yet there is nothing to do */
649 if (!card->instantiated)
652 /* Due to the resume being scheduled into a workqueue we could
653 * suspend before that's finished - wait for it to complete.
655 snd_power_lock(card->snd_card);
656 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
657 snd_power_unlock(card->snd_card);
659 /* we're going to block userspace touching us until resume completes */
660 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
662 /* mute any active DACs */
663 list_for_each_entry(rtd, &card->rtd_list, list) {
665 if (rtd->dai_link->ignore_suspend)
668 for (i = 0; i < rtd->num_codecs; i++) {
669 struct snd_soc_dai *dai = rtd->codec_dais[i];
670 struct snd_soc_dai_driver *drv = dai->driver;
672 if (drv->ops->digital_mute && dai->playback_active)
673 drv->ops->digital_mute(dai, 1);
677 /* suspend all pcms */
678 list_for_each_entry(rtd, &card->rtd_list, list) {
679 if (rtd->dai_link->ignore_suspend)
682 snd_pcm_suspend_all(rtd->pcm);
685 if (card->suspend_pre)
686 card->suspend_pre(card);
688 list_for_each_entry(rtd, &card->rtd_list, list) {
689 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
691 if (rtd->dai_link->ignore_suspend)
694 if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control)
695 cpu_dai->driver->suspend(cpu_dai);
698 /* close any waiting streams */
699 list_for_each_entry(rtd, &card->rtd_list, list)
700 flush_delayed_work(&rtd->delayed_work);
702 list_for_each_entry(rtd, &card->rtd_list, list) {
704 if (rtd->dai_link->ignore_suspend)
707 snd_soc_dapm_stream_event(rtd,
708 SNDRV_PCM_STREAM_PLAYBACK,
709 SND_SOC_DAPM_STREAM_SUSPEND);
711 snd_soc_dapm_stream_event(rtd,
712 SNDRV_PCM_STREAM_CAPTURE,
713 SND_SOC_DAPM_STREAM_SUSPEND);
716 /* Recheck all endpoints too, their state is affected by suspend */
717 dapm_mark_endpoints_dirty(card);
718 snd_soc_dapm_sync(&card->dapm);
720 /* suspend all COMPONENTs */
721 list_for_each_entry(component, &card->component_dev_list, card_list) {
722 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
724 /* If there are paths active then the COMPONENT will be held with
725 * bias _ON and should not be suspended. */
726 if (!component->suspended) {
727 switch (snd_soc_dapm_get_bias_level(dapm)) {
728 case SND_SOC_BIAS_STANDBY:
730 * If the COMPONENT is capable of idle
731 * bias off then being in STANDBY
732 * means it's doing something,
733 * otherwise fall through.
735 if (dapm->idle_bias_off) {
736 dev_dbg(component->dev,
737 "ASoC: idle_bias_off CODEC on over suspend\n");
741 case SND_SOC_BIAS_OFF:
742 if (component->suspend)
743 component->suspend(component);
744 component->suspended = 1;
745 if (component->regmap)
746 regcache_mark_dirty(component->regmap);
747 /* deactivate pins to sleep state */
748 pinctrl_pm_select_sleep_state(component->dev);
751 dev_dbg(component->dev,
752 "ASoC: COMPONENT is on over suspend\n");
758 list_for_each_entry(rtd, &card->rtd_list, list) {
759 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
761 if (rtd->dai_link->ignore_suspend)
764 if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control)
765 cpu_dai->driver->suspend(cpu_dai);
767 /* deactivate pins to sleep state */
768 pinctrl_pm_select_sleep_state(cpu_dai->dev);
771 if (card->suspend_post)
772 card->suspend_post(card);
776 EXPORT_SYMBOL_GPL(snd_soc_suspend);
778 /* deferred resume work, so resume can complete before we finished
779 * setting our codec back up, which can be very slow on I2C
781 static void soc_resume_deferred(struct work_struct *work)
783 struct snd_soc_card *card =
784 container_of(work, struct snd_soc_card, deferred_resume_work);
785 struct snd_soc_pcm_runtime *rtd;
786 struct snd_soc_component *component;
789 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
790 * so userspace apps are blocked from touching us
793 dev_dbg(card->dev, "ASoC: starting resume work\n");
795 /* Bring us up into D2 so that DAPM starts enabling things */
796 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
798 if (card->resume_pre)
799 card->resume_pre(card);
801 /* resume control bus DAIs */
802 list_for_each_entry(rtd, &card->rtd_list, list) {
803 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
805 if (rtd->dai_link->ignore_suspend)
808 if (cpu_dai->driver->resume && cpu_dai->driver->bus_control)
809 cpu_dai->driver->resume(cpu_dai);
812 list_for_each_entry(component, &card->component_dev_list, card_list) {
813 if (component->suspended) {
814 if (component->resume)
815 component->resume(component);
816 component->suspended = 0;
820 list_for_each_entry(rtd, &card->rtd_list, list) {
822 if (rtd->dai_link->ignore_suspend)
825 snd_soc_dapm_stream_event(rtd,
826 SNDRV_PCM_STREAM_PLAYBACK,
827 SND_SOC_DAPM_STREAM_RESUME);
829 snd_soc_dapm_stream_event(rtd,
830 SNDRV_PCM_STREAM_CAPTURE,
831 SND_SOC_DAPM_STREAM_RESUME);
834 /* unmute any active DACs */
835 list_for_each_entry(rtd, &card->rtd_list, list) {
837 if (rtd->dai_link->ignore_suspend)
840 for (i = 0; i < rtd->num_codecs; i++) {
841 struct snd_soc_dai *dai = rtd->codec_dais[i];
842 struct snd_soc_dai_driver *drv = dai->driver;
844 if (drv->ops->digital_mute && dai->playback_active)
845 drv->ops->digital_mute(dai, 0);
849 list_for_each_entry(rtd, &card->rtd_list, list) {
850 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
852 if (rtd->dai_link->ignore_suspend)
855 if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control)
856 cpu_dai->driver->resume(cpu_dai);
859 if (card->resume_post)
860 card->resume_post(card);
862 dev_dbg(card->dev, "ASoC: resume work completed\n");
864 /* Recheck all endpoints too, their state is affected by suspend */
865 dapm_mark_endpoints_dirty(card);
866 snd_soc_dapm_sync(&card->dapm);
868 /* userspace can access us now we are back as we were before */
869 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
872 /* powers up audio subsystem after a suspend */
873 int snd_soc_resume(struct device *dev)
875 struct snd_soc_card *card = dev_get_drvdata(dev);
876 bool bus_control = false;
877 struct snd_soc_pcm_runtime *rtd;
879 /* If the card is not initialized yet there is nothing to do */
880 if (!card->instantiated)
883 /* activate pins from sleep state */
884 list_for_each_entry(rtd, &card->rtd_list, list) {
885 struct snd_soc_dai **codec_dais = rtd->codec_dais;
886 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
890 pinctrl_pm_select_default_state(cpu_dai->dev);
892 for (j = 0; j < rtd->num_codecs; j++) {
893 struct snd_soc_dai *codec_dai = codec_dais[j];
894 if (codec_dai->active)
895 pinctrl_pm_select_default_state(codec_dai->dev);
900 * DAIs that also act as the control bus master might have other drivers
901 * hanging off them so need to resume immediately. Other drivers don't
902 * have that problem and may take a substantial amount of time to resume
903 * due to I/O costs and anti-pop so handle them out of line.
905 list_for_each_entry(rtd, &card->rtd_list, list) {
906 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
907 bus_control |= cpu_dai->driver->bus_control;
910 dev_dbg(dev, "ASoC: Resuming control bus master immediately\n");
911 soc_resume_deferred(&card->deferred_resume_work);
913 dev_dbg(dev, "ASoC: Scheduling resume work\n");
914 if (!schedule_work(&card->deferred_resume_work))
915 dev_err(dev, "ASoC: resume work item may be lost\n");
920 EXPORT_SYMBOL_GPL(snd_soc_resume);
922 #define snd_soc_suspend NULL
923 #define snd_soc_resume NULL
926 static const struct snd_soc_dai_ops null_dai_ops = {
929 static struct snd_soc_component *soc_find_component(
930 const struct device_node *of_node, const char *name)
932 struct snd_soc_component *component;
934 lockdep_assert_held(&client_mutex);
936 list_for_each_entry(component, &component_list, list) {
938 if (component->dev->of_node == of_node)
940 } else if (strcmp(component->name, name) == 0) {
949 * snd_soc_find_dai - Find a registered DAI
951 * @dlc: name of the DAI and optional component info to match
953 * This function will search all registered components and their DAIs to
954 * find the DAI of the same name. The component's of_node and name
955 * should also match if being specified.
957 * Return: pointer of DAI, or NULL if not found.
959 struct snd_soc_dai *snd_soc_find_dai(
960 const struct snd_soc_dai_link_component *dlc)
962 struct snd_soc_component *component;
963 struct snd_soc_dai *dai;
964 struct device_node *component_of_node;
966 lockdep_assert_held(&client_mutex);
968 /* Find CPU DAI from registered DAIs*/
969 list_for_each_entry(component, &component_list, list) {
970 component_of_node = component->dev->of_node;
971 if (!component_of_node && component->dev->parent)
972 component_of_node = component->dev->parent->of_node;
974 if (dlc->of_node && component_of_node != dlc->of_node)
976 if (dlc->name && strcmp(component->name, dlc->name))
978 list_for_each_entry(dai, &component->dai_list, list) {
979 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
988 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
992 * snd_soc_find_dai_link - Find a DAI link
995 * @id: DAI link ID to match
996 * @name: DAI link name to match, optional
997 * @stream_name: DAI link stream name to match, optional
999 * This function will search all existing DAI links of the soc card to
1000 * find the link of the same ID. Since DAI links may not have their
1001 * unique ID, so name and stream name should also match if being
1004 * Return: pointer of DAI link, or NULL if not found.
1006 struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
1007 int id, const char *name,
1008 const char *stream_name)
1010 struct snd_soc_dai_link *link, *_link;
1012 lockdep_assert_held(&client_mutex);
1014 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1018 if (name && (!link->name || strcmp(name, link->name)))
1021 if (stream_name && (!link->stream_name
1022 || strcmp(stream_name, link->stream_name)))
1030 EXPORT_SYMBOL_GPL(snd_soc_find_dai_link);
1032 static bool soc_is_dai_link_bound(struct snd_soc_card *card,
1033 struct snd_soc_dai_link *dai_link)
1035 struct snd_soc_pcm_runtime *rtd;
1037 list_for_each_entry(rtd, &card->rtd_list, list) {
1038 if (rtd->dai_link == dai_link)
1045 static int soc_bind_dai_link(struct snd_soc_card *card,
1046 struct snd_soc_dai_link *dai_link)
1048 struct snd_soc_pcm_runtime *rtd;
1049 struct snd_soc_dai_link_component *codecs = dai_link->codecs;
1050 struct snd_soc_dai_link_component cpu_dai_component;
1051 struct snd_soc_dai **codec_dais;
1052 struct snd_soc_platform *platform;
1053 struct device_node *platform_of_node;
1054 const char *platform_name;
1057 dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
1059 if (soc_is_dai_link_bound(card, dai_link)) {
1060 dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
1065 rtd = soc_new_pcm_runtime(card, dai_link);
1069 cpu_dai_component.name = dai_link->cpu_name;
1070 cpu_dai_component.of_node = dai_link->cpu_of_node;
1071 cpu_dai_component.dai_name = dai_link->cpu_dai_name;
1072 rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
1073 if (!rtd->cpu_dai) {
1074 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
1075 dai_link->cpu_dai_name);
1079 rtd->num_codecs = dai_link->num_codecs;
1081 /* Find CODEC from registered CODECs */
1082 codec_dais = rtd->codec_dais;
1083 for (i = 0; i < rtd->num_codecs; i++) {
1084 codec_dais[i] = snd_soc_find_dai(&codecs[i]);
1085 if (!codec_dais[i]) {
1086 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
1087 codecs[i].dai_name);
1092 /* Single codec links expect codec and codec_dai in runtime data */
1093 rtd->codec_dai = codec_dais[0];
1094 rtd->codec = rtd->codec_dai->codec;
1096 /* if there's no platform we match on the empty platform */
1097 platform_name = dai_link->platform_name;
1098 if (!platform_name && !dai_link->platform_of_node)
1099 platform_name = "snd-soc-dummy";
1101 /* find one from the set of registered platforms */
1102 list_for_each_entry(platform, &platform_list, list) {
1103 platform_of_node = platform->dev->of_node;
1104 if (!platform_of_node && platform->dev->parent->of_node)
1105 platform_of_node = platform->dev->parent->of_node;
1107 if (dai_link->platform_of_node) {
1108 if (platform_of_node != dai_link->platform_of_node)
1111 if (strcmp(platform->component.name, platform_name))
1115 rtd->platform = platform;
1117 if (!rtd->platform) {
1118 dev_err(card->dev, "ASoC: platform %s not registered\n",
1119 dai_link->platform_name);
1123 soc_add_pcm_runtime(card, rtd);
1127 soc_free_pcm_runtime(rtd);
1128 return -EPROBE_DEFER;
1131 static void soc_remove_component(struct snd_soc_component *component)
1133 if (!component->card)
1136 list_del(&component->card_list);
1138 if (component->remove)
1139 component->remove(component);
1141 snd_soc_dapm_free(snd_soc_component_get_dapm(component));
1143 soc_cleanup_component_debugfs(component);
1144 component->card = NULL;
1145 module_put(component->dev->driver->owner);
1148 static void soc_remove_dai(struct snd_soc_dai *dai, int order)
1152 if (dai && dai->probed &&
1153 dai->driver->remove_order == order) {
1154 if (dai->driver->remove) {
1155 err = dai->driver->remove(dai);
1158 "ASoC: failed to remove %s: %d\n",
1165 static void soc_remove_link_dais(struct snd_soc_card *card,
1166 struct snd_soc_pcm_runtime *rtd, int order)
1170 /* unregister the rtd device */
1171 if (rtd->dev_registered) {
1172 device_unregister(rtd->dev);
1173 rtd->dev_registered = 0;
1176 /* remove the CODEC DAI */
1177 for (i = 0; i < rtd->num_codecs; i++)
1178 soc_remove_dai(rtd->codec_dais[i], order);
1180 soc_remove_dai(rtd->cpu_dai, order);
1183 static void soc_remove_link_components(struct snd_soc_card *card,
1184 struct snd_soc_pcm_runtime *rtd, int order)
1186 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1187 struct snd_soc_platform *platform = rtd->platform;
1188 struct snd_soc_component *component;
1191 /* remove the platform */
1192 if (platform && platform->component.driver->remove_order == order)
1193 soc_remove_component(&platform->component);
1195 /* remove the CODEC-side CODEC */
1196 for (i = 0; i < rtd->num_codecs; i++) {
1197 component = rtd->codec_dais[i]->component;
1198 if (component->driver->remove_order == order)
1199 soc_remove_component(component);
1202 /* remove any CPU-side CODEC */
1204 if (cpu_dai->component->driver->remove_order == order)
1205 soc_remove_component(cpu_dai->component);
1209 static void soc_remove_dai_links(struct snd_soc_card *card)
1212 struct snd_soc_pcm_runtime *rtd;
1213 struct snd_soc_dai_link *link, *_link;
1215 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1217 list_for_each_entry(rtd, &card->rtd_list, list)
1218 soc_remove_link_dais(card, rtd, order);
1221 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1223 list_for_each_entry(rtd, &card->rtd_list, list)
1224 soc_remove_link_components(card, rtd, order);
1227 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1228 if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK)
1229 dev_warn(card->dev, "Topology forgot to remove link %s?\n",
1232 list_del(&link->list);
1233 card->num_dai_links--;
1237 static int snd_soc_init_multicodec(struct snd_soc_card *card,
1238 struct snd_soc_dai_link *dai_link)
1240 /* Legacy codec/codec_dai link is a single entry in multicodec */
1241 if (dai_link->codec_name || dai_link->codec_of_node ||
1242 dai_link->codec_dai_name) {
1243 dai_link->num_codecs = 1;
1245 dai_link->codecs = devm_kzalloc(card->dev,
1246 sizeof(struct snd_soc_dai_link_component),
1248 if (!dai_link->codecs)
1251 dai_link->codecs[0].name = dai_link->codec_name;
1252 dai_link->codecs[0].of_node = dai_link->codec_of_node;
1253 dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
1256 if (!dai_link->codecs) {
1257 dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
1264 static int soc_init_dai_link(struct snd_soc_card *card,
1265 struct snd_soc_dai_link *link)
1269 ret = snd_soc_init_multicodec(card, link);
1271 dev_err(card->dev, "ASoC: failed to init multicodec\n");
1275 for (i = 0; i < link->num_codecs; i++) {
1277 * Codec must be specified by 1 of name or OF node,
1278 * not both or neither.
1280 if (!!link->codecs[i].name ==
1281 !!link->codecs[i].of_node) {
1282 dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
1286 /* Codec DAI name must be specified */
1287 if (!link->codecs[i].dai_name) {
1288 dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
1295 * Platform may be specified by either name or OF node, but
1296 * can be left unspecified, and a dummy platform will be used.
1298 if (link->platform_name && link->platform_of_node) {
1300 "ASoC: Both platform name/of_node are set for %s\n",
1306 * CPU device may be specified by either name or OF node, but
1307 * can be left unspecified, and will be matched based on DAI
1310 if (link->cpu_name && link->cpu_of_node) {
1312 "ASoC: Neither/both cpu name/of_node are set for %s\n",
1317 * At least one of CPU DAI name or CPU device name/node must be
1320 if (!link->cpu_dai_name &&
1321 !(link->cpu_name || link->cpu_of_node)) {
1323 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
1332 * snd_soc_add_dai_link - Add a DAI link dynamically
1333 * @card: The ASoC card to which the DAI link is added
1334 * @dai_link: The new DAI link to add
1336 * This function adds a DAI link to the ASoC card's link list.
1338 * Note: Topology can use this API to add DAI links when probing the
1339 * topology component. And machine drivers can still define static
1340 * DAI links in dai_link array.
1342 int snd_soc_add_dai_link(struct snd_soc_card *card,
1343 struct snd_soc_dai_link *dai_link)
1345 if (dai_link->dobj.type
1346 && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1347 dev_err(card->dev, "Invalid dai link type %d\n",
1348 dai_link->dobj.type);
1352 lockdep_assert_held(&client_mutex);
1353 /* Notify the machine driver for extra initialization
1354 * on the link created by topology.
1356 if (dai_link->dobj.type && card->add_dai_link)
1357 card->add_dai_link(card, dai_link);
1359 list_add_tail(&dai_link->list, &card->dai_link_list);
1360 card->num_dai_links++;
1364 EXPORT_SYMBOL_GPL(snd_soc_add_dai_link);
1367 * snd_soc_remove_dai_link - Remove a DAI link from the list
1368 * @card: The ASoC card that owns the link
1369 * @dai_link: The DAI link to remove
1371 * This function removes a DAI link from the ASoC card's link list.
1373 * For DAI links previously added by topology, topology should
1374 * remove them by using the dobj embedded in the link.
1376 void snd_soc_remove_dai_link(struct snd_soc_card *card,
1377 struct snd_soc_dai_link *dai_link)
1379 struct snd_soc_dai_link *link, *_link;
1381 if (dai_link->dobj.type
1382 && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1383 dev_err(card->dev, "Invalid dai link type %d\n",
1384 dai_link->dobj.type);
1388 lockdep_assert_held(&client_mutex);
1389 /* Notify the machine driver for extra destruction
1390 * on the link created by topology.
1392 if (dai_link->dobj.type && card->remove_dai_link)
1393 card->remove_dai_link(card, dai_link);
1395 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1396 if (link == dai_link) {
1397 list_del(&link->list);
1398 card->num_dai_links--;
1403 EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
1405 static void soc_set_name_prefix(struct snd_soc_card *card,
1406 struct snd_soc_component *component)
1410 if (card->codec_conf == NULL)
1413 for (i = 0; i < card->num_configs; i++) {
1414 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1415 if (map->of_node && component->dev->of_node != map->of_node)
1417 if (map->dev_name && strcmp(component->name, map->dev_name))
1419 component->name_prefix = map->name_prefix;
1424 static int soc_probe_component(struct snd_soc_card *card,
1425 struct snd_soc_component *component)
1427 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1428 struct snd_soc_dai *dai;
1431 if (!strcmp(component->name, "snd-soc-dummy"))
1434 if (component->card) {
1435 if (component->card != card) {
1436 dev_err(component->dev,
1437 "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1438 card->name, component->card->name);
1444 if (!try_module_get(component->dev->driver->owner))
1447 component->card = card;
1449 soc_set_name_prefix(card, component);
1451 soc_init_component_debugfs(component);
1453 if (component->dapm_widgets) {
1454 ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets,
1455 component->num_dapm_widgets);
1458 dev_err(component->dev,
1459 "Failed to create new controls %d\n", ret);
1464 list_for_each_entry(dai, &component->dai_list, list) {
1465 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1467 dev_err(component->dev,
1468 "Failed to create DAI widgets %d\n", ret);
1473 if (component->probe) {
1474 ret = component->probe(component);
1476 dev_err(component->dev,
1477 "ASoC: failed to probe component %d\n", ret);
1481 WARN(dapm->idle_bias_off &&
1482 dapm->bias_level != SND_SOC_BIAS_OFF,
1483 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1487 /* machine specific init */
1488 if (component->init) {
1489 ret = component->init(component);
1491 dev_err(component->dev,
1492 "Failed to do machine specific init %d\n", ret);
1497 if (component->controls)
1498 snd_soc_add_component_controls(component, component->controls,
1499 component->num_controls);
1500 if (component->dapm_routes)
1501 snd_soc_dapm_add_routes(dapm, component->dapm_routes,
1502 component->num_dapm_routes);
1504 list_add(&dapm->list, &card->dapm_list);
1505 list_add(&component->card_list, &card->component_dev_list);
1510 soc_cleanup_component_debugfs(component);
1511 component->card = NULL;
1512 module_put(component->dev->driver->owner);
1517 static void rtd_release(struct device *dev)
1522 static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1527 /* register the rtd device */
1528 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1531 device_initialize(rtd->dev);
1532 rtd->dev->parent = rtd->card->dev;
1533 rtd->dev->release = rtd_release;
1534 rtd->dev->groups = soc_dev_attr_groups;
1535 dev_set_name(rtd->dev, "%s", name);
1536 dev_set_drvdata(rtd->dev, rtd);
1537 mutex_init(&rtd->pcm_mutex);
1538 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1539 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1540 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1541 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1542 ret = device_add(rtd->dev);
1544 /* calling put_device() here to free the rtd->dev */
1545 put_device(rtd->dev);
1546 dev_err(rtd->card->dev,
1547 "ASoC: failed to register runtime device: %d\n", ret);
1550 rtd->dev_registered = 1;
1554 static int soc_probe_link_components(struct snd_soc_card *card,
1555 struct snd_soc_pcm_runtime *rtd,
1558 struct snd_soc_platform *platform = rtd->platform;
1559 struct snd_soc_component *component;
1562 /* probe the CPU-side component, if it is a CODEC */
1563 component = rtd->cpu_dai->component;
1564 if (component->driver->probe_order == order) {
1565 ret = soc_probe_component(card, component);
1570 /* probe the CODEC-side components */
1571 for (i = 0; i < rtd->num_codecs; i++) {
1572 component = rtd->codec_dais[i]->component;
1573 if (component->driver->probe_order == order) {
1574 ret = soc_probe_component(card, component);
1580 /* probe the platform */
1581 if (platform->component.driver->probe_order == order) {
1582 ret = soc_probe_component(card, &platform->component);
1590 static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1594 if (!dai->probed && dai->driver->probe_order == order) {
1595 if (dai->driver->probe) {
1596 ret = dai->driver->probe(dai);
1599 "ASoC: failed to probe DAI %s: %d\n",
1611 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
1612 struct snd_soc_pcm_runtime *rtd)
1616 for (i = 0; i < num_dais; ++i) {
1617 struct snd_soc_dai_driver *drv = dais[i]->driver;
1619 if (!rtd->dai_link->no_pcm && drv->pcm_new)
1620 ret = drv->pcm_new(rtd, dais[i]);
1622 dev_err(dais[i]->dev,
1623 "ASoC: Failed to bind %s with pcm device\n",
1632 static int soc_link_dai_widgets(struct snd_soc_card *card,
1633 struct snd_soc_dai_link *dai_link,
1634 struct snd_soc_pcm_runtime *rtd)
1636 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1637 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1638 struct snd_soc_dapm_widget *sink, *source;
1641 if (rtd->num_codecs > 1)
1642 dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
1644 /* link the DAI widgets */
1645 sink = codec_dai->playback_widget;
1646 source = cpu_dai->capture_widget;
1647 if (sink && source) {
1648 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1649 dai_link->num_params,
1652 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1653 sink->name, source->name, ret);
1658 sink = cpu_dai->playback_widget;
1659 source = codec_dai->capture_widget;
1660 if (sink && source) {
1661 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1662 dai_link->num_params,
1665 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1666 sink->name, source->name, ret);
1674 static int soc_probe_link_dais(struct snd_soc_card *card,
1675 struct snd_soc_pcm_runtime *rtd, int order)
1677 struct snd_soc_dai_link *dai_link = rtd->dai_link;
1678 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1681 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1682 card->name, rtd->num, order);
1684 /* set default power off timeout */
1685 rtd->pmdown_time = pmdown_time;
1687 ret = soc_probe_dai(cpu_dai, order);
1691 /* probe the CODEC DAI */
1692 for (i = 0; i < rtd->num_codecs; i++) {
1693 ret = soc_probe_dai(rtd->codec_dais[i], order);
1698 /* complete DAI probe during last probe */
1699 if (order != SND_SOC_COMP_ORDER_LAST)
1702 /* do machine specific initialization */
1703 if (dai_link->init) {
1704 ret = dai_link->init(rtd);
1706 dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1707 dai_link->name, ret);
1712 if (dai_link->dai_fmt)
1713 snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1715 ret = soc_post_component_init(rtd, dai_link->name);
1719 #ifdef CONFIG_DEBUG_FS
1720 /* add DPCM sysfs entries */
1721 if (dai_link->dynamic)
1722 soc_dpcm_debugfs_add(rtd);
1725 if (cpu_dai->driver->compress_new) {
1726 /*create compress_device"*/
1727 ret = cpu_dai->driver->compress_new(rtd, rtd->num);
1729 dev_err(card->dev, "ASoC: can't create compress %s\n",
1730 dai_link->stream_name);
1735 if (!dai_link->params) {
1736 /* create the pcm */
1737 ret = soc_new_pcm(rtd, rtd->num);
1739 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1740 dai_link->stream_name, ret);
1743 ret = soc_link_dai_pcm_new(&cpu_dai, 1, rtd);
1746 ret = soc_link_dai_pcm_new(rtd->codec_dais,
1747 rtd->num_codecs, rtd);
1751 INIT_DELAYED_WORK(&rtd->delayed_work,
1752 codec2codec_close_delayed_work);
1754 /* link the DAI widgets */
1755 ret = soc_link_dai_widgets(card, dai_link, rtd);
1764 static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1766 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1767 struct snd_soc_component *component;
1769 struct device_node *codec_of_node;
1771 if (aux_dev->codec_of_node || aux_dev->codec_name) {
1772 /* codecs, usually analog devices */
1773 name = aux_dev->codec_name;
1774 codec_of_node = aux_dev->codec_of_node;
1775 component = soc_find_component(codec_of_node, name);
1778 name = of_node_full_name(codec_of_node);
1781 } else if (aux_dev->name) {
1782 /* generic components */
1783 name = aux_dev->name;
1784 component = soc_find_component(NULL, name);
1788 dev_err(card->dev, "ASoC: Invalid auxiliary device\n");
1792 component->init = aux_dev->init;
1793 list_add(&component->card_aux_list, &card->aux_comp_list);
1798 dev_err(card->dev, "ASoC: %s not registered\n", name);
1799 return -EPROBE_DEFER;
1802 static int soc_probe_aux_devices(struct snd_soc_card *card)
1804 struct snd_soc_component *comp;
1808 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1810 list_for_each_entry(comp, &card->aux_comp_list, card_aux_list) {
1811 if (comp->driver->probe_order == order) {
1812 ret = soc_probe_component(card, comp);
1815 "ASoC: failed to probe aux component %s %d\n",
1826 static void soc_remove_aux_devices(struct snd_soc_card *card)
1828 struct snd_soc_component *comp, *_comp;
1831 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1833 list_for_each_entry_safe(comp, _comp,
1834 &card->aux_comp_list, card_aux_list) {
1836 if (comp->driver->remove_order == order) {
1837 soc_remove_component(comp);
1838 /* remove it from the card's aux_comp_list */
1839 list_del(&comp->card_aux_list);
1845 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
1849 if (codec->cache_init)
1852 ret = snd_soc_cache_init(codec);
1855 "ASoC: Failed to set cache compression type: %d\n",
1859 codec->cache_init = 1;
1864 * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1865 * @rtd: The runtime for which the DAI link format should be changed
1866 * @dai_fmt: The new DAI link format
1868 * This function updates the DAI link format for all DAIs connected to the DAI
1869 * link for the specified runtime.
1871 * Note: For setups with a static format set the dai_fmt field in the
1872 * corresponding snd_dai_link struct instead of using this function.
1874 * Returns 0 on success, otherwise a negative error code.
1876 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1877 unsigned int dai_fmt)
1879 struct snd_soc_dai **codec_dais = rtd->codec_dais;
1880 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1884 for (i = 0; i < rtd->num_codecs; i++) {
1885 struct snd_soc_dai *codec_dai = codec_dais[i];
1887 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1888 if (ret != 0 && ret != -ENOTSUPP) {
1889 dev_warn(codec_dai->dev,
1890 "ASoC: Failed to set DAI format: %d\n", ret);
1895 /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
1896 if (cpu_dai->codec) {
1897 unsigned int inv_dai_fmt;
1899 inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1900 switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1901 case SND_SOC_DAIFMT_CBM_CFM:
1902 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1904 case SND_SOC_DAIFMT_CBM_CFS:
1905 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1907 case SND_SOC_DAIFMT_CBS_CFM:
1908 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1910 case SND_SOC_DAIFMT_CBS_CFS:
1911 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1915 dai_fmt = inv_dai_fmt;
1918 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1919 if (ret != 0 && ret != -ENOTSUPP) {
1920 dev_warn(cpu_dai->dev,
1921 "ASoC: Failed to set DAI format: %d\n", ret);
1927 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1931 /* Trim special characters, and replace '-' with '_' since '-' is used to
1932 * separate different DMI fields in the card long name. Only number and
1933 * alphabet characters and a few separator characters are kept.
1935 static void cleanup_dmi_name(char *name)
1939 for (i = 0; name[i]; i++) {
1940 if (isalnum(name[i]) || (name[i] == '.')
1941 || (name[i] == '_'))
1942 name[j++] = name[i];
1943 else if (name[i] == '-')
1950 /* Check if a DMI field is valid, i.e. not containing any string
1951 * in the black list.
1953 static int is_dmi_valid(const char *field)
1957 while (dmi_blacklist[i]) {
1958 if (strstr(field, dmi_blacklist[i]))
1967 * snd_soc_set_dmi_name() - Register DMI names to card
1968 * @card: The card to register DMI names
1969 * @flavour: The flavour "differentiator" for the card amongst its peers.
1971 * An Intel machine driver may be used by many different devices but are
1972 * difficult for userspace to differentiate, since machine drivers ususally
1973 * use their own name as the card short name and leave the card long name
1974 * blank. To differentiate such devices and fix bugs due to lack of
1975 * device-specific configurations, this function allows DMI info to be used
1976 * as the sound card long name, in the format of
1977 * "vendor-product-version-board"
1978 * (Character '-' is used to separate different DMI fields here).
1979 * This will help the user space to load the device-specific Use Case Manager
1980 * (UCM) configurations for the card.
1982 * Possible card long names may be:
1983 * DellInc.-XPS139343-01-0310JH
1984 * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
1985 * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
1987 * This function also supports flavoring the card longname to provide
1988 * the extra differentiation, like "vendor-product-version-board-flavor".
1990 * We only keep number and alphabet characters and a few separator characters
1991 * in the card long name since UCM in the user space uses the card long names
1992 * as card configuration directory names and AudoConf cannot support special
1993 * charactors like SPACE.
1995 * Returns 0 on success, otherwise a negative error code.
1997 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
1999 const char *vendor, *product, *product_version, *board;
2000 size_t longname_buf_size = sizeof(card->snd_card->longname);
2003 if (card->long_name)
2004 return 0; /* long name already set by driver or from DMI */
2006 /* make up dmi long name as: vendor.product.version.board */
2007 vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2008 if (!vendor || !is_dmi_valid(vendor)) {
2009 dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
2014 snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
2016 cleanup_dmi_name(card->dmi_longname);
2018 product = dmi_get_system_info(DMI_PRODUCT_NAME);
2019 if (product && is_dmi_valid(product)) {
2020 len = strlen(card->dmi_longname);
2021 snprintf(card->dmi_longname + len,
2022 longname_buf_size - len,
2025 len++; /* skip the separator "-" */
2026 if (len < longname_buf_size)
2027 cleanup_dmi_name(card->dmi_longname + len);
2029 /* some vendors like Lenovo may only put a self-explanatory
2030 * name in the product version field
2032 product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
2033 if (product_version && is_dmi_valid(product_version)) {
2034 len = strlen(card->dmi_longname);
2035 snprintf(card->dmi_longname + len,
2036 longname_buf_size - len,
2037 "-%s", product_version);
2040 if (len < longname_buf_size)
2041 cleanup_dmi_name(card->dmi_longname + len);
2045 board = dmi_get_system_info(DMI_BOARD_NAME);
2046 if (board && is_dmi_valid(board)) {
2047 len = strlen(card->dmi_longname);
2048 snprintf(card->dmi_longname + len,
2049 longname_buf_size - len,
2053 if (len < longname_buf_size)
2054 cleanup_dmi_name(card->dmi_longname + len);
2055 } else if (!product) {
2056 /* fall back to using legacy name */
2057 dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
2061 /* Add flavour to dmi long name */
2063 len = strlen(card->dmi_longname);
2064 snprintf(card->dmi_longname + len,
2065 longname_buf_size - len,
2069 if (len < longname_buf_size)
2070 cleanup_dmi_name(card->dmi_longname + len);
2073 /* set the card long name */
2074 card->long_name = card->dmi_longname;
2078 EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
2079 #endif /* CONFIG_DMI */
2081 static int snd_soc_instantiate_card(struct snd_soc_card *card)
2083 struct snd_soc_codec *codec;
2084 struct snd_soc_pcm_runtime *rtd;
2085 struct snd_soc_dai_link *dai_link;
2088 mutex_lock(&client_mutex);
2089 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
2092 for (i = 0; i < card->num_links; i++) {
2093 ret = soc_bind_dai_link(card, &card->dai_link[i]);
2098 /* bind aux_devs too */
2099 for (i = 0; i < card->num_aux_devs; i++) {
2100 ret = soc_bind_aux_dev(card, i);
2105 /* add predefined DAI links to the list */
2106 for (i = 0; i < card->num_links; i++)
2107 snd_soc_add_dai_link(card, card->dai_link+i);
2109 /* initialize the register cache for each available codec */
2110 list_for_each_entry(codec, &codec_list, list) {
2111 if (codec->cache_init)
2113 ret = snd_soc_init_codec_cache(codec);
2118 /* card bind complete so register a sound card */
2119 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
2120 card->owner, 0, &card->snd_card);
2123 "ASoC: can't create sound card for card %s: %d\n",
2128 soc_init_card_debugfs(card);
2130 card->dapm.bias_level = SND_SOC_BIAS_OFF;
2131 card->dapm.dev = card->dev;
2132 card->dapm.card = card;
2133 list_add(&card->dapm.list, &card->dapm_list);
2135 #ifdef CONFIG_DEBUG_FS
2136 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
2139 #ifdef CONFIG_PM_SLEEP
2140 /* deferred resume work */
2141 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
2144 if (card->dapm_widgets)
2145 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
2146 card->num_dapm_widgets);
2148 if (card->of_dapm_widgets)
2149 snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
2150 card->num_of_dapm_widgets);
2152 /* initialise the sound card only once */
2154 ret = card->probe(card);
2156 goto card_probe_error;
2159 /* probe all components used by DAI links on this card */
2160 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2162 list_for_each_entry(rtd, &card->rtd_list, list) {
2163 ret = soc_probe_link_components(card, rtd, order);
2166 "ASoC: failed to instantiate card %d\n",
2173 /* probe auxiliary components */
2174 ret = soc_probe_aux_devices(card);
2178 /* Find new DAI links added during probing components and bind them.
2179 * Components with topology may bring new DAIs and DAI links.
2181 list_for_each_entry(dai_link, &card->dai_link_list, list) {
2182 if (soc_is_dai_link_bound(card, dai_link))
2185 ret = soc_init_dai_link(card, dai_link);
2188 ret = soc_bind_dai_link(card, dai_link);
2193 /* probe all DAI links on this card */
2194 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2196 list_for_each_entry(rtd, &card->rtd_list, list) {
2197 ret = soc_probe_link_dais(card, rtd, order);
2200 "ASoC: failed to instantiate card %d\n",
2207 snd_soc_dapm_link_dai_widgets(card);
2208 snd_soc_dapm_connect_dai_link_widgets(card);
2211 snd_soc_add_card_controls(card, card->controls, card->num_controls);
2213 if (card->dapm_routes)
2214 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
2215 card->num_dapm_routes);
2217 if (card->of_dapm_routes)
2218 snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
2219 card->num_of_dapm_routes);
2221 /* try to set some sane longname if DMI is available */
2222 snd_soc_set_dmi_name(card, NULL);
2224 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
2226 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
2227 "%s", card->long_name ? card->long_name : card->name);
2228 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
2229 "%s", card->driver_name ? card->driver_name : card->name);
2230 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
2231 switch (card->snd_card->driver[i]) {
2237 if (!isalnum(card->snd_card->driver[i]))
2238 card->snd_card->driver[i] = '_';
2243 if (card->late_probe) {
2244 ret = card->late_probe(card);
2246 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
2248 goto probe_aux_dev_err;
2252 snd_soc_dapm_new_widgets(card);
2254 ret = snd_card_register(card->snd_card);
2256 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
2258 goto probe_aux_dev_err;
2261 card->instantiated = 1;
2262 snd_soc_dapm_sync(&card->dapm);
2263 mutex_unlock(&card->mutex);
2264 mutex_unlock(&client_mutex);
2269 soc_remove_aux_devices(card);
2272 soc_remove_dai_links(card);
2278 snd_soc_dapm_free(&card->dapm);
2279 soc_cleanup_card_debugfs(card);
2280 snd_card_free(card->snd_card);
2283 soc_remove_pcm_runtimes(card);
2284 mutex_unlock(&card->mutex);
2285 mutex_unlock(&client_mutex);
2290 /* probes a new socdev */
2291 static int soc_probe(struct platform_device *pdev)
2293 struct snd_soc_card *card = platform_get_drvdata(pdev);
2296 * no card, so machine driver should be registering card
2297 * we should not be here in that case so ret error
2302 dev_warn(&pdev->dev,
2303 "ASoC: machine %s should use snd_soc_register_card()\n",
2306 /* Bodge while we unpick instantiation */
2307 card->dev = &pdev->dev;
2309 return snd_soc_register_card(card);
2312 static int soc_cleanup_card_resources(struct snd_soc_card *card)
2314 struct snd_soc_pcm_runtime *rtd;
2316 /* make sure any delayed work runs */
2317 list_for_each_entry(rtd, &card->rtd_list, list)
2318 flush_delayed_work(&rtd->delayed_work);
2320 /* free the ALSA card at first; this syncs with pending operations */
2321 snd_card_free(card->snd_card);
2323 /* remove and free each DAI */
2324 soc_remove_dai_links(card);
2325 soc_remove_pcm_runtimes(card);
2327 /* remove auxiliary devices */
2328 soc_remove_aux_devices(card);
2330 snd_soc_dapm_free(&card->dapm);
2331 soc_cleanup_card_debugfs(card);
2333 /* remove the card */
2340 /* removes a socdev */
2341 static int soc_remove(struct platform_device *pdev)
2343 struct snd_soc_card *card = platform_get_drvdata(pdev);
2345 snd_soc_unregister_card(card);
2349 int snd_soc_poweroff(struct device *dev)
2351 struct snd_soc_card *card = dev_get_drvdata(dev);
2352 struct snd_soc_pcm_runtime *rtd;
2354 if (!card->instantiated)
2357 /* Flush out pmdown_time work - we actually do want to run it
2358 * now, we're shutting down so no imminent restart. */
2359 list_for_each_entry(rtd, &card->rtd_list, list)
2360 flush_delayed_work(&rtd->delayed_work);
2362 snd_soc_dapm_shutdown(card);
2364 /* deactivate pins to sleep state */
2365 list_for_each_entry(rtd, &card->rtd_list, list) {
2366 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2369 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2370 for (i = 0; i < rtd->num_codecs; i++) {
2371 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
2372 pinctrl_pm_select_sleep_state(codec_dai->dev);
2378 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
2380 const struct dev_pm_ops snd_soc_pm_ops = {
2381 .suspend = snd_soc_suspend,
2382 .resume = snd_soc_resume,
2383 .freeze = snd_soc_suspend,
2384 .thaw = snd_soc_resume,
2385 .poweroff = snd_soc_poweroff,
2386 .restore = snd_soc_resume,
2388 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
2390 /* ASoC platform driver */
2391 static struct platform_driver soc_driver = {
2393 .name = "soc-audio",
2394 .pm = &snd_soc_pm_ops,
2397 .remove = soc_remove,
2401 * snd_soc_cnew - create new control
2402 * @_template: control template
2403 * @data: control private data
2404 * @long_name: control long name
2405 * @prefix: control name prefix
2407 * Create a new mixer control from a template control.
2409 * Returns 0 for success, else error.
2411 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2412 void *data, const char *long_name,
2415 struct snd_kcontrol_new template;
2416 struct snd_kcontrol *kcontrol;
2419 memcpy(&template, _template, sizeof(template));
2423 long_name = template.name;
2426 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2430 template.name = name;
2432 template.name = long_name;
2435 kcontrol = snd_ctl_new1(&template, data);
2441 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2443 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2444 const struct snd_kcontrol_new *controls, int num_controls,
2445 const char *prefix, void *data)
2449 for (i = 0; i < num_controls; i++) {
2450 const struct snd_kcontrol_new *control = &controls[i];
2451 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2452 control->name, prefix));
2454 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2455 control->name, err);
2463 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2466 struct snd_card *card = soc_card->snd_card;
2467 struct snd_kcontrol *kctl;
2469 if (unlikely(!name))
2472 list_for_each_entry(kctl, &card->controls, list)
2473 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2477 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2480 * snd_soc_add_component_controls - Add an array of controls to a component.
2482 * @component: Component to add controls to
2483 * @controls: Array of controls to add
2484 * @num_controls: Number of elements in the array
2486 * Return: 0 for success, else error.
2488 int snd_soc_add_component_controls(struct snd_soc_component *component,
2489 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2491 struct snd_card *card = component->card->snd_card;
2493 return snd_soc_add_controls(card, component->dev, controls,
2494 num_controls, component->name_prefix, component);
2496 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
2499 * snd_soc_add_codec_controls - add an array of controls to a codec.
2500 * Convenience function to add a list of controls. Many codecs were
2501 * duplicating this code.
2503 * @codec: codec to add controls to
2504 * @controls: array of controls to add
2505 * @num_controls: number of elements in the array
2507 * Return 0 for success, else error.
2509 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2510 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2512 return snd_soc_add_component_controls(&codec->component, controls,
2515 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2518 * snd_soc_add_platform_controls - add an array of controls to a platform.
2519 * Convenience function to add a list of controls.
2521 * @platform: platform to add controls to
2522 * @controls: array of controls to add
2523 * @num_controls: number of elements in the array
2525 * Return 0 for success, else error.
2527 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2528 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2530 return snd_soc_add_component_controls(&platform->component, controls,
2533 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2536 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2537 * Convenience function to add a list of controls.
2539 * @soc_card: SoC card to add controls to
2540 * @controls: array of controls to add
2541 * @num_controls: number of elements in the array
2543 * Return 0 for success, else error.
2545 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2546 const struct snd_kcontrol_new *controls, int num_controls)
2548 struct snd_card *card = soc_card->snd_card;
2550 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2553 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2556 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2557 * Convienience function to add a list of controls.
2559 * @dai: DAI to add controls to
2560 * @controls: array of controls to add
2561 * @num_controls: number of elements in the array
2563 * Return 0 for success, else error.
2565 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2566 const struct snd_kcontrol_new *controls, int num_controls)
2568 struct snd_card *card = dai->component->card->snd_card;
2570 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2573 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2576 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2578 * @clk_id: DAI specific clock ID
2579 * @freq: new clock frequency in Hz
2580 * @dir: new clock direction - input/output.
2582 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2584 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2585 unsigned int freq, int dir)
2587 if (dai->driver && dai->driver->ops->set_sysclk)
2588 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2589 else if (dai->codec && dai->codec->driver->set_sysclk)
2590 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2595 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2598 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2600 * @clk_id: DAI specific clock ID
2601 * @source: Source for the clock
2602 * @freq: new clock frequency in Hz
2603 * @dir: new clock direction - input/output.
2605 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2607 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2608 int source, unsigned int freq, int dir)
2610 if (codec->driver->set_sysclk)
2611 return codec->driver->set_sysclk(codec, clk_id, source,
2616 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2619 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2621 * @div_id: DAI specific clock divider ID
2622 * @div: new clock divisor.
2624 * Configures the clock dividers. This is used to derive the best DAI bit and
2625 * frame clocks from the system or master clock. It's best to set the DAI bit
2626 * and frame clocks as low as possible to save system power.
2628 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2629 int div_id, int div)
2631 if (dai->driver && dai->driver->ops->set_clkdiv)
2632 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2636 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2639 * snd_soc_dai_set_pll - configure DAI PLL.
2641 * @pll_id: DAI specific PLL ID
2642 * @source: DAI specific source for the PLL
2643 * @freq_in: PLL input clock frequency in Hz
2644 * @freq_out: requested PLL output clock frequency in Hz
2646 * Configures and enables PLL to generate output clock based on input clock.
2648 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2649 unsigned int freq_in, unsigned int freq_out)
2651 if (dai->driver && dai->driver->ops->set_pll)
2652 return dai->driver->ops->set_pll(dai, pll_id, source,
2654 else if (dai->codec && dai->codec->driver->set_pll)
2655 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2660 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2663 * snd_soc_codec_set_pll - configure codec PLL.
2665 * @pll_id: DAI specific PLL ID
2666 * @source: DAI specific source for the PLL
2667 * @freq_in: PLL input clock frequency in Hz
2668 * @freq_out: requested PLL output clock frequency in Hz
2670 * Configures and enables PLL to generate output clock based on input clock.
2672 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2673 unsigned int freq_in, unsigned int freq_out)
2675 if (codec->driver->set_pll)
2676 return codec->driver->set_pll(codec, pll_id, source,
2681 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2684 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
2686 * @ratio: Ratio of BCLK to Sample rate.
2688 * Configures the DAI for a preset BCLK to sample rate ratio.
2690 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2692 if (dai->driver && dai->driver->ops->set_bclk_ratio)
2693 return dai->driver->ops->set_bclk_ratio(dai, ratio);
2697 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
2700 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2702 * @fmt: SND_SOC_DAIFMT_ format value.
2704 * Configures the DAI hardware format and clocking.
2706 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2708 if (dai->driver == NULL)
2710 if (dai->driver->ops->set_fmt == NULL)
2712 return dai->driver->ops->set_fmt(dai, fmt);
2714 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2717 * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
2718 * @slots: Number of slots in use.
2719 * @tx_mask: bitmask representing active TX slots.
2720 * @rx_mask: bitmask representing active RX slots.
2722 * Generates the TDM tx and rx slot default masks for DAI.
2724 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2725 unsigned int *tx_mask,
2726 unsigned int *rx_mask)
2728 if (*tx_mask || *rx_mask)
2734 *tx_mask = (1 << slots) - 1;
2735 *rx_mask = (1 << slots) - 1;
2741 * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
2742 * @dai: The DAI to configure
2743 * @tx_mask: bitmask representing active TX slots.
2744 * @rx_mask: bitmask representing active RX slots.
2745 * @slots: Number of slots in use.
2746 * @slot_width: Width in bits for each slot.
2748 * This function configures the specified DAI for TDM operation. @slot contains
2749 * the total number of slots of the TDM stream and @slot_with the width of each
2750 * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
2751 * active slots of the TDM stream for the specified DAI, i.e. which slots the
2752 * DAI should write to or read from. If a bit is set the corresponding slot is
2753 * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
2754 * the first slot, bit 1 to the second slot and so on. The first active slot
2755 * maps to the first channel of the DAI, the second active slot to the second
2756 * channel and so on.
2758 * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
2759 * @rx_mask and @slot_width will be ignored.
2761 * Returns 0 on success, a negative error code otherwise.
2763 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2764 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2766 if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask)
2767 dai->driver->ops->xlate_tdm_slot_mask(slots,
2768 &tx_mask, &rx_mask);
2770 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
2772 dai->tx_mask = tx_mask;
2773 dai->rx_mask = rx_mask;
2775 if (dai->driver && dai->driver->ops->set_tdm_slot)
2776 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2781 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2784 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2786 * @tx_num: how many TX channels
2787 * @tx_slot: pointer to an array which imply the TX slot number channel
2789 * @rx_num: how many RX channels
2790 * @rx_slot: pointer to an array which imply the RX slot number channel
2793 * configure the relationship between channel number and TDM slot number.
2795 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2796 unsigned int tx_num, unsigned int *tx_slot,
2797 unsigned int rx_num, unsigned int *rx_slot)
2799 if (dai->driver && dai->driver->ops->set_channel_map)
2800 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2805 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2808 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2810 * @tristate: tristate enable
2812 * Tristates the DAI so that others can use it.
2814 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2816 if (dai->driver && dai->driver->ops->set_tristate)
2817 return dai->driver->ops->set_tristate(dai, tristate);
2821 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2824 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2826 * @mute: mute enable
2827 * @direction: stream to mute
2829 * Mutes the DAI DAC.
2831 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
2837 if (dai->driver->ops->mute_stream)
2838 return dai->driver->ops->mute_stream(dai, mute, direction);
2839 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
2840 dai->driver->ops->digital_mute)
2841 return dai->driver->ops->digital_mute(dai, mute);
2845 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2848 * snd_soc_register_card - Register a card with the ASoC core
2850 * @card: Card to register
2853 int snd_soc_register_card(struct snd_soc_card *card)
2856 struct snd_soc_pcm_runtime *rtd;
2858 if (!card->name || !card->dev)
2861 for (i = 0; i < card->num_links; i++) {
2862 struct snd_soc_dai_link *link = &card->dai_link[i];
2864 ret = soc_init_dai_link(card, link);
2866 dev_err(card->dev, "ASoC: failed to init link %s\n",
2872 dev_set_drvdata(card->dev, card);
2874 snd_soc_initialize_card_lists(card);
2876 INIT_LIST_HEAD(&card->dai_link_list);
2877 card->num_dai_links = 0;
2879 INIT_LIST_HEAD(&card->rtd_list);
2882 INIT_LIST_HEAD(&card->dapm_dirty);
2883 INIT_LIST_HEAD(&card->dobj_list);
2884 card->instantiated = 0;
2885 mutex_init(&card->mutex);
2886 mutex_init(&card->dapm_mutex);
2888 ret = snd_soc_instantiate_card(card);
2892 /* deactivate pins to sleep state */
2893 list_for_each_entry(rtd, &card->rtd_list, list) {
2894 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2897 for (j = 0; j < rtd->num_codecs; j++) {
2898 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
2899 if (!codec_dai->active)
2900 pinctrl_pm_select_sleep_state(codec_dai->dev);
2903 if (!cpu_dai->active)
2904 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2909 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2912 * snd_soc_unregister_card - Unregister a card with the ASoC core
2914 * @card: Card to unregister
2917 int snd_soc_unregister_card(struct snd_soc_card *card)
2919 if (card->instantiated) {
2920 card->instantiated = false;
2921 snd_soc_dapm_shutdown(card);
2922 soc_cleanup_card_resources(card);
2923 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2928 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2931 * Simplify DAI link configuration by removing ".-1" from device names
2932 * and sanitizing names.
2934 static char *fmt_single_name(struct device *dev, int *id)
2936 char *found, name[NAME_SIZE];
2939 if (dev_name(dev) == NULL)
2942 strlcpy(name, dev_name(dev), NAME_SIZE);
2944 /* are we a "%s.%d" name (platform and SPI components) */
2945 found = strstr(name, dev->driver->name);
2948 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2950 /* discard ID from name if ID == -1 */
2952 found[strlen(dev->driver->name)] = '\0';
2956 /* I2C component devices are named "bus-addr" */
2957 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2958 char tmp[NAME_SIZE];
2960 /* create unique ID number from I2C addr and bus */
2961 *id = ((id1 & 0xffff) << 16) + id2;
2963 /* sanitize component name for DAI link creation */
2964 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2965 strlcpy(name, tmp, NAME_SIZE);
2970 return kstrdup(name, GFP_KERNEL);
2974 * Simplify DAI link naming for single devices with multiple DAIs by removing
2975 * any ".-1" and using the DAI name (instead of device name).
2977 static inline char *fmt_multiple_name(struct device *dev,
2978 struct snd_soc_dai_driver *dai_drv)
2980 if (dai_drv->name == NULL) {
2982 "ASoC: error - multiple DAI %s registered with no name\n",
2987 return kstrdup(dai_drv->name, GFP_KERNEL);
2991 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
2993 * @component: The component for which the DAIs should be unregistered
2995 static void snd_soc_unregister_dais(struct snd_soc_component *component)
2997 struct snd_soc_dai *dai, *_dai;
2999 list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
3000 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
3002 list_del(&dai->list);
3008 /* Create a DAI and add it to the component's DAI list */
3009 static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
3010 struct snd_soc_dai_driver *dai_drv,
3011 bool legacy_dai_naming)
3013 struct device *dev = component->dev;
3014 struct snd_soc_dai *dai;
3016 dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
3018 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3023 * Back in the old days when we still had component-less DAIs,
3024 * instead of having a static name, component-less DAIs would
3025 * inherit the name of the parent device so it is possible to
3026 * register multiple instances of the DAI. We still need to keep
3027 * the same naming style even though those DAIs are not
3028 * component-less anymore.
3030 if (legacy_dai_naming &&
3031 (dai_drv->id == 0 || dai_drv->name == NULL)) {
3032 dai->name = fmt_single_name(dev, &dai->id);
3034 dai->name = fmt_multiple_name(dev, dai_drv);
3036 dai->id = dai_drv->id;
3038 dai->id = component->num_dai;
3040 if (dai->name == NULL) {
3045 dai->component = component;
3047 dai->driver = dai_drv;
3048 if (!dai->driver->ops)
3049 dai->driver->ops = &null_dai_ops;
3051 list_add(&dai->list, &component->dai_list);
3052 component->num_dai++;
3054 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
3059 * snd_soc_register_dais - Register a DAI with the ASoC core
3061 * @component: The component the DAIs are registered for
3062 * @dai_drv: DAI driver to use for the DAIs
3063 * @count: Number of DAIs
3064 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3067 static int snd_soc_register_dais(struct snd_soc_component *component,
3068 struct snd_soc_dai_driver *dai_drv, size_t count,
3069 bool legacy_dai_naming)
3071 struct device *dev = component->dev;
3072 struct snd_soc_dai *dai;
3076 dev_dbg(dev, "ASoC: dai register %s #%zu\n", dev_name(dev), count);
3078 component->dai_drv = dai_drv;
3080 for (i = 0; i < count; i++) {
3082 dai = soc_add_dai(component, dai_drv + i,
3083 count == 1 && legacy_dai_naming);
3093 snd_soc_unregister_dais(component);
3099 * snd_soc_register_dai - Register a DAI dynamically & create its widgets
3101 * @component: The component the DAIs are registered for
3102 * @dai_drv: DAI driver to use for the DAI
3104 * Topology can use this API to register DAIs when probing a component.
3105 * These DAIs's widgets will be freed in the card cleanup and the DAIs
3106 * will be freed in the component cleanup.
3108 int snd_soc_register_dai(struct snd_soc_component *component,
3109 struct snd_soc_dai_driver *dai_drv)
3111 struct snd_soc_dapm_context *dapm =
3112 snd_soc_component_get_dapm(component);
3113 struct snd_soc_dai *dai;
3116 if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
3117 dev_err(component->dev, "Invalid dai type %d\n",
3118 dai_drv->dobj.type);
3122 lockdep_assert_held(&client_mutex);
3123 dai = soc_add_dai(component, dai_drv, false);
3127 /* Create the DAI widgets here. After adding DAIs, topology may
3128 * also add routes that need these widgets as source or sink.
3130 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
3132 dev_err(component->dev,
3133 "Failed to create DAI widgets %d\n", ret);
3138 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3140 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
3141 enum snd_soc_dapm_type type, int subseq)
3143 struct snd_soc_component *component = dapm->component;
3145 component->driver->seq_notifier(component, type, subseq);
3148 static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
3151 struct snd_soc_component *component = dapm->component;
3153 return component->driver->stream_event(component, event);
3156 static int snd_soc_component_initialize(struct snd_soc_component *component,
3157 const struct snd_soc_component_driver *driver, struct device *dev)
3159 struct snd_soc_dapm_context *dapm;
3161 component->name = fmt_single_name(dev, &component->id);
3162 if (!component->name) {
3163 dev_err(dev, "ASoC: Failed to allocate name\n");
3167 component->dev = dev;
3168 component->driver = driver;
3169 component->probe = component->driver->probe;
3170 component->remove = component->driver->remove;
3171 component->suspend = component->driver->suspend;
3172 component->resume = component->driver->resume;
3173 component->pcm_new = component->driver->pcm_new;
3174 component->pcm_free = component->driver->pcm_free;
3176 dapm = &component->dapm;
3178 dapm->component = component;
3179 dapm->bias_level = SND_SOC_BIAS_OFF;
3180 dapm->idle_bias_off = true;
3181 if (driver->seq_notifier)
3182 dapm->seq_notifier = snd_soc_component_seq_notifier;
3183 if (driver->stream_event)
3184 dapm->stream_event = snd_soc_component_stream_event;
3186 component->controls = driver->controls;
3187 component->num_controls = driver->num_controls;
3188 component->dapm_widgets = driver->dapm_widgets;
3189 component->num_dapm_widgets = driver->num_dapm_widgets;
3190 component->dapm_routes = driver->dapm_routes;
3191 component->num_dapm_routes = driver->num_dapm_routes;
3193 INIT_LIST_HEAD(&component->dai_list);
3194 mutex_init(&component->io_mutex);
3199 static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
3201 int val_bytes = regmap_get_val_bytes(component->regmap);
3203 /* Errors are legitimate for non-integer byte multiples */
3205 component->val_bytes = val_bytes;
3208 #ifdef CONFIG_REGMAP
3211 * snd_soc_component_init_regmap() - Initialize regmap instance for the component
3212 * @component: The component for which to initialize the regmap instance
3213 * @regmap: The regmap instance that should be used by the component
3215 * This function allows deferred assignment of the regmap instance that is
3216 * associated with the component. Only use this if the regmap instance is not
3217 * yet ready when the component is registered. The function must also be called
3218 * before the first IO attempt of the component.
3220 void snd_soc_component_init_regmap(struct snd_soc_component *component,
3221 struct regmap *regmap)
3223 component->regmap = regmap;
3224 snd_soc_component_setup_regmap(component);
3226 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
3229 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component
3230 * @component: The component for which to de-initialize the regmap instance
3232 * Calls regmap_exit() on the regmap instance associated to the component and
3233 * removes the regmap instance from the component.
3235 * This function should only be used if snd_soc_component_init_regmap() was used
3236 * to initialize the regmap instance.
3238 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
3240 regmap_exit(component->regmap);
3241 component->regmap = NULL;
3243 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
3247 static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
3249 if (!component->write && !component->read) {
3250 if (!component->regmap)
3251 component->regmap = dev_get_regmap(component->dev, NULL);
3252 if (component->regmap)
3253 snd_soc_component_setup_regmap(component);
3256 list_add(&component->list, &component_list);
3257 INIT_LIST_HEAD(&component->dobj_list);
3260 static void snd_soc_component_add(struct snd_soc_component *component)
3262 mutex_lock(&client_mutex);
3263 snd_soc_component_add_unlocked(component);
3264 mutex_unlock(&client_mutex);
3267 static void snd_soc_component_cleanup(struct snd_soc_component *component)
3269 snd_soc_unregister_dais(component);
3270 kfree(component->name);
3273 static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
3275 struct snd_soc_card *card = component->card;
3278 snd_soc_unregister_card(card);
3280 list_del(&component->list);
3283 int snd_soc_register_component(struct device *dev,
3284 const struct snd_soc_component_driver *cmpnt_drv,
3285 struct snd_soc_dai_driver *dai_drv,
3288 struct snd_soc_component *cmpnt;
3291 cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL);
3293 dev_err(dev, "ASoC: Failed to allocate memory\n");
3297 ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev);
3301 cmpnt->ignore_pmdown_time = true;
3302 cmpnt->registered_as_component = true;
3304 ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true);
3306 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3310 snd_soc_component_add(cmpnt);
3315 snd_soc_component_cleanup(cmpnt);
3320 EXPORT_SYMBOL_GPL(snd_soc_register_component);
3323 * snd_soc_unregister_component - Unregister a component from the ASoC core
3325 * @dev: The device to unregister
3327 void snd_soc_unregister_component(struct device *dev)
3329 struct snd_soc_component *cmpnt;
3331 mutex_lock(&client_mutex);
3332 list_for_each_entry(cmpnt, &component_list, list) {
3333 if (dev == cmpnt->dev && cmpnt->registered_as_component)
3336 mutex_unlock(&client_mutex);
3340 snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL);
3341 snd_soc_component_del_unlocked(cmpnt);
3342 mutex_unlock(&client_mutex);
3343 snd_soc_component_cleanup(cmpnt);
3346 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3348 static int snd_soc_platform_drv_probe(struct snd_soc_component *component)
3350 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3352 return platform->driver->probe(platform);
3355 static void snd_soc_platform_drv_remove(struct snd_soc_component *component)
3357 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3359 platform->driver->remove(platform);
3362 static int snd_soc_platform_drv_pcm_new(struct snd_soc_pcm_runtime *rtd)
3364 struct snd_soc_platform *platform = rtd->platform;
3366 if (platform->driver->pcm_new)
3367 return platform->driver->pcm_new(rtd);
3372 static void snd_soc_platform_drv_pcm_free(struct snd_pcm *pcm)
3374 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
3375 struct snd_soc_platform *platform = rtd->platform;
3377 if (platform->driver->pcm_free)
3378 platform->driver->pcm_free(pcm);
3382 * snd_soc_add_platform - Add a platform to the ASoC core
3383 * @dev: The parent device for the platform
3384 * @platform: The platform to add
3385 * @platform_drv: The driver for the platform
3387 int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3388 const struct snd_soc_platform_driver *platform_drv)
3392 ret = snd_soc_component_initialize(&platform->component,
3393 &platform_drv->component_driver, dev);
3397 platform->dev = dev;
3398 platform->driver = platform_drv;
3400 if (platform_drv->probe)
3401 platform->component.probe = snd_soc_platform_drv_probe;
3402 if (platform_drv->remove)
3403 platform->component.remove = snd_soc_platform_drv_remove;
3404 if (platform_drv->pcm_new)
3405 platform->component.pcm_new = snd_soc_platform_drv_pcm_new;
3406 if (platform_drv->pcm_free)
3407 platform->component.pcm_free = snd_soc_platform_drv_pcm_free;
3409 #ifdef CONFIG_DEBUG_FS
3410 platform->component.debugfs_prefix = "platform";
3413 mutex_lock(&client_mutex);
3414 snd_soc_component_add_unlocked(&platform->component);
3415 list_add(&platform->list, &platform_list);
3416 mutex_unlock(&client_mutex);
3418 dev_dbg(dev, "ASoC: Registered platform '%s'\n",
3419 platform->component.name);
3423 EXPORT_SYMBOL_GPL(snd_soc_add_platform);
3426 * snd_soc_register_platform - Register a platform with the ASoC core
3428 * @dev: The device for the platform
3429 * @platform_drv: The driver for the platform
3431 int snd_soc_register_platform(struct device *dev,
3432 const struct snd_soc_platform_driver *platform_drv)
3434 struct snd_soc_platform *platform;
3437 dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
3439 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3440 if (platform == NULL)
3443 ret = snd_soc_add_platform(dev, platform, platform_drv);
3449 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3452 * snd_soc_remove_platform - Remove a platform from the ASoC core
3453 * @platform: the platform to remove
3455 void snd_soc_remove_platform(struct snd_soc_platform *platform)
3458 mutex_lock(&client_mutex);
3459 list_del(&platform->list);
3460 snd_soc_component_del_unlocked(&platform->component);
3461 mutex_unlock(&client_mutex);
3463 dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
3464 platform->component.name);
3466 snd_soc_component_cleanup(&platform->component);
3468 EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
3470 struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
3472 struct snd_soc_platform *platform;
3474 mutex_lock(&client_mutex);
3475 list_for_each_entry(platform, &platform_list, list) {
3476 if (dev == platform->dev) {
3477 mutex_unlock(&client_mutex);
3481 mutex_unlock(&client_mutex);
3485 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
3488 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3490 * @dev: platform to unregister
3492 void snd_soc_unregister_platform(struct device *dev)
3494 struct snd_soc_platform *platform;
3496 platform = snd_soc_lookup_platform(dev);
3500 snd_soc_remove_platform(platform);
3503 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3505 static u64 codec_format_map[] = {
3506 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3507 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3508 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3509 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3510 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3511 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3512 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,