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/of_graph.h>
38 #include <linux/dmi.h>
39 #include <sound/core.h>
40 #include <sound/jack.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/soc.h>
44 #include <sound/soc-dpcm.h>
45 #include <sound/soc-topology.h>
46 #include <sound/initval.h>
48 #define CREATE_TRACE_POINTS
49 #include <trace/events/asoc.h>
53 #ifdef CONFIG_DEBUG_FS
54 struct dentry *snd_soc_debugfs_root;
55 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
58 static DEFINE_MUTEX(client_mutex);
59 static LIST_HEAD(platform_list);
60 static LIST_HEAD(codec_list);
61 static LIST_HEAD(component_list);
64 * This is a timeout to do a DAPM powerdown after a stream is closed().
65 * It can be used to eliminate pops between different playback streams, e.g.
66 * between two audio tracks.
68 static int pmdown_time = 5000;
69 module_param(pmdown_time, int, 0);
70 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
72 /* If a DMI filed contain strings in this blacklist (e.g.
73 * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
74 * as invalid and dropped when setting the card long name from DMI info.
76 static const char * const dmi_blacklist[] = {
77 "To be filled by OEM",
83 NULL, /* terminator */
86 /* returns the minimum number of bytes needed to represent
87 * a particular given value */
88 static int min_bytes_needed(unsigned long val)
93 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
96 c = (sizeof val * 8) - c;
104 /* fill buf which is 'len' bytes with a formatted
105 * string of the form 'reg: value\n' */
106 static int format_register_str(struct snd_soc_codec *codec,
107 unsigned int reg, char *buf, size_t len)
109 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
110 int regsize = codec->driver->reg_word_size * 2;
113 /* +2 for ': ' and + 1 for '\n' */
114 if (wordsize + regsize + 2 + 1 != len)
117 sprintf(buf, "%.*x: ", wordsize, reg);
120 ret = snd_soc_read(codec, reg);
122 memset(buf, 'X', regsize);
124 sprintf(buf, "%.*x", regsize, ret);
126 /* no NUL-termination needed */
130 /* codec register dump */
131 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
132 size_t count, loff_t pos)
135 int wordsize, regsize;
140 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
141 regsize = codec->driver->reg_word_size * 2;
143 len = wordsize + regsize + 2 + 1;
145 if (!codec->driver->reg_cache_size)
148 if (codec->driver->reg_cache_step)
149 step = codec->driver->reg_cache_step;
151 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
155 if (total + len >= count - 1)
157 format_register_str(codec, i, buf + total, len);
163 total = min(total, count - 1);
168 static ssize_t codec_reg_show(struct device *dev,
169 struct device_attribute *attr, char *buf)
171 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
173 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
176 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
178 static ssize_t pmdown_time_show(struct device *dev,
179 struct device_attribute *attr, char *buf)
181 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
183 return sprintf(buf, "%ld\n", rtd->pmdown_time);
186 static ssize_t pmdown_time_set(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
190 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
193 ret = kstrtol(buf, 10, &rtd->pmdown_time);
200 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
202 static struct attribute *soc_dev_attrs[] = {
203 &dev_attr_codec_reg.attr,
204 &dev_attr_pmdown_time.attr,
208 static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
209 struct attribute *attr, int idx)
211 struct device *dev = kobj_to_dev(kobj);
212 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
214 if (attr == &dev_attr_pmdown_time.attr)
215 return attr->mode; /* always visible */
216 return rtd->codec ? attr->mode : 0; /* enabled only with codec */
219 static const struct attribute_group soc_dapm_dev_group = {
220 .attrs = soc_dapm_dev_attrs,
221 .is_visible = soc_dev_attr_is_visible,
224 static const struct attribute_group soc_dev_roup = {
225 .attrs = soc_dev_attrs,
226 .is_visible = soc_dev_attr_is_visible,
229 static const struct attribute_group *soc_dev_attr_groups[] = {
235 #ifdef CONFIG_DEBUG_FS
236 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
237 size_t count, loff_t *ppos)
240 struct snd_soc_codec *codec = file->private_data;
243 if (*ppos < 0 || !count)
246 buf = kmalloc(count, GFP_KERNEL);
250 ret = soc_codec_reg_show(codec, buf, count, *ppos);
252 if (copy_to_user(user_buf, buf, ret)) {
263 static ssize_t codec_reg_write_file(struct file *file,
264 const char __user *user_buf, size_t count, loff_t *ppos)
269 unsigned long reg, value;
270 struct snd_soc_codec *codec = file->private_data;
273 buf_size = min(count, (sizeof(buf)-1));
274 if (copy_from_user(buf, user_buf, buf_size))
278 while (*start == ' ')
280 reg = simple_strtoul(start, &start, 16);
281 while (*start == ' ')
283 ret = kstrtoul(start, 16, &value);
287 /* Userspace has been fiddling around behind the kernel's back */
288 add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
290 snd_soc_write(codec, reg, value);
294 static const struct file_operations codec_reg_fops = {
296 .read = codec_reg_read_file,
297 .write = codec_reg_write_file,
298 .llseek = default_llseek,
301 static void soc_init_component_debugfs(struct snd_soc_component *component)
303 if (!component->card->debugfs_card_root)
306 if (component->debugfs_prefix) {
309 name = kasprintf(GFP_KERNEL, "%s:%s",
310 component->debugfs_prefix, component->name);
312 component->debugfs_root = debugfs_create_dir(name,
313 component->card->debugfs_card_root);
317 component->debugfs_root = debugfs_create_dir(component->name,
318 component->card->debugfs_card_root);
321 if (!component->debugfs_root) {
322 dev_warn(component->dev,
323 "ASoC: Failed to create component debugfs directory\n");
327 snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
328 component->debugfs_root);
330 if (component->init_debugfs)
331 component->init_debugfs(component);
334 static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
336 debugfs_remove_recursive(component->debugfs_root);
339 static void soc_init_codec_debugfs(struct snd_soc_component *component)
341 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
342 struct dentry *debugfs_reg;
344 debugfs_reg = debugfs_create_file("codec_reg", 0644,
345 codec->component.debugfs_root,
346 codec, &codec_reg_fops);
349 "ASoC: Failed to create codec register debugfs file\n");
352 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
353 size_t count, loff_t *ppos)
355 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
356 ssize_t len, ret = 0;
357 struct snd_soc_codec *codec;
362 mutex_lock(&client_mutex);
364 list_for_each_entry(codec, &codec_list, list) {
365 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
366 codec->component.name);
369 if (ret > PAGE_SIZE) {
375 mutex_unlock(&client_mutex);
378 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
385 static const struct file_operations codec_list_fops = {
386 .read = codec_list_read_file,
387 .llseek = default_llseek,/* read accesses f_pos */
390 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
391 size_t count, loff_t *ppos)
393 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
394 ssize_t len, ret = 0;
395 struct snd_soc_component *component;
396 struct snd_soc_dai *dai;
401 mutex_lock(&client_mutex);
403 list_for_each_entry(component, &component_list, list) {
404 list_for_each_entry(dai, &component->dai_list, list) {
405 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
409 if (ret > PAGE_SIZE) {
416 mutex_unlock(&client_mutex);
418 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
425 static const struct file_operations dai_list_fops = {
426 .read = dai_list_read_file,
427 .llseek = default_llseek,/* read accesses f_pos */
430 static ssize_t platform_list_read_file(struct file *file,
431 char __user *user_buf,
432 size_t count, loff_t *ppos)
434 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
435 ssize_t len, ret = 0;
436 struct snd_soc_platform *platform;
441 mutex_lock(&client_mutex);
443 list_for_each_entry(platform, &platform_list, list) {
444 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
445 platform->component.name);
448 if (ret > PAGE_SIZE) {
454 mutex_unlock(&client_mutex);
456 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
463 static const struct file_operations platform_list_fops = {
464 .read = platform_list_read_file,
465 .llseek = default_llseek,/* read accesses f_pos */
468 static void soc_init_card_debugfs(struct snd_soc_card *card)
470 if (!snd_soc_debugfs_root)
473 card->debugfs_card_root = debugfs_create_dir(card->name,
474 snd_soc_debugfs_root);
475 if (!card->debugfs_card_root) {
477 "ASoC: Failed to create card debugfs directory\n");
481 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
482 card->debugfs_card_root,
484 if (!card->debugfs_pop_time)
486 "ASoC: Failed to create pop time debugfs file\n");
489 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
491 debugfs_remove_recursive(card->debugfs_card_root);
495 static void snd_soc_debugfs_init(void)
497 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
498 if (IS_ERR_OR_NULL(snd_soc_debugfs_root)) {
499 pr_warn("ASoC: Failed to create debugfs directory\n");
500 snd_soc_debugfs_root = NULL;
504 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
506 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
508 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
510 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
512 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
513 &platform_list_fops))
514 pr_warn("ASoC: Failed to create platform list debugfs file\n");
517 static void snd_soc_debugfs_exit(void)
519 debugfs_remove_recursive(snd_soc_debugfs_root);
524 #define soc_init_codec_debugfs NULL
526 static inline void soc_init_component_debugfs(
527 struct snd_soc_component *component)
531 static inline void soc_cleanup_component_debugfs(
532 struct snd_soc_component *component)
536 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
540 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
544 static inline void snd_soc_debugfs_init(void)
548 static inline void snd_soc_debugfs_exit(void)
554 static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
555 struct snd_soc_component *component)
557 struct snd_soc_rtdcom_list *rtdcom;
558 struct snd_soc_rtdcom_list *new_rtdcom;
560 for_each_rtdcom(rtd, rtdcom) {
561 /* already connected */
562 if (rtdcom->component == component)
566 new_rtdcom = kmalloc(sizeof(*new_rtdcom), GFP_KERNEL);
570 new_rtdcom->component = component;
571 INIT_LIST_HEAD(&new_rtdcom->list);
573 list_add_tail(&new_rtdcom->list, &rtd->component_list);
578 static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
580 struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
582 for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
585 INIT_LIST_HEAD(&rtd->component_list);
588 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
589 const char *driver_name)
591 struct snd_soc_rtdcom_list *rtdcom;
593 for_each_rtdcom(rtd, rtdcom) {
594 if ((rtdcom->component->driver->name == driver_name) ||
595 strcmp(rtdcom->component->driver->name, driver_name) == 0)
596 return rtdcom->component;
602 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
603 const char *dai_link, int stream)
605 struct snd_soc_pcm_runtime *rtd;
607 list_for_each_entry(rtd, &card->rtd_list, list) {
608 if (rtd->dai_link->no_pcm &&
609 !strcmp(rtd->dai_link->name, dai_link))
610 return rtd->pcm->streams[stream].substream;
612 dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
615 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
617 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
618 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
620 struct snd_soc_pcm_runtime *rtd;
622 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
626 INIT_LIST_HEAD(&rtd->component_list);
628 rtd->dai_link = dai_link;
629 rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) *
630 dai_link->num_codecs,
632 if (!rtd->codec_dais) {
640 static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
642 if (rtd && rtd->codec_dais)
643 kfree(rtd->codec_dais);
644 snd_soc_rtdcom_del_all(rtd);
648 static void soc_add_pcm_runtime(struct snd_soc_card *card,
649 struct snd_soc_pcm_runtime *rtd)
651 list_add_tail(&rtd->list, &card->rtd_list);
652 rtd->num = card->num_rtd;
656 static void soc_remove_pcm_runtimes(struct snd_soc_card *card)
658 struct snd_soc_pcm_runtime *rtd, *_rtd;
660 list_for_each_entry_safe(rtd, _rtd, &card->rtd_list, list) {
661 list_del(&rtd->list);
662 soc_free_pcm_runtime(rtd);
668 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
669 const char *dai_link)
671 struct snd_soc_pcm_runtime *rtd;
673 list_for_each_entry(rtd, &card->rtd_list, list) {
674 if (!strcmp(rtd->dai_link->name, dai_link))
677 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
680 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
682 static void codec2codec_close_delayed_work(struct work_struct *work)
684 /* Currently nothing to do for c2c links
685 * Since c2c links are internal nodes in the DAPM graph and
686 * don't interface with the outside world or application layer
687 * we don't have to do any special handling on close.
691 #ifdef CONFIG_PM_SLEEP
692 /* powers down audio subsystem for suspend */
693 int snd_soc_suspend(struct device *dev)
695 struct snd_soc_card *card = dev_get_drvdata(dev);
696 struct snd_soc_component *component;
697 struct snd_soc_pcm_runtime *rtd;
700 /* If the card is not initialized yet there is nothing to do */
701 if (!card->instantiated)
704 /* Due to the resume being scheduled into a workqueue we could
705 * suspend before that's finished - wait for it to complete.
707 snd_power_lock(card->snd_card);
708 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
709 snd_power_unlock(card->snd_card);
711 /* we're going to block userspace touching us until resume completes */
712 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
714 /* mute any active DACs */
715 list_for_each_entry(rtd, &card->rtd_list, list) {
717 if (rtd->dai_link->ignore_suspend)
720 for (i = 0; i < rtd->num_codecs; i++) {
721 struct snd_soc_dai *dai = rtd->codec_dais[i];
722 struct snd_soc_dai_driver *drv = dai->driver;
724 if (drv->ops->digital_mute && dai->playback_active)
725 drv->ops->digital_mute(dai, 1);
729 /* suspend all pcms */
730 list_for_each_entry(rtd, &card->rtd_list, list) {
731 if (rtd->dai_link->ignore_suspend)
734 snd_pcm_suspend_all(rtd->pcm);
737 if (card->suspend_pre)
738 card->suspend_pre(card);
740 list_for_each_entry(rtd, &card->rtd_list, list) {
741 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
743 if (rtd->dai_link->ignore_suspend)
746 if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control)
747 cpu_dai->driver->suspend(cpu_dai);
750 /* close any waiting streams */
751 list_for_each_entry(rtd, &card->rtd_list, list)
752 flush_delayed_work(&rtd->delayed_work);
754 list_for_each_entry(rtd, &card->rtd_list, list) {
756 if (rtd->dai_link->ignore_suspend)
759 snd_soc_dapm_stream_event(rtd,
760 SNDRV_PCM_STREAM_PLAYBACK,
761 SND_SOC_DAPM_STREAM_SUSPEND);
763 snd_soc_dapm_stream_event(rtd,
764 SNDRV_PCM_STREAM_CAPTURE,
765 SND_SOC_DAPM_STREAM_SUSPEND);
768 /* Recheck all endpoints too, their state is affected by suspend */
769 dapm_mark_endpoints_dirty(card);
770 snd_soc_dapm_sync(&card->dapm);
772 /* suspend all COMPONENTs */
773 list_for_each_entry(component, &card->component_dev_list, card_list) {
774 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
776 /* If there are paths active then the COMPONENT will be held with
777 * bias _ON and should not be suspended. */
778 if (!component->suspended) {
779 switch (snd_soc_dapm_get_bias_level(dapm)) {
780 case SND_SOC_BIAS_STANDBY:
782 * If the COMPONENT is capable of idle
783 * bias off then being in STANDBY
784 * means it's doing something,
785 * otherwise fall through.
787 if (dapm->idle_bias_off) {
788 dev_dbg(component->dev,
789 "ASoC: idle_bias_off CODEC on over suspend\n");
793 case SND_SOC_BIAS_OFF:
794 if (component->suspend)
795 component->suspend(component);
796 component->suspended = 1;
797 if (component->regmap)
798 regcache_mark_dirty(component->regmap);
799 /* deactivate pins to sleep state */
800 pinctrl_pm_select_sleep_state(component->dev);
803 dev_dbg(component->dev,
804 "ASoC: COMPONENT is on over suspend\n");
810 list_for_each_entry(rtd, &card->rtd_list, list) {
811 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
813 if (rtd->dai_link->ignore_suspend)
816 if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control)
817 cpu_dai->driver->suspend(cpu_dai);
819 /* deactivate pins to sleep state */
820 pinctrl_pm_select_sleep_state(cpu_dai->dev);
823 if (card->suspend_post)
824 card->suspend_post(card);
828 EXPORT_SYMBOL_GPL(snd_soc_suspend);
830 /* deferred resume work, so resume can complete before we finished
831 * setting our codec back up, which can be very slow on I2C
833 static void soc_resume_deferred(struct work_struct *work)
835 struct snd_soc_card *card =
836 container_of(work, struct snd_soc_card, deferred_resume_work);
837 struct snd_soc_pcm_runtime *rtd;
838 struct snd_soc_component *component;
841 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
842 * so userspace apps are blocked from touching us
845 dev_dbg(card->dev, "ASoC: starting resume work\n");
847 /* Bring us up into D2 so that DAPM starts enabling things */
848 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
850 if (card->resume_pre)
851 card->resume_pre(card);
853 /* resume control bus DAIs */
854 list_for_each_entry(rtd, &card->rtd_list, list) {
855 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
857 if (rtd->dai_link->ignore_suspend)
860 if (cpu_dai->driver->resume && cpu_dai->driver->bus_control)
861 cpu_dai->driver->resume(cpu_dai);
864 list_for_each_entry(component, &card->component_dev_list, card_list) {
865 if (component->suspended) {
866 if (component->resume)
867 component->resume(component);
868 component->suspended = 0;
872 list_for_each_entry(rtd, &card->rtd_list, list) {
874 if (rtd->dai_link->ignore_suspend)
877 snd_soc_dapm_stream_event(rtd,
878 SNDRV_PCM_STREAM_PLAYBACK,
879 SND_SOC_DAPM_STREAM_RESUME);
881 snd_soc_dapm_stream_event(rtd,
882 SNDRV_PCM_STREAM_CAPTURE,
883 SND_SOC_DAPM_STREAM_RESUME);
886 /* unmute any active DACs */
887 list_for_each_entry(rtd, &card->rtd_list, list) {
889 if (rtd->dai_link->ignore_suspend)
892 for (i = 0; i < rtd->num_codecs; i++) {
893 struct snd_soc_dai *dai = rtd->codec_dais[i];
894 struct snd_soc_dai_driver *drv = dai->driver;
896 if (drv->ops->digital_mute && dai->playback_active)
897 drv->ops->digital_mute(dai, 0);
901 list_for_each_entry(rtd, &card->rtd_list, list) {
902 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
904 if (rtd->dai_link->ignore_suspend)
907 if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control)
908 cpu_dai->driver->resume(cpu_dai);
911 if (card->resume_post)
912 card->resume_post(card);
914 dev_dbg(card->dev, "ASoC: resume work completed\n");
916 /* Recheck all endpoints too, their state is affected by suspend */
917 dapm_mark_endpoints_dirty(card);
918 snd_soc_dapm_sync(&card->dapm);
920 /* userspace can access us now we are back as we were before */
921 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
924 /* powers up audio subsystem after a suspend */
925 int snd_soc_resume(struct device *dev)
927 struct snd_soc_card *card = dev_get_drvdata(dev);
928 bool bus_control = false;
929 struct snd_soc_pcm_runtime *rtd;
931 /* If the card is not initialized yet there is nothing to do */
932 if (!card->instantiated)
935 /* activate pins from sleep state */
936 list_for_each_entry(rtd, &card->rtd_list, list) {
937 struct snd_soc_dai **codec_dais = rtd->codec_dais;
938 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
942 pinctrl_pm_select_default_state(cpu_dai->dev);
944 for (j = 0; j < rtd->num_codecs; j++) {
945 struct snd_soc_dai *codec_dai = codec_dais[j];
946 if (codec_dai->active)
947 pinctrl_pm_select_default_state(codec_dai->dev);
952 * DAIs that also act as the control bus master might have other drivers
953 * hanging off them so need to resume immediately. Other drivers don't
954 * have that problem and may take a substantial amount of time to resume
955 * due to I/O costs and anti-pop so handle them out of line.
957 list_for_each_entry(rtd, &card->rtd_list, list) {
958 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
959 bus_control |= cpu_dai->driver->bus_control;
962 dev_dbg(dev, "ASoC: Resuming control bus master immediately\n");
963 soc_resume_deferred(&card->deferred_resume_work);
965 dev_dbg(dev, "ASoC: Scheduling resume work\n");
966 if (!schedule_work(&card->deferred_resume_work))
967 dev_err(dev, "ASoC: resume work item may be lost\n");
972 EXPORT_SYMBOL_GPL(snd_soc_resume);
974 #define snd_soc_suspend NULL
975 #define snd_soc_resume NULL
978 static const struct snd_soc_dai_ops null_dai_ops = {
981 static struct snd_soc_component *soc_find_component(
982 const struct device_node *of_node, const char *name)
984 struct snd_soc_component *component;
986 lockdep_assert_held(&client_mutex);
988 list_for_each_entry(component, &component_list, list) {
990 if (component->dev->of_node == of_node)
992 } else if (strcmp(component->name, name) == 0) {
1001 * snd_soc_find_dai - Find a registered DAI
1003 * @dlc: name of the DAI and optional component info to match
1005 * This function will search all registered components and their DAIs to
1006 * find the DAI of the same name. The component's of_node and name
1007 * should also match if being specified.
1009 * Return: pointer of DAI, or NULL if not found.
1011 struct snd_soc_dai *snd_soc_find_dai(
1012 const struct snd_soc_dai_link_component *dlc)
1014 struct snd_soc_component *component;
1015 struct snd_soc_dai *dai;
1016 struct device_node *component_of_node;
1018 lockdep_assert_held(&client_mutex);
1020 /* Find CPU DAI from registered DAIs*/
1021 list_for_each_entry(component, &component_list, list) {
1022 component_of_node = component->dev->of_node;
1023 if (!component_of_node && component->dev->parent)
1024 component_of_node = component->dev->parent->of_node;
1026 if (dlc->of_node && component_of_node != dlc->of_node)
1028 if (dlc->name && strcmp(component->name, dlc->name))
1030 list_for_each_entry(dai, &component->dai_list, list) {
1031 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
1040 EXPORT_SYMBOL_GPL(snd_soc_find_dai);
1044 * snd_soc_find_dai_link - Find a DAI link
1047 * @id: DAI link ID to match
1048 * @name: DAI link name to match, optional
1049 * @stream_name: DAI link stream name to match, optional
1051 * This function will search all existing DAI links of the soc card to
1052 * find the link of the same ID. Since DAI links may not have their
1053 * unique ID, so name and stream name should also match if being
1056 * Return: pointer of DAI link, or NULL if not found.
1058 struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
1059 int id, const char *name,
1060 const char *stream_name)
1062 struct snd_soc_dai_link *link, *_link;
1064 lockdep_assert_held(&client_mutex);
1066 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1070 if (name && (!link->name || strcmp(name, link->name)))
1073 if (stream_name && (!link->stream_name
1074 || strcmp(stream_name, link->stream_name)))
1082 EXPORT_SYMBOL_GPL(snd_soc_find_dai_link);
1084 static bool soc_is_dai_link_bound(struct snd_soc_card *card,
1085 struct snd_soc_dai_link *dai_link)
1087 struct snd_soc_pcm_runtime *rtd;
1089 list_for_each_entry(rtd, &card->rtd_list, list) {
1090 if (rtd->dai_link == dai_link)
1097 static int soc_bind_dai_link(struct snd_soc_card *card,
1098 struct snd_soc_dai_link *dai_link)
1100 struct snd_soc_pcm_runtime *rtd;
1101 struct snd_soc_dai_link_component *codecs = dai_link->codecs;
1102 struct snd_soc_dai_link_component cpu_dai_component;
1103 struct snd_soc_component *component;
1104 struct snd_soc_dai **codec_dais;
1105 struct snd_soc_platform *platform;
1106 struct device_node *platform_of_node;
1107 const char *platform_name;
1110 dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
1112 if (soc_is_dai_link_bound(card, dai_link)) {
1113 dev_dbg(card->dev, "ASoC: dai link %s already bound\n",
1118 rtd = soc_new_pcm_runtime(card, dai_link);
1122 cpu_dai_component.name = dai_link->cpu_name;
1123 cpu_dai_component.of_node = dai_link->cpu_of_node;
1124 cpu_dai_component.dai_name = dai_link->cpu_dai_name;
1125 rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
1126 if (!rtd->cpu_dai) {
1127 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
1128 dai_link->cpu_dai_name);
1131 snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component);
1133 rtd->num_codecs = dai_link->num_codecs;
1135 /* Find CODEC from registered CODECs */
1136 codec_dais = rtd->codec_dais;
1137 for (i = 0; i < rtd->num_codecs; i++) {
1138 codec_dais[i] = snd_soc_find_dai(&codecs[i]);
1139 if (!codec_dais[i]) {
1140 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
1141 codecs[i].dai_name);
1144 snd_soc_rtdcom_add(rtd, codec_dais[i]->component);
1147 /* Single codec links expect codec and codec_dai in runtime data */
1148 rtd->codec_dai = codec_dais[0];
1149 rtd->codec = rtd->codec_dai->codec;
1151 /* if there's no platform we match on the empty platform */
1152 platform_name = dai_link->platform_name;
1153 if (!platform_name && !dai_link->platform_of_node)
1154 platform_name = "snd-soc-dummy";
1156 /* find one from the set of registered platforms */
1157 list_for_each_entry(component, &component_list, list) {
1158 platform_of_node = component->dev->of_node;
1159 if (!platform_of_node && component->dev->parent->of_node)
1160 platform_of_node = component->dev->parent->of_node;
1162 if (dai_link->platform_of_node) {
1163 if (platform_of_node != dai_link->platform_of_node)
1166 if (strcmp(component->name, platform_name))
1170 snd_soc_rtdcom_add(rtd, component);
1173 /* find one from the set of registered platforms */
1174 list_for_each_entry(platform, &platform_list, list) {
1175 platform_of_node = platform->dev->of_node;
1176 if (!platform_of_node && platform->dev->parent->of_node)
1177 platform_of_node = platform->dev->parent->of_node;
1179 if (dai_link->platform_of_node) {
1180 if (platform_of_node != dai_link->platform_of_node)
1183 if (strcmp(platform->component.name, platform_name))
1187 rtd->platform = platform;
1189 if (!rtd->platform) {
1190 dev_err(card->dev, "ASoC: platform %s not registered\n",
1191 dai_link->platform_name);
1195 soc_add_pcm_runtime(card, rtd);
1199 soc_free_pcm_runtime(rtd);
1200 return -EPROBE_DEFER;
1203 static void soc_remove_component(struct snd_soc_component *component)
1205 if (!component->card)
1208 list_del(&component->card_list);
1210 if (component->remove)
1211 component->remove(component);
1213 snd_soc_dapm_free(snd_soc_component_get_dapm(component));
1215 soc_cleanup_component_debugfs(component);
1216 component->card = NULL;
1217 module_put(component->dev->driver->owner);
1220 static void soc_remove_dai(struct snd_soc_dai *dai, int order)
1224 if (dai && dai->probed &&
1225 dai->driver->remove_order == order) {
1226 if (dai->driver->remove) {
1227 err = dai->driver->remove(dai);
1230 "ASoC: failed to remove %s: %d\n",
1237 static void soc_remove_link_dais(struct snd_soc_card *card,
1238 struct snd_soc_pcm_runtime *rtd, int order)
1242 /* unregister the rtd device */
1243 if (rtd->dev_registered) {
1244 device_unregister(rtd->dev);
1245 rtd->dev_registered = 0;
1248 /* remove the CODEC DAI */
1249 for (i = 0; i < rtd->num_codecs; i++)
1250 soc_remove_dai(rtd->codec_dais[i], order);
1252 soc_remove_dai(rtd->cpu_dai, order);
1255 static void soc_remove_link_components(struct snd_soc_card *card,
1256 struct snd_soc_pcm_runtime *rtd, int order)
1258 struct snd_soc_component *component;
1259 struct snd_soc_rtdcom_list *rtdcom;
1261 for_each_rtdcom(rtd, rtdcom) {
1262 component = rtdcom->component;
1264 if (component->driver->remove_order == order)
1265 soc_remove_component(component);
1269 static void soc_remove_dai_links(struct snd_soc_card *card)
1272 struct snd_soc_pcm_runtime *rtd;
1273 struct snd_soc_dai_link *link, *_link;
1275 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1277 list_for_each_entry(rtd, &card->rtd_list, list)
1278 soc_remove_link_dais(card, rtd, order);
1281 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1283 list_for_each_entry(rtd, &card->rtd_list, list)
1284 soc_remove_link_components(card, rtd, order);
1287 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1288 if (link->dobj.type == SND_SOC_DOBJ_DAI_LINK)
1289 dev_warn(card->dev, "Topology forgot to remove link %s?\n",
1292 list_del(&link->list);
1293 card->num_dai_links--;
1297 static int snd_soc_init_multicodec(struct snd_soc_card *card,
1298 struct snd_soc_dai_link *dai_link)
1300 /* Legacy codec/codec_dai link is a single entry in multicodec */
1301 if (dai_link->codec_name || dai_link->codec_of_node ||
1302 dai_link->codec_dai_name) {
1303 dai_link->num_codecs = 1;
1305 dai_link->codecs = devm_kzalloc(card->dev,
1306 sizeof(struct snd_soc_dai_link_component),
1308 if (!dai_link->codecs)
1311 dai_link->codecs[0].name = dai_link->codec_name;
1312 dai_link->codecs[0].of_node = dai_link->codec_of_node;
1313 dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
1316 if (!dai_link->codecs) {
1317 dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
1324 static int soc_init_dai_link(struct snd_soc_card *card,
1325 struct snd_soc_dai_link *link)
1329 ret = snd_soc_init_multicodec(card, link);
1331 dev_err(card->dev, "ASoC: failed to init multicodec\n");
1335 for (i = 0; i < link->num_codecs; i++) {
1337 * Codec must be specified by 1 of name or OF node,
1338 * not both or neither.
1340 if (!!link->codecs[i].name ==
1341 !!link->codecs[i].of_node) {
1342 dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
1346 /* Codec DAI name must be specified */
1347 if (!link->codecs[i].dai_name) {
1348 dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
1355 * Platform may be specified by either name or OF node, but
1356 * can be left unspecified, and a dummy platform will be used.
1358 if (link->platform_name && link->platform_of_node) {
1360 "ASoC: Both platform name/of_node are set for %s\n",
1366 * CPU device may be specified by either name or OF node, but
1367 * can be left unspecified, and will be matched based on DAI
1370 if (link->cpu_name && link->cpu_of_node) {
1372 "ASoC: Neither/both cpu name/of_node are set for %s\n",
1377 * At least one of CPU DAI name or CPU device name/node must be
1380 if (!link->cpu_dai_name &&
1381 !(link->cpu_name || link->cpu_of_node)) {
1383 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
1392 * snd_soc_add_dai_link - Add a DAI link dynamically
1393 * @card: The ASoC card to which the DAI link is added
1394 * @dai_link: The new DAI link to add
1396 * This function adds a DAI link to the ASoC card's link list.
1398 * Note: Topology can use this API to add DAI links when probing the
1399 * topology component. And machine drivers can still define static
1400 * DAI links in dai_link array.
1402 int snd_soc_add_dai_link(struct snd_soc_card *card,
1403 struct snd_soc_dai_link *dai_link)
1405 if (dai_link->dobj.type
1406 && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1407 dev_err(card->dev, "Invalid dai link type %d\n",
1408 dai_link->dobj.type);
1412 lockdep_assert_held(&client_mutex);
1413 /* Notify the machine driver for extra initialization
1414 * on the link created by topology.
1416 if (dai_link->dobj.type && card->add_dai_link)
1417 card->add_dai_link(card, dai_link);
1419 list_add_tail(&dai_link->list, &card->dai_link_list);
1420 card->num_dai_links++;
1424 EXPORT_SYMBOL_GPL(snd_soc_add_dai_link);
1427 * snd_soc_remove_dai_link - Remove a DAI link from the list
1428 * @card: The ASoC card that owns the link
1429 * @dai_link: The DAI link to remove
1431 * This function removes a DAI link from the ASoC card's link list.
1433 * For DAI links previously added by topology, topology should
1434 * remove them by using the dobj embedded in the link.
1436 void snd_soc_remove_dai_link(struct snd_soc_card *card,
1437 struct snd_soc_dai_link *dai_link)
1439 struct snd_soc_dai_link *link, *_link;
1441 if (dai_link->dobj.type
1442 && dai_link->dobj.type != SND_SOC_DOBJ_DAI_LINK) {
1443 dev_err(card->dev, "Invalid dai link type %d\n",
1444 dai_link->dobj.type);
1448 lockdep_assert_held(&client_mutex);
1449 /* Notify the machine driver for extra destruction
1450 * on the link created by topology.
1452 if (dai_link->dobj.type && card->remove_dai_link)
1453 card->remove_dai_link(card, dai_link);
1455 list_for_each_entry_safe(link, _link, &card->dai_link_list, list) {
1456 if (link == dai_link) {
1457 list_del(&link->list);
1458 card->num_dai_links--;
1463 EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link);
1465 static void soc_set_name_prefix(struct snd_soc_card *card,
1466 struct snd_soc_component *component)
1470 if (card->codec_conf == NULL)
1473 for (i = 0; i < card->num_configs; i++) {
1474 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1475 if (map->of_node && component->dev->of_node != map->of_node)
1477 if (map->dev_name && strcmp(component->name, map->dev_name))
1479 component->name_prefix = map->name_prefix;
1484 static int soc_probe_component(struct snd_soc_card *card,
1485 struct snd_soc_component *component)
1487 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1488 struct snd_soc_dai *dai;
1491 if (!strcmp(component->name, "snd-soc-dummy"))
1494 if (component->card) {
1495 if (component->card != card) {
1496 dev_err(component->dev,
1497 "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1498 card->name, component->card->name);
1504 if (!try_module_get(component->dev->driver->owner))
1507 component->card = card;
1509 soc_set_name_prefix(card, component);
1511 soc_init_component_debugfs(component);
1513 if (component->dapm_widgets) {
1514 ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets,
1515 component->num_dapm_widgets);
1518 dev_err(component->dev,
1519 "Failed to create new controls %d\n", ret);
1524 list_for_each_entry(dai, &component->dai_list, list) {
1525 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1527 dev_err(component->dev,
1528 "Failed to create DAI widgets %d\n", ret);
1533 if (component->probe) {
1534 ret = component->probe(component);
1536 dev_err(component->dev,
1537 "ASoC: failed to probe component %d\n", ret);
1541 WARN(dapm->idle_bias_off &&
1542 dapm->bias_level != SND_SOC_BIAS_OFF,
1543 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1547 /* machine specific init */
1548 if (component->init) {
1549 ret = component->init(component);
1551 dev_err(component->dev,
1552 "Failed to do machine specific init %d\n", ret);
1557 if (component->controls)
1558 snd_soc_add_component_controls(component, component->controls,
1559 component->num_controls);
1560 if (component->dapm_routes)
1561 snd_soc_dapm_add_routes(dapm, component->dapm_routes,
1562 component->num_dapm_routes);
1564 list_add(&dapm->list, &card->dapm_list);
1565 list_add(&component->card_list, &card->component_dev_list);
1570 soc_cleanup_component_debugfs(component);
1571 component->card = NULL;
1572 module_put(component->dev->driver->owner);
1577 static void rtd_release(struct device *dev)
1582 static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1587 /* register the rtd device */
1588 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1591 device_initialize(rtd->dev);
1592 rtd->dev->parent = rtd->card->dev;
1593 rtd->dev->release = rtd_release;
1594 rtd->dev->groups = soc_dev_attr_groups;
1595 dev_set_name(rtd->dev, "%s", name);
1596 dev_set_drvdata(rtd->dev, rtd);
1597 mutex_init(&rtd->pcm_mutex);
1598 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1599 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1600 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1601 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1602 ret = device_add(rtd->dev);
1604 /* calling put_device() here to free the rtd->dev */
1605 put_device(rtd->dev);
1606 dev_err(rtd->card->dev,
1607 "ASoC: failed to register runtime device: %d\n", ret);
1610 rtd->dev_registered = 1;
1614 static int soc_probe_link_components(struct snd_soc_card *card,
1615 struct snd_soc_pcm_runtime *rtd,
1618 struct snd_soc_component *component;
1619 struct snd_soc_rtdcom_list *rtdcom;
1622 for_each_rtdcom(rtd, rtdcom) {
1623 component = rtdcom->component;
1625 if (component->driver->probe_order == order) {
1626 ret = soc_probe_component(card, component);
1635 static int soc_probe_dai(struct snd_soc_dai *dai, int order)
1639 if (!dai->probed && dai->driver->probe_order == order) {
1640 if (dai->driver->probe) {
1641 ret = dai->driver->probe(dai);
1644 "ASoC: failed to probe DAI %s: %d\n",
1656 static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais,
1657 struct snd_soc_pcm_runtime *rtd)
1661 for (i = 0; i < num_dais; ++i) {
1662 struct snd_soc_dai_driver *drv = dais[i]->driver;
1664 if (!rtd->dai_link->no_pcm && drv->pcm_new)
1665 ret = drv->pcm_new(rtd, dais[i]);
1667 dev_err(dais[i]->dev,
1668 "ASoC: Failed to bind %s with pcm device\n",
1677 static int soc_link_dai_widgets(struct snd_soc_card *card,
1678 struct snd_soc_dai_link *dai_link,
1679 struct snd_soc_pcm_runtime *rtd)
1681 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1682 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1683 struct snd_soc_dapm_widget *sink, *source;
1686 if (rtd->num_codecs > 1)
1687 dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
1689 /* link the DAI widgets */
1690 sink = codec_dai->playback_widget;
1691 source = cpu_dai->capture_widget;
1692 if (sink && source) {
1693 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1694 dai_link->num_params,
1697 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1698 sink->name, source->name, ret);
1703 sink = cpu_dai->playback_widget;
1704 source = codec_dai->capture_widget;
1705 if (sink && source) {
1706 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1707 dai_link->num_params,
1710 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1711 sink->name, source->name, ret);
1719 static int soc_probe_link_dais(struct snd_soc_card *card,
1720 struct snd_soc_pcm_runtime *rtd, int order)
1722 struct snd_soc_dai_link *dai_link = rtd->dai_link;
1723 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1726 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1727 card->name, rtd->num, order);
1729 /* set default power off timeout */
1730 rtd->pmdown_time = pmdown_time;
1732 ret = soc_probe_dai(cpu_dai, order);
1736 /* probe the CODEC DAI */
1737 for (i = 0; i < rtd->num_codecs; i++) {
1738 ret = soc_probe_dai(rtd->codec_dais[i], order);
1743 /* complete DAI probe during last probe */
1744 if (order != SND_SOC_COMP_ORDER_LAST)
1747 /* do machine specific initialization */
1748 if (dai_link->init) {
1749 ret = dai_link->init(rtd);
1751 dev_err(card->dev, "ASoC: failed to init %s: %d\n",
1752 dai_link->name, ret);
1757 if (dai_link->dai_fmt)
1758 snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
1760 ret = soc_post_component_init(rtd, dai_link->name);
1764 #ifdef CONFIG_DEBUG_FS
1765 /* add DPCM sysfs entries */
1766 if (dai_link->dynamic)
1767 soc_dpcm_debugfs_add(rtd);
1770 if (cpu_dai->driver->compress_new) {
1771 /*create compress_device"*/
1772 ret = cpu_dai->driver->compress_new(rtd, rtd->num);
1774 dev_err(card->dev, "ASoC: can't create compress %s\n",
1775 dai_link->stream_name);
1780 if (!dai_link->params) {
1781 /* create the pcm */
1782 ret = soc_new_pcm(rtd, rtd->num);
1784 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1785 dai_link->stream_name, ret);
1788 ret = soc_link_dai_pcm_new(&cpu_dai, 1, rtd);
1791 ret = soc_link_dai_pcm_new(rtd->codec_dais,
1792 rtd->num_codecs, rtd);
1796 INIT_DELAYED_WORK(&rtd->delayed_work,
1797 codec2codec_close_delayed_work);
1799 /* link the DAI widgets */
1800 ret = soc_link_dai_widgets(card, dai_link, rtd);
1809 static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
1811 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1812 struct snd_soc_component *component;
1814 struct device_node *codec_of_node;
1816 if (aux_dev->codec_of_node || aux_dev->codec_name) {
1817 /* codecs, usually analog devices */
1818 name = aux_dev->codec_name;
1819 codec_of_node = aux_dev->codec_of_node;
1820 component = soc_find_component(codec_of_node, name);
1823 name = of_node_full_name(codec_of_node);
1826 } else if (aux_dev->name) {
1827 /* generic components */
1828 name = aux_dev->name;
1829 component = soc_find_component(NULL, name);
1833 dev_err(card->dev, "ASoC: Invalid auxiliary device\n");
1837 component->init = aux_dev->init;
1838 list_add(&component->card_aux_list, &card->aux_comp_list);
1843 dev_err(card->dev, "ASoC: %s not registered\n", name);
1844 return -EPROBE_DEFER;
1847 static int soc_probe_aux_devices(struct snd_soc_card *card)
1849 struct snd_soc_component *comp;
1853 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1855 list_for_each_entry(comp, &card->aux_comp_list, card_aux_list) {
1856 if (comp->driver->probe_order == order) {
1857 ret = soc_probe_component(card, comp);
1860 "ASoC: failed to probe aux component %s %d\n",
1871 static void soc_remove_aux_devices(struct snd_soc_card *card)
1873 struct snd_soc_component *comp, *_comp;
1876 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1878 list_for_each_entry_safe(comp, _comp,
1879 &card->aux_comp_list, card_aux_list) {
1881 if (comp->driver->remove_order == order) {
1882 soc_remove_component(comp);
1883 /* remove it from the card's aux_comp_list */
1884 list_del(&comp->card_aux_list);
1890 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
1894 if (codec->cache_init)
1897 ret = snd_soc_cache_init(codec);
1900 "ASoC: Failed to set cache compression type: %d\n",
1904 codec->cache_init = 1;
1909 * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1910 * @rtd: The runtime for which the DAI link format should be changed
1911 * @dai_fmt: The new DAI link format
1913 * This function updates the DAI link format for all DAIs connected to the DAI
1914 * link for the specified runtime.
1916 * Note: For setups with a static format set the dai_fmt field in the
1917 * corresponding snd_dai_link struct instead of using this function.
1919 * Returns 0 on success, otherwise a negative error code.
1921 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1922 unsigned int dai_fmt)
1924 struct snd_soc_dai **codec_dais = rtd->codec_dais;
1925 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1929 for (i = 0; i < rtd->num_codecs; i++) {
1930 struct snd_soc_dai *codec_dai = codec_dais[i];
1932 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1933 if (ret != 0 && ret != -ENOTSUPP) {
1934 dev_warn(codec_dai->dev,
1935 "ASoC: Failed to set DAI format: %d\n", ret);
1940 /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
1941 if (cpu_dai->codec) {
1942 unsigned int inv_dai_fmt;
1944 inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1945 switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1946 case SND_SOC_DAIFMT_CBM_CFM:
1947 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1949 case SND_SOC_DAIFMT_CBM_CFS:
1950 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1952 case SND_SOC_DAIFMT_CBS_CFM:
1953 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1955 case SND_SOC_DAIFMT_CBS_CFS:
1956 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1960 dai_fmt = inv_dai_fmt;
1963 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1964 if (ret != 0 && ret != -ENOTSUPP) {
1965 dev_warn(cpu_dai->dev,
1966 "ASoC: Failed to set DAI format: %d\n", ret);
1972 EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1976 /* Trim special characters, and replace '-' with '_' since '-' is used to
1977 * separate different DMI fields in the card long name. Only number and
1978 * alphabet characters and a few separator characters are kept.
1980 static void cleanup_dmi_name(char *name)
1984 for (i = 0; name[i]; i++) {
1985 if (isalnum(name[i]) || (name[i] == '.')
1986 || (name[i] == '_'))
1987 name[j++] = name[i];
1988 else if (name[i] == '-')
1995 /* Check if a DMI field is valid, i.e. not containing any string
1996 * in the black list.
1998 static int is_dmi_valid(const char *field)
2002 while (dmi_blacklist[i]) {
2003 if (strstr(field, dmi_blacklist[i]))
2012 * snd_soc_set_dmi_name() - Register DMI names to card
2013 * @card: The card to register DMI names
2014 * @flavour: The flavour "differentiator" for the card amongst its peers.
2016 * An Intel machine driver may be used by many different devices but are
2017 * difficult for userspace to differentiate, since machine drivers ususally
2018 * use their own name as the card short name and leave the card long name
2019 * blank. To differentiate such devices and fix bugs due to lack of
2020 * device-specific configurations, this function allows DMI info to be used
2021 * as the sound card long name, in the format of
2022 * "vendor-product-version-board"
2023 * (Character '-' is used to separate different DMI fields here).
2024 * This will help the user space to load the device-specific Use Case Manager
2025 * (UCM) configurations for the card.
2027 * Possible card long names may be:
2028 * DellInc.-XPS139343-01-0310JH
2029 * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
2030 * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
2032 * This function also supports flavoring the card longname to provide
2033 * the extra differentiation, like "vendor-product-version-board-flavor".
2035 * We only keep number and alphabet characters and a few separator characters
2036 * in the card long name since UCM in the user space uses the card long names
2037 * as card configuration directory names and AudoConf cannot support special
2038 * charactors like SPACE.
2040 * Returns 0 on success, otherwise a negative error code.
2042 int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
2044 const char *vendor, *product, *product_version, *board;
2045 size_t longname_buf_size = sizeof(card->snd_card->longname);
2048 if (card->long_name)
2049 return 0; /* long name already set by driver or from DMI */
2051 /* make up dmi long name as: vendor.product.version.board */
2052 vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2053 if (!vendor || !is_dmi_valid(vendor)) {
2054 dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
2059 snprintf(card->dmi_longname, sizeof(card->snd_card->longname),
2061 cleanup_dmi_name(card->dmi_longname);
2063 product = dmi_get_system_info(DMI_PRODUCT_NAME);
2064 if (product && is_dmi_valid(product)) {
2065 len = strlen(card->dmi_longname);
2066 snprintf(card->dmi_longname + len,
2067 longname_buf_size - len,
2070 len++; /* skip the separator "-" */
2071 if (len < longname_buf_size)
2072 cleanup_dmi_name(card->dmi_longname + len);
2074 /* some vendors like Lenovo may only put a self-explanatory
2075 * name in the product version field
2077 product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
2078 if (product_version && is_dmi_valid(product_version)) {
2079 len = strlen(card->dmi_longname);
2080 snprintf(card->dmi_longname + len,
2081 longname_buf_size - len,
2082 "-%s", product_version);
2085 if (len < longname_buf_size)
2086 cleanup_dmi_name(card->dmi_longname + len);
2090 board = dmi_get_system_info(DMI_BOARD_NAME);
2091 if (board && is_dmi_valid(board)) {
2092 len = strlen(card->dmi_longname);
2093 snprintf(card->dmi_longname + len,
2094 longname_buf_size - len,
2098 if (len < longname_buf_size)
2099 cleanup_dmi_name(card->dmi_longname + len);
2100 } else if (!product) {
2101 /* fall back to using legacy name */
2102 dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
2106 /* Add flavour to dmi long name */
2108 len = strlen(card->dmi_longname);
2109 snprintf(card->dmi_longname + len,
2110 longname_buf_size - len,
2114 if (len < longname_buf_size)
2115 cleanup_dmi_name(card->dmi_longname + len);
2118 /* set the card long name */
2119 card->long_name = card->dmi_longname;
2123 EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
2124 #endif /* CONFIG_DMI */
2126 static int snd_soc_instantiate_card(struct snd_soc_card *card)
2128 struct snd_soc_codec *codec;
2129 struct snd_soc_pcm_runtime *rtd;
2130 struct snd_soc_dai_link *dai_link;
2133 mutex_lock(&client_mutex);
2134 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
2137 for (i = 0; i < card->num_links; i++) {
2138 ret = soc_bind_dai_link(card, &card->dai_link[i]);
2143 /* bind aux_devs too */
2144 for (i = 0; i < card->num_aux_devs; i++) {
2145 ret = soc_bind_aux_dev(card, i);
2150 /* add predefined DAI links to the list */
2151 for (i = 0; i < card->num_links; i++)
2152 snd_soc_add_dai_link(card, card->dai_link+i);
2154 /* initialize the register cache for each available codec */
2155 list_for_each_entry(codec, &codec_list, list) {
2156 if (codec->cache_init)
2158 ret = snd_soc_init_codec_cache(codec);
2163 /* card bind complete so register a sound card */
2164 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
2165 card->owner, 0, &card->snd_card);
2168 "ASoC: can't create sound card for card %s: %d\n",
2173 soc_init_card_debugfs(card);
2175 card->dapm.bias_level = SND_SOC_BIAS_OFF;
2176 card->dapm.dev = card->dev;
2177 card->dapm.card = card;
2178 list_add(&card->dapm.list, &card->dapm_list);
2180 #ifdef CONFIG_DEBUG_FS
2181 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
2184 #ifdef CONFIG_PM_SLEEP
2185 /* deferred resume work */
2186 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
2189 if (card->dapm_widgets)
2190 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
2191 card->num_dapm_widgets);
2193 if (card->of_dapm_widgets)
2194 snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
2195 card->num_of_dapm_widgets);
2197 /* initialise the sound card only once */
2199 ret = card->probe(card);
2201 goto card_probe_error;
2204 /* probe all components used by DAI links on this card */
2205 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2207 list_for_each_entry(rtd, &card->rtd_list, list) {
2208 ret = soc_probe_link_components(card, rtd, order);
2211 "ASoC: failed to instantiate card %d\n",
2218 /* probe auxiliary components */
2219 ret = soc_probe_aux_devices(card);
2223 /* Find new DAI links added during probing components and bind them.
2224 * Components with topology may bring new DAIs and DAI links.
2226 list_for_each_entry(dai_link, &card->dai_link_list, list) {
2227 if (soc_is_dai_link_bound(card, dai_link))
2230 ret = soc_init_dai_link(card, dai_link);
2233 ret = soc_bind_dai_link(card, dai_link);
2238 /* probe all DAI links on this card */
2239 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
2241 list_for_each_entry(rtd, &card->rtd_list, list) {
2242 ret = soc_probe_link_dais(card, rtd, order);
2245 "ASoC: failed to instantiate card %d\n",
2252 snd_soc_dapm_link_dai_widgets(card);
2253 snd_soc_dapm_connect_dai_link_widgets(card);
2256 snd_soc_add_card_controls(card, card->controls, card->num_controls);
2258 if (card->dapm_routes)
2259 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
2260 card->num_dapm_routes);
2262 if (card->of_dapm_routes)
2263 snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
2264 card->num_of_dapm_routes);
2266 /* try to set some sane longname if DMI is available */
2267 snd_soc_set_dmi_name(card, NULL);
2269 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
2271 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
2272 "%s", card->long_name ? card->long_name : card->name);
2273 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
2274 "%s", card->driver_name ? card->driver_name : card->name);
2275 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
2276 switch (card->snd_card->driver[i]) {
2282 if (!isalnum(card->snd_card->driver[i]))
2283 card->snd_card->driver[i] = '_';
2288 if (card->late_probe) {
2289 ret = card->late_probe(card);
2291 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
2293 goto probe_aux_dev_err;
2297 snd_soc_dapm_new_widgets(card);
2299 ret = snd_card_register(card->snd_card);
2301 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
2303 goto probe_aux_dev_err;
2306 card->instantiated = 1;
2307 snd_soc_dapm_sync(&card->dapm);
2308 mutex_unlock(&card->mutex);
2309 mutex_unlock(&client_mutex);
2314 soc_remove_aux_devices(card);
2317 soc_remove_dai_links(card);
2323 snd_soc_dapm_free(&card->dapm);
2324 soc_cleanup_card_debugfs(card);
2325 snd_card_free(card->snd_card);
2328 soc_remove_pcm_runtimes(card);
2329 mutex_unlock(&card->mutex);
2330 mutex_unlock(&client_mutex);
2335 /* probes a new socdev */
2336 static int soc_probe(struct platform_device *pdev)
2338 struct snd_soc_card *card = platform_get_drvdata(pdev);
2341 * no card, so machine driver should be registering card
2342 * we should not be here in that case so ret error
2347 dev_warn(&pdev->dev,
2348 "ASoC: machine %s should use snd_soc_register_card()\n",
2351 /* Bodge while we unpick instantiation */
2352 card->dev = &pdev->dev;
2354 return snd_soc_register_card(card);
2357 static int soc_cleanup_card_resources(struct snd_soc_card *card)
2359 struct snd_soc_pcm_runtime *rtd;
2361 /* make sure any delayed work runs */
2362 list_for_each_entry(rtd, &card->rtd_list, list)
2363 flush_delayed_work(&rtd->delayed_work);
2365 /* free the ALSA card at first; this syncs with pending operations */
2366 snd_card_free(card->snd_card);
2368 /* remove and free each DAI */
2369 soc_remove_dai_links(card);
2370 soc_remove_pcm_runtimes(card);
2372 /* remove auxiliary devices */
2373 soc_remove_aux_devices(card);
2375 snd_soc_dapm_free(&card->dapm);
2376 soc_cleanup_card_debugfs(card);
2378 /* remove the card */
2385 /* removes a socdev */
2386 static int soc_remove(struct platform_device *pdev)
2388 struct snd_soc_card *card = platform_get_drvdata(pdev);
2390 snd_soc_unregister_card(card);
2394 int snd_soc_poweroff(struct device *dev)
2396 struct snd_soc_card *card = dev_get_drvdata(dev);
2397 struct snd_soc_pcm_runtime *rtd;
2399 if (!card->instantiated)
2402 /* Flush out pmdown_time work - we actually do want to run it
2403 * now, we're shutting down so no imminent restart. */
2404 list_for_each_entry(rtd, &card->rtd_list, list)
2405 flush_delayed_work(&rtd->delayed_work);
2407 snd_soc_dapm_shutdown(card);
2409 /* deactivate pins to sleep state */
2410 list_for_each_entry(rtd, &card->rtd_list, list) {
2411 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2414 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2415 for (i = 0; i < rtd->num_codecs; i++) {
2416 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
2417 pinctrl_pm_select_sleep_state(codec_dai->dev);
2423 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
2425 const struct dev_pm_ops snd_soc_pm_ops = {
2426 .suspend = snd_soc_suspend,
2427 .resume = snd_soc_resume,
2428 .freeze = snd_soc_suspend,
2429 .thaw = snd_soc_resume,
2430 .poweroff = snd_soc_poweroff,
2431 .restore = snd_soc_resume,
2433 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
2435 /* ASoC platform driver */
2436 static struct platform_driver soc_driver = {
2438 .name = "soc-audio",
2439 .pm = &snd_soc_pm_ops,
2442 .remove = soc_remove,
2446 * snd_soc_cnew - create new control
2447 * @_template: control template
2448 * @data: control private data
2449 * @long_name: control long name
2450 * @prefix: control name prefix
2452 * Create a new mixer control from a template control.
2454 * Returns 0 for success, else error.
2456 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2457 void *data, const char *long_name,
2460 struct snd_kcontrol_new template;
2461 struct snd_kcontrol *kcontrol;
2464 memcpy(&template, _template, sizeof(template));
2468 long_name = template.name;
2471 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2475 template.name = name;
2477 template.name = long_name;
2480 kcontrol = snd_ctl_new1(&template, data);
2486 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2488 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2489 const struct snd_kcontrol_new *controls, int num_controls,
2490 const char *prefix, void *data)
2494 for (i = 0; i < num_controls; i++) {
2495 const struct snd_kcontrol_new *control = &controls[i];
2496 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2497 control->name, prefix));
2499 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2500 control->name, err);
2508 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2511 struct snd_card *card = soc_card->snd_card;
2512 struct snd_kcontrol *kctl;
2514 if (unlikely(!name))
2517 list_for_each_entry(kctl, &card->controls, list)
2518 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2522 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2525 * snd_soc_add_component_controls - Add an array of controls to a component.
2527 * @component: Component to add controls to
2528 * @controls: Array of controls to add
2529 * @num_controls: Number of elements in the array
2531 * Return: 0 for success, else error.
2533 int snd_soc_add_component_controls(struct snd_soc_component *component,
2534 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2536 struct snd_card *card = component->card->snd_card;
2538 return snd_soc_add_controls(card, component->dev, controls,
2539 num_controls, component->name_prefix, component);
2541 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
2544 * snd_soc_add_codec_controls - add an array of controls to a codec.
2545 * Convenience function to add a list of controls. Many codecs were
2546 * duplicating this code.
2548 * @codec: codec to add controls to
2549 * @controls: array of controls to add
2550 * @num_controls: number of elements in the array
2552 * Return 0 for success, else error.
2554 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2555 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2557 return snd_soc_add_component_controls(&codec->component, controls,
2560 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2563 * snd_soc_add_platform_controls - add an array of controls to a platform.
2564 * Convenience function to add a list of controls.
2566 * @platform: platform to add controls to
2567 * @controls: array of controls to add
2568 * @num_controls: number of elements in the array
2570 * Return 0 for success, else error.
2572 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2573 const struct snd_kcontrol_new *controls, unsigned int num_controls)
2575 return snd_soc_add_component_controls(&platform->component, controls,
2578 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2581 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2582 * Convenience function to add a list of controls.
2584 * @soc_card: SoC card to add controls to
2585 * @controls: array of controls to add
2586 * @num_controls: number of elements in the array
2588 * Return 0 for success, else error.
2590 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2591 const struct snd_kcontrol_new *controls, int num_controls)
2593 struct snd_card *card = soc_card->snd_card;
2595 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2598 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2601 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2602 * Convienience function to add a list of controls.
2604 * @dai: DAI to add controls to
2605 * @controls: array of controls to add
2606 * @num_controls: number of elements in the array
2608 * Return 0 for success, else error.
2610 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2611 const struct snd_kcontrol_new *controls, int num_controls)
2613 struct snd_card *card = dai->component->card->snd_card;
2615 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2618 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2621 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2623 * @clk_id: DAI specific clock ID
2624 * @freq: new clock frequency in Hz
2625 * @dir: new clock direction - input/output.
2627 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2629 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2630 unsigned int freq, int dir)
2632 if (dai->driver && dai->driver->ops->set_sysclk)
2633 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2634 else if (dai->codec && dai->codec->driver->set_sysclk)
2635 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2640 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2643 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2645 * @clk_id: DAI specific clock ID
2646 * @source: Source for the clock
2647 * @freq: new clock frequency in Hz
2648 * @dir: new clock direction - input/output.
2650 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2652 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2653 int source, unsigned int freq, int dir)
2655 if (codec->driver->set_sysclk)
2656 return codec->driver->set_sysclk(codec, clk_id, source,
2661 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2664 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2666 * @div_id: DAI specific clock divider ID
2667 * @div: new clock divisor.
2669 * Configures the clock dividers. This is used to derive the best DAI bit and
2670 * frame clocks from the system or master clock. It's best to set the DAI bit
2671 * and frame clocks as low as possible to save system power.
2673 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2674 int div_id, int div)
2676 if (dai->driver && dai->driver->ops->set_clkdiv)
2677 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2681 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2684 * snd_soc_dai_set_pll - configure DAI PLL.
2686 * @pll_id: DAI specific PLL ID
2687 * @source: DAI specific source for the PLL
2688 * @freq_in: PLL input clock frequency in Hz
2689 * @freq_out: requested PLL output clock frequency in Hz
2691 * Configures and enables PLL to generate output clock based on input clock.
2693 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2694 unsigned int freq_in, unsigned int freq_out)
2696 if (dai->driver && dai->driver->ops->set_pll)
2697 return dai->driver->ops->set_pll(dai, pll_id, source,
2699 else if (dai->codec && dai->codec->driver->set_pll)
2700 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2705 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2708 * snd_soc_codec_set_pll - configure codec PLL.
2710 * @pll_id: DAI specific PLL ID
2711 * @source: DAI specific source for the PLL
2712 * @freq_in: PLL input clock frequency in Hz
2713 * @freq_out: requested PLL output clock frequency in Hz
2715 * Configures and enables PLL to generate output clock based on input clock.
2717 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2718 unsigned int freq_in, unsigned int freq_out)
2720 if (codec->driver->set_pll)
2721 return codec->driver->set_pll(codec, pll_id, source,
2726 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2729 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
2731 * @ratio: Ratio of BCLK to Sample rate.
2733 * Configures the DAI for a preset BCLK to sample rate ratio.
2735 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2737 if (dai->driver && dai->driver->ops->set_bclk_ratio)
2738 return dai->driver->ops->set_bclk_ratio(dai, ratio);
2742 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
2745 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2747 * @fmt: SND_SOC_DAIFMT_ format value.
2749 * Configures the DAI hardware format and clocking.
2751 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2753 if (dai->driver == NULL)
2755 if (dai->driver->ops->set_fmt == NULL)
2757 return dai->driver->ops->set_fmt(dai, fmt);
2759 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2762 * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
2763 * @slots: Number of slots in use.
2764 * @tx_mask: bitmask representing active TX slots.
2765 * @rx_mask: bitmask representing active RX slots.
2767 * Generates the TDM tx and rx slot default masks for DAI.
2769 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2770 unsigned int *tx_mask,
2771 unsigned int *rx_mask)
2773 if (*tx_mask || *rx_mask)
2779 *tx_mask = (1 << slots) - 1;
2780 *rx_mask = (1 << slots) - 1;
2786 * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
2787 * @dai: The DAI to configure
2788 * @tx_mask: bitmask representing active TX slots.
2789 * @rx_mask: bitmask representing active RX slots.
2790 * @slots: Number of slots in use.
2791 * @slot_width: Width in bits for each slot.
2793 * This function configures the specified DAI for TDM operation. @slot contains
2794 * the total number of slots of the TDM stream and @slot_with the width of each
2795 * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
2796 * active slots of the TDM stream for the specified DAI, i.e. which slots the
2797 * DAI should write to or read from. If a bit is set the corresponding slot is
2798 * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
2799 * the first slot, bit 1 to the second slot and so on. The first active slot
2800 * maps to the first channel of the DAI, the second active slot to the second
2801 * channel and so on.
2803 * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
2804 * @rx_mask and @slot_width will be ignored.
2806 * Returns 0 on success, a negative error code otherwise.
2808 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2809 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2811 if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask)
2812 dai->driver->ops->xlate_tdm_slot_mask(slots,
2813 &tx_mask, &rx_mask);
2815 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
2817 dai->tx_mask = tx_mask;
2818 dai->rx_mask = rx_mask;
2820 if (dai->driver && dai->driver->ops->set_tdm_slot)
2821 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2826 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2829 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2831 * @tx_num: how many TX channels
2832 * @tx_slot: pointer to an array which imply the TX slot number channel
2834 * @rx_num: how many RX channels
2835 * @rx_slot: pointer to an array which imply the RX slot number channel
2838 * configure the relationship between channel number and TDM slot number.
2840 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2841 unsigned int tx_num, unsigned int *tx_slot,
2842 unsigned int rx_num, unsigned int *rx_slot)
2844 if (dai->driver && dai->driver->ops->set_channel_map)
2845 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2850 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2853 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2855 * @tristate: tristate enable
2857 * Tristates the DAI so that others can use it.
2859 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2861 if (dai->driver && dai->driver->ops->set_tristate)
2862 return dai->driver->ops->set_tristate(dai, tristate);
2866 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2869 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2871 * @mute: mute enable
2872 * @direction: stream to mute
2874 * Mutes the DAI DAC.
2876 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
2882 if (dai->driver->ops->mute_stream)
2883 return dai->driver->ops->mute_stream(dai, mute, direction);
2884 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
2885 dai->driver->ops->digital_mute)
2886 return dai->driver->ops->digital_mute(dai, mute);
2890 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2893 * snd_soc_register_card - Register a card with the ASoC core
2895 * @card: Card to register
2898 int snd_soc_register_card(struct snd_soc_card *card)
2901 struct snd_soc_pcm_runtime *rtd;
2903 if (!card->name || !card->dev)
2906 for (i = 0; i < card->num_links; i++) {
2907 struct snd_soc_dai_link *link = &card->dai_link[i];
2909 ret = soc_init_dai_link(card, link);
2911 dev_err(card->dev, "ASoC: failed to init link %s\n",
2917 dev_set_drvdata(card->dev, card);
2919 snd_soc_initialize_card_lists(card);
2921 INIT_LIST_HEAD(&card->dai_link_list);
2922 card->num_dai_links = 0;
2924 INIT_LIST_HEAD(&card->rtd_list);
2927 INIT_LIST_HEAD(&card->dapm_dirty);
2928 INIT_LIST_HEAD(&card->dobj_list);
2929 card->instantiated = 0;
2930 mutex_init(&card->mutex);
2931 mutex_init(&card->dapm_mutex);
2933 ret = snd_soc_instantiate_card(card);
2937 /* deactivate pins to sleep state */
2938 list_for_each_entry(rtd, &card->rtd_list, list) {
2939 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2942 for (j = 0; j < rtd->num_codecs; j++) {
2943 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
2944 if (!codec_dai->active)
2945 pinctrl_pm_select_sleep_state(codec_dai->dev);
2948 if (!cpu_dai->active)
2949 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2954 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2957 * snd_soc_unregister_card - Unregister a card with the ASoC core
2959 * @card: Card to unregister
2962 int snd_soc_unregister_card(struct snd_soc_card *card)
2964 if (card->instantiated) {
2965 card->instantiated = false;
2966 snd_soc_dapm_shutdown(card);
2967 soc_cleanup_card_resources(card);
2968 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2973 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2976 * Simplify DAI link configuration by removing ".-1" from device names
2977 * and sanitizing names.
2979 static char *fmt_single_name(struct device *dev, int *id)
2981 char *found, name[NAME_SIZE];
2984 if (dev_name(dev) == NULL)
2987 strlcpy(name, dev_name(dev), NAME_SIZE);
2989 /* are we a "%s.%d" name (platform and SPI components) */
2990 found = strstr(name, dev->driver->name);
2993 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2995 /* discard ID from name if ID == -1 */
2997 found[strlen(dev->driver->name)] = '\0';
3001 /* I2C component devices are named "bus-addr" */
3002 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3003 char tmp[NAME_SIZE];
3005 /* create unique ID number from I2C addr and bus */
3006 *id = ((id1 & 0xffff) << 16) + id2;
3008 /* sanitize component name for DAI link creation */
3009 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
3010 strlcpy(name, tmp, NAME_SIZE);
3015 return kstrdup(name, GFP_KERNEL);
3019 * Simplify DAI link naming for single devices with multiple DAIs by removing
3020 * any ".-1" and using the DAI name (instead of device name).
3022 static inline char *fmt_multiple_name(struct device *dev,
3023 struct snd_soc_dai_driver *dai_drv)
3025 if (dai_drv->name == NULL) {
3027 "ASoC: error - multiple DAI %s registered with no name\n",
3032 return kstrdup(dai_drv->name, GFP_KERNEL);
3036 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
3038 * @component: The component for which the DAIs should be unregistered
3040 static void snd_soc_unregister_dais(struct snd_soc_component *component)
3042 struct snd_soc_dai *dai, *_dai;
3044 list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
3045 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
3047 list_del(&dai->list);
3053 /* Create a DAI and add it to the component's DAI list */
3054 static struct snd_soc_dai *soc_add_dai(struct snd_soc_component *component,
3055 struct snd_soc_dai_driver *dai_drv,
3056 bool legacy_dai_naming)
3058 struct device *dev = component->dev;
3059 struct snd_soc_dai *dai;
3061 dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
3063 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3068 * Back in the old days when we still had component-less DAIs,
3069 * instead of having a static name, component-less DAIs would
3070 * inherit the name of the parent device so it is possible to
3071 * register multiple instances of the DAI. We still need to keep
3072 * the same naming style even though those DAIs are not
3073 * component-less anymore.
3075 if (legacy_dai_naming &&
3076 (dai_drv->id == 0 || dai_drv->name == NULL)) {
3077 dai->name = fmt_single_name(dev, &dai->id);
3079 dai->name = fmt_multiple_name(dev, dai_drv);
3081 dai->id = dai_drv->id;
3083 dai->id = component->num_dai;
3085 if (dai->name == NULL) {
3090 dai->component = component;
3092 dai->driver = dai_drv;
3093 if (!dai->driver->ops)
3094 dai->driver->ops = &null_dai_ops;
3096 list_add(&dai->list, &component->dai_list);
3097 component->num_dai++;
3099 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
3104 * snd_soc_register_dais - Register a DAI with the ASoC core
3106 * @component: The component the DAIs are registered for
3107 * @dai_drv: DAI driver to use for the DAIs
3108 * @count: Number of DAIs
3109 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3112 static int snd_soc_register_dais(struct snd_soc_component *component,
3113 struct snd_soc_dai_driver *dai_drv, size_t count,
3114 bool legacy_dai_naming)
3116 struct device *dev = component->dev;
3117 struct snd_soc_dai *dai;
3121 dev_dbg(dev, "ASoC: dai register %s #%zu\n", dev_name(dev), count);
3123 component->dai_drv = dai_drv;
3125 for (i = 0; i < count; i++) {
3127 dai = soc_add_dai(component, dai_drv + i,
3128 count == 1 && legacy_dai_naming);
3138 snd_soc_unregister_dais(component);
3144 * snd_soc_register_dai - Register a DAI dynamically & create its widgets
3146 * @component: The component the DAIs are registered for
3147 * @dai_drv: DAI driver to use for the DAI
3149 * Topology can use this API to register DAIs when probing a component.
3150 * These DAIs's widgets will be freed in the card cleanup and the DAIs
3151 * will be freed in the component cleanup.
3153 int snd_soc_register_dai(struct snd_soc_component *component,
3154 struct snd_soc_dai_driver *dai_drv)
3156 struct snd_soc_dapm_context *dapm =
3157 snd_soc_component_get_dapm(component);
3158 struct snd_soc_dai *dai;
3161 if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) {
3162 dev_err(component->dev, "Invalid dai type %d\n",
3163 dai_drv->dobj.type);
3167 lockdep_assert_held(&client_mutex);
3168 dai = soc_add_dai(component, dai_drv, false);
3172 /* Create the DAI widgets here. After adding DAIs, topology may
3173 * also add routes that need these widgets as source or sink.
3175 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
3177 dev_err(component->dev,
3178 "Failed to create DAI widgets %d\n", ret);
3183 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3185 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
3186 enum snd_soc_dapm_type type, int subseq)
3188 struct snd_soc_component *component = dapm->component;
3190 component->driver->seq_notifier(component, type, subseq);
3193 static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
3196 struct snd_soc_component *component = dapm->component;
3198 return component->driver->stream_event(component, event);
3201 static int snd_soc_component_initialize(struct snd_soc_component *component,
3202 const struct snd_soc_component_driver *driver, struct device *dev)
3204 struct snd_soc_dapm_context *dapm;
3206 component->name = fmt_single_name(dev, &component->id);
3207 if (!component->name) {
3208 dev_err(dev, "ASoC: Failed to allocate name\n");
3212 component->dev = dev;
3213 component->driver = driver;
3214 component->probe = component->driver->probe;
3215 component->remove = component->driver->remove;
3216 component->suspend = component->driver->suspend;
3217 component->resume = component->driver->resume;
3218 component->pcm_new = component->driver->pcm_new;
3219 component->pcm_free = component->driver->pcm_free;
3221 dapm = &component->dapm;
3223 dapm->component = component;
3224 dapm->bias_level = SND_SOC_BIAS_OFF;
3225 dapm->idle_bias_off = true;
3226 if (driver->seq_notifier)
3227 dapm->seq_notifier = snd_soc_component_seq_notifier;
3228 if (driver->stream_event)
3229 dapm->stream_event = snd_soc_component_stream_event;
3231 component->controls = driver->controls;
3232 component->num_controls = driver->num_controls;
3233 component->dapm_widgets = driver->dapm_widgets;
3234 component->num_dapm_widgets = driver->num_dapm_widgets;
3235 component->dapm_routes = driver->dapm_routes;
3236 component->num_dapm_routes = driver->num_dapm_routes;
3238 INIT_LIST_HEAD(&component->dai_list);
3239 mutex_init(&component->io_mutex);
3244 static void snd_soc_component_setup_regmap(struct snd_soc_component *component)
3246 int val_bytes = regmap_get_val_bytes(component->regmap);
3248 /* Errors are legitimate for non-integer byte multiples */
3250 component->val_bytes = val_bytes;
3253 #ifdef CONFIG_REGMAP
3256 * snd_soc_component_init_regmap() - Initialize regmap instance for the component
3257 * @component: The component for which to initialize the regmap instance
3258 * @regmap: The regmap instance that should be used by the component
3260 * This function allows deferred assignment of the regmap instance that is
3261 * associated with the component. Only use this if the regmap instance is not
3262 * yet ready when the component is registered. The function must also be called
3263 * before the first IO attempt of the component.
3265 void snd_soc_component_init_regmap(struct snd_soc_component *component,
3266 struct regmap *regmap)
3268 component->regmap = regmap;
3269 snd_soc_component_setup_regmap(component);
3271 EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
3274 * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component
3275 * @component: The component for which to de-initialize the regmap instance
3277 * Calls regmap_exit() on the regmap instance associated to the component and
3278 * removes the regmap instance from the component.
3280 * This function should only be used if snd_soc_component_init_regmap() was used
3281 * to initialize the regmap instance.
3283 void snd_soc_component_exit_regmap(struct snd_soc_component *component)
3285 regmap_exit(component->regmap);
3286 component->regmap = NULL;
3288 EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
3292 static void snd_soc_component_add_unlocked(struct snd_soc_component *component)
3294 if (!component->write && !component->read) {
3295 if (!component->regmap)
3296 component->regmap = dev_get_regmap(component->dev, NULL);
3297 if (component->regmap)
3298 snd_soc_component_setup_regmap(component);
3301 list_add(&component->list, &component_list);
3302 INIT_LIST_HEAD(&component->dobj_list);
3305 static void snd_soc_component_add(struct snd_soc_component *component)
3307 mutex_lock(&client_mutex);
3308 snd_soc_component_add_unlocked(component);
3309 mutex_unlock(&client_mutex);
3312 static void snd_soc_component_cleanup(struct snd_soc_component *component)
3314 snd_soc_unregister_dais(component);
3315 kfree(component->name);
3318 static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
3320 struct snd_soc_card *card = component->card;
3323 snd_soc_unregister_card(card);
3325 list_del(&component->list);
3328 int snd_soc_register_component(struct device *dev,
3329 const struct snd_soc_component_driver *component_driver,
3330 struct snd_soc_dai_driver *dai_drv,
3333 struct snd_soc_component *component;
3336 component = kzalloc(sizeof(*component), GFP_KERNEL);
3338 dev_err(dev, "ASoC: Failed to allocate memory\n");
3342 ret = snd_soc_component_initialize(component, component_driver, dev);
3346 component->ignore_pmdown_time = true;
3347 component->registered_as_component = true;
3349 ret = snd_soc_register_dais(component, dai_drv, num_dai, true);
3351 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3355 snd_soc_component_add(component);
3360 snd_soc_component_cleanup(component);
3365 EXPORT_SYMBOL_GPL(snd_soc_register_component);
3368 * snd_soc_unregister_component - Unregister a component from the ASoC core
3370 * @dev: The device to unregister
3372 void snd_soc_unregister_component(struct device *dev)
3374 struct snd_soc_component *component;
3377 mutex_lock(&client_mutex);
3378 list_for_each_entry(component, &component_list, list) {
3379 if (dev != component->dev ||
3380 !component->registered_as_component)
3383 snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
3384 snd_soc_component_del_unlocked(component);
3388 mutex_unlock(&client_mutex);
3391 snd_soc_component_cleanup(component);
3395 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3397 static int snd_soc_platform_drv_probe(struct snd_soc_component *component)
3399 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3401 return platform->driver->probe(platform);
3404 static void snd_soc_platform_drv_remove(struct snd_soc_component *component)
3406 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3408 platform->driver->remove(platform);
3411 static int snd_soc_platform_drv_pcm_new(struct snd_soc_pcm_runtime *rtd)
3413 struct snd_soc_platform *platform = rtd->platform;
3415 if (platform->driver->pcm_new)
3416 return platform->driver->pcm_new(rtd);
3421 static void snd_soc_platform_drv_pcm_free(struct snd_pcm *pcm)
3423 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
3424 struct snd_soc_platform *platform = rtd->platform;
3426 if (platform->driver->pcm_free)
3427 platform->driver->pcm_free(pcm);
3431 * snd_soc_add_platform - Add a platform to the ASoC core
3432 * @dev: The parent device for the platform
3433 * @platform: The platform to add
3434 * @platform_drv: The driver for the platform
3436 int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3437 const struct snd_soc_platform_driver *platform_drv)
3441 ret = snd_soc_component_initialize(&platform->component,
3442 &platform_drv->component_driver, dev);
3446 platform->dev = dev;
3447 platform->driver = platform_drv;
3449 if (platform_drv->probe)
3450 platform->component.probe = snd_soc_platform_drv_probe;
3451 if (platform_drv->remove)
3452 platform->component.remove = snd_soc_platform_drv_remove;
3453 if (platform_drv->pcm_new)
3454 platform->component.pcm_new = snd_soc_platform_drv_pcm_new;
3455 if (platform_drv->pcm_free)
3456 platform->component.pcm_free = snd_soc_platform_drv_pcm_free;
3458 #ifdef CONFIG_DEBUG_FS
3459 platform->component.debugfs_prefix = "platform";
3462 mutex_lock(&client_mutex);
3463 snd_soc_component_add_unlocked(&platform->component);
3464 list_add(&platform->list, &platform_list);
3465 mutex_unlock(&client_mutex);
3467 dev_dbg(dev, "ASoC: Registered platform '%s'\n",
3468 platform->component.name);
3472 EXPORT_SYMBOL_GPL(snd_soc_add_platform);
3475 * snd_soc_register_platform - Register a platform with the ASoC core
3477 * @dev: The device for the platform
3478 * @platform_drv: The driver for the platform
3480 int snd_soc_register_platform(struct device *dev,
3481 const struct snd_soc_platform_driver *platform_drv)
3483 struct snd_soc_platform *platform;
3486 dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
3488 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3489 if (platform == NULL)
3492 ret = snd_soc_add_platform(dev, platform, platform_drv);
3498 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3501 * snd_soc_remove_platform - Remove a platform from the ASoC core
3502 * @platform: the platform to remove
3504 void snd_soc_remove_platform(struct snd_soc_platform *platform)
3507 mutex_lock(&client_mutex);
3508 list_del(&platform->list);
3509 snd_soc_component_del_unlocked(&platform->component);
3510 mutex_unlock(&client_mutex);
3512 dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
3513 platform->component.name);
3515 snd_soc_component_cleanup(&platform->component);
3517 EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
3519 struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
3521 struct snd_soc_platform *platform;
3523 mutex_lock(&client_mutex);
3524 list_for_each_entry(platform, &platform_list, list) {
3525 if (dev == platform->dev) {
3526 mutex_unlock(&client_mutex);
3530 mutex_unlock(&client_mutex);
3534 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
3537 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3539 * @dev: platform to unregister
3541 void snd_soc_unregister_platform(struct device *dev)
3543 struct snd_soc_platform *platform;
3545 platform = snd_soc_lookup_platform(dev);
3549 snd_soc_remove_platform(platform);
3552 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3554 static u64 codec_format_map[] = {
3555 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3556 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3557 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3558 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3559 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3560 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3561 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3562 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3563 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3564 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3565 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3566 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3567 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3568 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3569 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3570 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3573 /* Fix up the DAI formats for endianness: codecs don't actually see
3574 * the endianness of the data but we're using the CPU format
3575 * definitions which do need to include endianness so we ensure that
3576 * codec DAIs always have both big and little endian variants set.
3578 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3582 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3583 if (stream->formats & codec_format_map[i])
3584 stream->formats |= codec_format_map[i];
3587 static int snd_soc_codec_drv_probe(struct snd_soc_component *component)
3589 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3591 return codec->driver->probe(codec);
3594 static void snd_soc_codec_drv_remove(struct snd_soc_component *component)
3596 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3598 codec->driver->remove(codec);
3601 static int snd_soc_codec_drv_suspend(struct snd_soc_component *component)
3603 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3605 return codec->driver->suspend(codec);
3608 static int snd_soc_codec_drv_resume(struct snd_soc_component *component)
3610 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3612 return codec->driver->resume(codec);
3615 static int snd_soc_codec_drv_write(struct snd_soc_component *component,
3616 unsigned int reg, unsigned int val)
3618 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3620 return codec->driver->write(codec, reg, val);
3623 static int snd_soc_codec_drv_read(struct snd_soc_component *component,
3624 unsigned int reg, unsigned int *val)
3626 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
3628 *val = codec->driver->read(codec, reg);
3633 static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm,
3634 enum snd_soc_bias_level level)
3636 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
3638 return codec->driver->set_bias_level(codec, level);
3642 * snd_soc_register_codec - Register a codec with the ASoC core
3644 * @dev: The parent device for this codec
3645 * @codec_drv: Codec driver
3646 * @dai_drv: The associated DAI driver
3647 * @num_dai: Number of DAIs
3649 int snd_soc_register_codec(struct device *dev,
3650 const struct snd_soc_codec_driver *codec_drv,
3651 struct snd_soc_dai_driver *dai_drv,
3654 struct snd_soc_dapm_context *dapm;
3655 struct snd_soc_codec *codec;
3656 struct snd_soc_dai *dai;
3659 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3661 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3665 codec->component.codec = codec;
3667 ret = snd_soc_component_initialize(&codec->component,
3668 &codec_drv->component_driver, dev);
3672 if (codec_drv->probe)
3673 codec->component.probe = snd_soc_codec_drv_probe;
3674 if (codec_drv->remove)
3675 codec->component.remove = snd_soc_codec_drv_remove;
3676 if (codec_drv->suspend)
3677 codec->component.suspend = snd_soc_codec_drv_suspend;
3678 if (codec_drv->resume)
3679 codec->component.resume = snd_soc_codec_drv_resume;
3680 if (codec_drv->write)
3681 codec->component.write = snd_soc_codec_drv_write;
3682 if (codec_drv->read)
3683 codec->component.read = snd_soc_codec_drv_read;
3684 codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
3686 dapm = snd_soc_codec_get_dapm(codec);
3687 dapm->idle_bias_off = codec_drv->idle_bias_off;
3688 dapm->suspend_bias_off = codec_drv->suspend_bias_off;
3689 if (codec_drv->seq_notifier)
3690 dapm->seq_notifier = codec_drv->seq_notifier;
3691 if (codec_drv->set_bias_level)
3692 dapm->set_bias_level = snd_soc_codec_set_bias_level;
3694 codec->driver = codec_drv;
3695 codec->component.val_bytes = codec_drv->reg_word_size;
3697 #ifdef CONFIG_DEBUG_FS
3698 codec->component.init_debugfs = soc_init_codec_debugfs;
3699 codec->component.debugfs_prefix = "codec";
3702 if (codec_drv->get_regmap)
3703 codec->component.regmap = codec_drv->get_regmap(dev);
3705 for (i = 0; i < num_dai; i++) {
3706 fixup_codec_formats(&dai_drv[i].playback);
3707 fixup_codec_formats(&dai_drv[i].capture);
3710 ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);
3712 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3716 list_for_each_entry(dai, &codec->component.dai_list, list)
3719 mutex_lock(&client_mutex);
3720 snd_soc_component_add_unlocked(&codec->component);
3721 list_add(&codec->list, &codec_list);
3722 mutex_unlock(&client_mutex);
3724 dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n",
3725 codec->component.name);
3729 snd_soc_component_cleanup(&codec->component);
3734 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3737 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3739 * @dev: codec to unregister
3741 void snd_soc_unregister_codec(struct device *dev)
3743 struct snd_soc_codec *codec;
3745 mutex_lock(&client_mutex);
3746 list_for_each_entry(codec, &codec_list, list) {
3747 if (dev == codec->dev)
3750 mutex_unlock(&client_mutex);
3754 list_del(&codec->list);
3755 snd_soc_component_del_unlocked(&codec->component);
3756 mutex_unlock(&client_mutex);
3758 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n",
3759 codec->component.name);
3761 snd_soc_component_cleanup(&codec->component);
3762 snd_soc_cache_exit(codec);
3765 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3767 /* Retrieve a card's name from device tree */
3768 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3769 const char *propname)
3771 struct device_node *np;
3775 pr_err("card->dev is not set before calling %s\n", __func__);
3779 np = card->dev->of_node;
3781 ret = of_property_read_string_index(np, propname, 0, &card->name);
3783 * EINVAL means the property does not exist. This is fine providing
3784 * card->name was previously set, which is checked later in
3785 * snd_soc_register_card.
3787 if (ret < 0 && ret != -EINVAL) {
3789 "ASoC: Property '%s' could not be read: %d\n",
3796 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3798 static const struct snd_soc_dapm_widget simple_widgets[] = {
3799 SND_SOC_DAPM_MIC("Microphone", NULL),
3800 SND_SOC_DAPM_LINE("Line", NULL),
3801 SND_SOC_DAPM_HP("Headphone", NULL),
3802 SND_SOC_DAPM_SPK("Speaker", NULL),
3805 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
3806 const char *propname)
3808 struct device_node *np = card->dev->of_node;
3809 struct snd_soc_dapm_widget *widgets;
3810 const char *template, *wname;
3811 int i, j, num_widgets, ret;
3813 num_widgets = of_property_count_strings(np, propname);
3814 if (num_widgets < 0) {
3816 "ASoC: Property '%s' does not exist\n", propname);
3819 if (num_widgets & 1) {
3821 "ASoC: Property '%s' length is not even\n", propname);
3827 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
3832 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
3836 "ASoC: Could not allocate memory for widgets\n");
3840 for (i = 0; i < num_widgets; i++) {
3841 ret = of_property_read_string_index(np, propname,
3845 "ASoC: Property '%s' index %d read error:%d\n",
3846 propname, 2 * i, ret);
3850 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
3851 if (!strncmp(template, simple_widgets[j].name,
3852 strlen(simple_widgets[j].name))) {
3853 widgets[i] = simple_widgets[j];
3858 if (j >= ARRAY_SIZE(simple_widgets)) {
3860 "ASoC: DAPM widget '%s' is not supported\n",
3865 ret = of_property_read_string_index(np, propname,
3870 "ASoC: Property '%s' index %d read error:%d\n",
3871 propname, (2 * i) + 1, ret);
3875 widgets[i].name = wname;
3878 card->of_dapm_widgets = widgets;
3879 card->num_of_dapm_widgets = num_widgets;
3883 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
3885 static int snd_soc_of_get_slot_mask(struct device_node *np,
3886 const char *prop_name,
3890 const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
3896 for (i = 0; i < val; i++)
3897 if (be32_to_cpup(&of_slot_mask[i]))
3903 int snd_soc_of_parse_tdm_slot(struct device_node *np,
3904 unsigned int *tx_mask,
3905 unsigned int *rx_mask,
3906 unsigned int *slots,
3907 unsigned int *slot_width)
3913 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
3915 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
3917 if (of_property_read_bool(np, "dai-tdm-slot-num")) {
3918 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
3926 if (of_property_read_bool(np, "dai-tdm-slot-width")) {
3927 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
3937 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
3939 void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
3940 struct snd_soc_codec_conf *codec_conf,
3941 struct device_node *of_node,
3942 const char *propname)
3944 struct device_node *np = card->dev->of_node;
3948 ret = of_property_read_string(np, propname, &str);
3950 /* no prefix is not error */
3954 codec_conf->of_node = of_node;
3955 codec_conf->name_prefix = str;
3957 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_prefix);
3959 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3960 const char *propname)
3962 struct device_node *np = card->dev->of_node;
3964 struct snd_soc_dapm_route *routes;
3967 num_routes = of_property_count_strings(np, propname);
3968 if (num_routes < 0 || num_routes & 1) {
3970 "ASoC: Property '%s' does not exist or its length is not even\n",
3976 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
3981 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3985 "ASoC: Could not allocate DAPM route table\n");
3989 for (i = 0; i < num_routes; i++) {
3990 ret = of_property_read_string_index(np, propname,
3991 2 * i, &routes[i].sink);
3994 "ASoC: Property '%s' index %d could not be read: %d\n",
3995 propname, 2 * i, ret);
3998 ret = of_property_read_string_index(np, propname,
3999 (2 * i) + 1, &routes[i].source);
4002 "ASoC: Property '%s' index %d could not be read: %d\n",
4003 propname, (2 * i) + 1, ret);
4008 card->num_of_dapm_routes = num_routes;
4009 card->of_dapm_routes = routes;
4013 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4015 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4017 struct device_node **bitclkmaster,
4018 struct device_node **framemaster)
4022 unsigned int format = 0;
4028 } of_fmt_table[] = {
4029 { "i2s", SND_SOC_DAIFMT_I2S },
4030 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
4031 { "left_j", SND_SOC_DAIFMT_LEFT_J },
4032 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
4033 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
4034 { "ac97", SND_SOC_DAIFMT_AC97 },
4035 { "pdm", SND_SOC_DAIFMT_PDM},
4036 { "msb", SND_SOC_DAIFMT_MSB },
4037 { "lsb", SND_SOC_DAIFMT_LSB },
4044 * check "dai-format = xxx"
4045 * or "[prefix]format = xxx"
4046 * SND_SOC_DAIFMT_FORMAT_MASK area
4048 ret = of_property_read_string(np, "dai-format", &str);
4050 snprintf(prop, sizeof(prop), "%sformat", prefix);
4051 ret = of_property_read_string(np, prop, &str);
4054 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
4055 if (strcmp(str, of_fmt_table[i].name) == 0) {
4056 format |= of_fmt_table[i].val;
4063 * check "[prefix]continuous-clock"
4064 * SND_SOC_DAIFMT_CLOCK_MASK area
4066 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
4067 if (of_property_read_bool(np, prop))
4068 format |= SND_SOC_DAIFMT_CONT;
4070 format |= SND_SOC_DAIFMT_GATED;
4073 * check "[prefix]bitclock-inversion"
4074 * check "[prefix]frame-inversion"
4075 * SND_SOC_DAIFMT_INV_MASK area
4077 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
4078 bit = !!of_get_property(np, prop, NULL);
4080 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
4081 frame = !!of_get_property(np, prop, NULL);
4083 switch ((bit << 4) + frame) {
4085 format |= SND_SOC_DAIFMT_IB_IF;
4088 format |= SND_SOC_DAIFMT_IB_NF;
4091 format |= SND_SOC_DAIFMT_NB_IF;
4094 /* SND_SOC_DAIFMT_NB_NF is default */
4099 * check "[prefix]bitclock-master"
4100 * check "[prefix]frame-master"
4101 * SND_SOC_DAIFMT_MASTER_MASK area
4103 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
4104 bit = !!of_get_property(np, prop, NULL);
4105 if (bit && bitclkmaster)
4106 *bitclkmaster = of_parse_phandle(np, prop, 0);
4108 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
4109 frame = !!of_get_property(np, prop, NULL);
4110 if (frame && framemaster)
4111 *framemaster = of_parse_phandle(np, prop, 0);
4113 switch ((bit << 4) + frame) {
4115 format |= SND_SOC_DAIFMT_CBM_CFM;
4118 format |= SND_SOC_DAIFMT_CBM_CFS;
4121 format |= SND_SOC_DAIFMT_CBS_CFM;
4124 format |= SND_SOC_DAIFMT_CBS_CFS;
4130 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4132 int snd_soc_get_dai_id(struct device_node *ep)
4134 struct snd_soc_component *pos;
4135 struct device_node *node;
4138 node = of_graph_get_port_parent(ep);
4141 * For example HDMI case, HDMI has video/sound port,
4142 * but ALSA SoC needs sound port number only.
4143 * Thus counting HDMI DT port/endpoint doesn't work.
4144 * Then, it should have .of_xlate_dai_id
4147 mutex_lock(&client_mutex);
4148 list_for_each_entry(pos, &component_list, list) {
4149 struct device_node *component_of_node = pos->dev->of_node;
4151 if (!component_of_node && pos->dev->parent)
4152 component_of_node = pos->dev->parent->of_node;
4154 if (component_of_node != node)
4157 if (pos->driver->of_xlate_dai_id)
4158 ret = pos->driver->of_xlate_dai_id(pos, ep);
4162 mutex_unlock(&client_mutex);
4166 EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
4168 int snd_soc_get_dai_name(struct of_phandle_args *args,
4169 const char **dai_name)
4171 struct snd_soc_component *pos;
4172 struct device_node *component_of_node;
4173 int ret = -EPROBE_DEFER;
4175 mutex_lock(&client_mutex);
4176 list_for_each_entry(pos, &component_list, list) {
4177 component_of_node = pos->dev->of_node;
4178 if (!component_of_node && pos->dev->parent)
4179 component_of_node = pos->dev->parent->of_node;
4181 if (component_of_node != args->np)
4184 if (pos->driver->of_xlate_dai_name) {
4185 ret = pos->driver->of_xlate_dai_name(pos,
4191 switch (args->args_count) {
4193 id = 0; /* same as dai_drv[0] */
4203 if (id < 0 || id >= pos->num_dai) {
4210 *dai_name = pos->dai_drv[id].name;
4212 *dai_name = pos->name;
4217 mutex_unlock(&client_mutex);
4220 EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
4222 int snd_soc_of_get_dai_name(struct device_node *of_node,
4223 const char **dai_name)
4225 struct of_phandle_args args;
4228 ret = of_parse_phandle_with_args(of_node, "sound-dai",
4229 "#sound-dai-cells", 0, &args);
4233 ret = snd_soc_get_dai_name(&args, dai_name);
4235 of_node_put(args.np);
4239 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
4242 * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
4244 * @of_node: Device node
4245 * @dai_link: DAI link
4247 * Builds an array of CODEC DAI components from the DAI link property
4249 * The array is set in the DAI link and the number of DAIs is set accordingly.
4250 * The device nodes in the array (of_node) must be dereferenced by the caller.
4252 * Returns 0 for success
4254 int snd_soc_of_get_dai_link_codecs(struct device *dev,
4255 struct device_node *of_node,
4256 struct snd_soc_dai_link *dai_link)
4258 struct of_phandle_args args;
4259 struct snd_soc_dai_link_component *component;
4261 int index, num_codecs, ret;
4263 /* Count the number of CODECs */
4265 num_codecs = of_count_phandle_with_args(of_node, name,
4266 "#sound-dai-cells");
4267 if (num_codecs <= 0) {
4268 if (num_codecs == -ENOENT)
4269 dev_err(dev, "No 'sound-dai' property\n");
4271 dev_err(dev, "Bad phandle in 'sound-dai'\n");
4274 component = devm_kzalloc(dev,
4275 sizeof *component * num_codecs,
4279 dai_link->codecs = component;
4280 dai_link->num_codecs = num_codecs;
4282 /* Parse the list */
4283 for (index = 0, component = dai_link->codecs;
4284 index < dai_link->num_codecs;
4285 index++, component++) {
4286 ret = of_parse_phandle_with_args(of_node, name,
4291 component->of_node = args.np;
4292 ret = snd_soc_get_dai_name(&args, &component->dai_name);
4298 for (index = 0, component = dai_link->codecs;
4299 index < dai_link->num_codecs;
4300 index++, component++) {
4301 if (!component->of_node)
4303 of_node_put(component->of_node);
4304 component->of_node = NULL;
4306 dai_link->codecs = NULL;
4307 dai_link->num_codecs = 0;
4310 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
4312 static int __init snd_soc_init(void)
4314 snd_soc_debugfs_init();
4315 snd_soc_util_init();
4317 return platform_driver_register(&soc_driver);
4319 module_init(snd_soc_init);
4321 static void __exit snd_soc_exit(void)
4323 snd_soc_util_exit();
4324 snd_soc_debugfs_exit();
4326 platform_driver_unregister(&soc_driver);
4328 module_exit(snd_soc_exit);
4330 /* Module information */
4331 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4332 MODULE_DESCRIPTION("ALSA SoC Core");
4333 MODULE_LICENSE("GPL");
4334 MODULE_ALIAS("platform:soc-audio");