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/ctype.h>
34 #include <linux/slab.h>
36 #include <sound/ac97_codec.h>
37 #include <sound/core.h>
38 #include <sound/jack.h>
39 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/soc.h>
42 #include <sound/soc-dpcm.h>
43 #include <sound/initval.h>
45 #define CREATE_TRACE_POINTS
46 #include <trace/events/asoc.h>
50 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
52 #ifdef CONFIG_DEBUG_FS
53 struct dentry *snd_soc_debugfs_root;
54 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
57 static DEFINE_MUTEX(client_mutex);
58 static LIST_HEAD(dai_list);
59 static LIST_HEAD(platform_list);
60 static LIST_HEAD(codec_list);
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
67 static int pmdown_time = 5000;
68 module_param(pmdown_time, int, 0);
69 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71 /* returns the minimum number of bytes needed to represent
72 * a particular given value */
73 static int min_bytes_needed(unsigned long val)
78 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
81 c = (sizeof val * 8) - c;
89 /* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91 static int format_register_str(struct snd_soc_codec *codec,
92 unsigned int reg, char *buf, size_t len)
94 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
95 int regsize = codec->driver->reg_word_size * 2;
98 char regbuf[regsize + 1];
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize + regsize + 2 + 1 != len)
108 ret = snd_soc_read(codec, reg);
110 memset(regbuf, 'X', regsize);
111 regbuf[regsize] = '\0';
113 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
116 /* prepare the buffer */
117 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf, tmpbuf, len);
124 /* codec register dump */
125 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
126 size_t count, loff_t pos)
129 int wordsize, regsize;
134 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
135 regsize = codec->driver->reg_word_size * 2;
137 len = wordsize + regsize + 2 + 1;
139 if (!codec->driver->reg_cache_size)
142 if (codec->driver->reg_cache_step)
143 step = codec->driver->reg_cache_step;
145 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
146 if (!snd_soc_codec_readable_register(codec, i))
148 if (codec->driver->display_register) {
149 count += codec->driver->display_register(codec, buf + count,
150 PAGE_SIZE - count, i);
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);
164 total = min(total, count - 1);
169 static ssize_t codec_reg_show(struct device *dev,
170 struct device_attribute *attr, char *buf)
172 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
174 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
177 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
179 static ssize_t pmdown_time_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
182 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
184 return sprintf(buf, "%ld\n", rtd->pmdown_time);
187 static ssize_t pmdown_time_set(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
191 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
194 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
201 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
203 #ifdef CONFIG_DEBUG_FS
204 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
205 size_t count, loff_t *ppos)
208 struct snd_soc_codec *codec = file->private_data;
211 if (*ppos < 0 || !count)
214 buf = kmalloc(count, GFP_KERNEL);
218 ret = soc_codec_reg_show(codec, buf, count, *ppos);
220 if (copy_to_user(user_buf, buf, ret)) {
231 static ssize_t codec_reg_write_file(struct file *file,
232 const char __user *user_buf, size_t count, loff_t *ppos)
237 unsigned long reg, value;
238 struct snd_soc_codec *codec = file->private_data;
240 buf_size = min(count, (sizeof(buf)-1));
241 if (copy_from_user(buf, user_buf, buf_size))
245 while (*start == ' ')
247 reg = simple_strtoul(start, &start, 16);
248 while (*start == ' ')
250 if (strict_strtoul(start, 16, &value))
253 /* Userspace has been fiddling around behind the kernel's back */
254 add_taint(TAINT_USER);
256 snd_soc_write(codec, reg, value);
260 static const struct file_operations codec_reg_fops = {
262 .read = codec_reg_read_file,
263 .write = codec_reg_write_file,
264 .llseek = default_llseek,
267 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
269 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
271 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
273 if (!codec->debugfs_codec_root) {
274 dev_warn(codec->dev, "Failed to create codec debugfs directory\n");
278 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
280 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
283 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
284 codec->debugfs_codec_root,
285 codec, &codec_reg_fops);
286 if (!codec->debugfs_reg)
287 dev_warn(codec->dev, "Failed to create codec register debugfs file\n");
289 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
292 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
294 debugfs_remove_recursive(codec->debugfs_codec_root);
297 static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
299 struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
301 platform->debugfs_platform_root = debugfs_create_dir(platform->name,
303 if (!platform->debugfs_platform_root) {
304 dev_warn(platform->dev,
305 "Failed to create platform debugfs directory\n");
309 snd_soc_dapm_debugfs_init(&platform->dapm,
310 platform->debugfs_platform_root);
313 static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
315 debugfs_remove_recursive(platform->debugfs_platform_root);
318 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
319 size_t count, loff_t *ppos)
321 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
322 ssize_t len, ret = 0;
323 struct snd_soc_codec *codec;
328 list_for_each_entry(codec, &codec_list, list) {
329 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
333 if (ret > PAGE_SIZE) {
340 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
347 static const struct file_operations codec_list_fops = {
348 .read = codec_list_read_file,
349 .llseek = default_llseek,/* read accesses f_pos */
352 static ssize_t dai_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_dai *dai;
362 list_for_each_entry(dai, &dai_list, list) {
363 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
366 if (ret > PAGE_SIZE) {
372 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
379 static const struct file_operations dai_list_fops = {
380 .read = dai_list_read_file,
381 .llseek = default_llseek,/* read accesses f_pos */
384 static ssize_t platform_list_read_file(struct file *file,
385 char __user *user_buf,
386 size_t count, loff_t *ppos)
388 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
389 ssize_t len, ret = 0;
390 struct snd_soc_platform *platform;
395 list_for_each_entry(platform, &platform_list, list) {
396 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
400 if (ret > PAGE_SIZE) {
406 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
413 static const struct file_operations platform_list_fops = {
414 .read = platform_list_read_file,
415 .llseek = default_llseek,/* read accesses f_pos */
418 static void soc_init_card_debugfs(struct snd_soc_card *card)
420 card->debugfs_card_root = debugfs_create_dir(card->name,
421 snd_soc_debugfs_root);
422 if (!card->debugfs_card_root) {
424 "ASoC: Failed to create card debugfs directory\n");
428 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
429 card->debugfs_card_root,
431 if (!card->debugfs_pop_time)
433 "Failed to create pop time debugfs file\n");
436 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
438 debugfs_remove_recursive(card->debugfs_card_root);
443 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
447 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
451 static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
455 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
459 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
463 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
468 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
469 const char *dai_link, int stream)
473 for (i = 0; i < card->num_links; i++) {
474 if (card->rtd[i].dai_link->no_pcm &&
475 !strcmp(card->rtd[i].dai_link->name, dai_link))
476 return card->rtd[i].pcm->streams[stream].substream;
478 dev_dbg(card->dev, "failed to find dai link %s\n", dai_link);
481 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
483 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
484 const char *dai_link)
488 for (i = 0; i < card->num_links; i++) {
489 if (!strcmp(card->rtd[i].dai_link->name, dai_link))
490 return &card->rtd[i];
492 dev_dbg(card->dev, "failed to find rtd %s\n", dai_link);
495 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
497 #ifdef CONFIG_SND_SOC_AC97_BUS
498 /* unregister ac97 codec */
499 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
501 if (codec->ac97->dev.bus)
502 device_unregister(&codec->ac97->dev);
506 /* stop no dev release warning */
507 static void soc_ac97_device_release(struct device *dev){}
509 /* register ac97 codec to bus */
510 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
514 codec->ac97->dev.bus = &ac97_bus_type;
515 codec->ac97->dev.parent = codec->card->dev;
516 codec->ac97->dev.release = soc_ac97_device_release;
518 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
519 codec->card->snd_card->number, 0, codec->name);
520 err = device_register(&codec->ac97->dev);
522 snd_printk(KERN_ERR "Can't register ac97 bus\n");
523 codec->ac97->dev.bus = NULL;
530 #ifdef CONFIG_PM_SLEEP
531 /* powers down audio subsystem for suspend */
532 int snd_soc_suspend(struct device *dev)
534 struct snd_soc_card *card = dev_get_drvdata(dev);
535 struct snd_soc_codec *codec;
538 /* If the initialization of this soc device failed, there is no codec
539 * associated with it. Just bail out in this case.
541 if (list_empty(&card->codec_dev_list))
544 /* Due to the resume being scheduled into a workqueue we could
545 * suspend before that's finished - wait for it to complete.
547 snd_power_lock(card->snd_card);
548 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
549 snd_power_unlock(card->snd_card);
551 /* we're going to block userspace touching us until resume completes */
552 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
554 /* mute any active DACs */
555 for (i = 0; i < card->num_rtd; i++) {
556 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
557 struct snd_soc_dai_driver *drv = dai->driver;
559 if (card->rtd[i].dai_link->ignore_suspend)
562 if (drv->ops->digital_mute && dai->playback_active)
563 drv->ops->digital_mute(dai, 1);
566 /* suspend all pcms */
567 for (i = 0; i < card->num_rtd; i++) {
568 if (card->rtd[i].dai_link->ignore_suspend)
571 snd_pcm_suspend_all(card->rtd[i].pcm);
574 if (card->suspend_pre)
575 card->suspend_pre(card);
577 for (i = 0; i < card->num_rtd; i++) {
578 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
579 struct snd_soc_platform *platform = card->rtd[i].platform;
581 if (card->rtd[i].dai_link->ignore_suspend)
584 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
585 cpu_dai->driver->suspend(cpu_dai);
586 if (platform->driver->suspend && !platform->suspended) {
587 platform->driver->suspend(cpu_dai);
588 platform->suspended = 1;
592 /* close any waiting streams and save state */
593 for (i = 0; i < card->num_rtd; i++) {
594 flush_delayed_work_sync(&card->rtd[i].delayed_work);
595 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
598 for (i = 0; i < card->num_rtd; i++) {
600 if (card->rtd[i].dai_link->ignore_suspend)
603 snd_soc_dapm_stream_event(&card->rtd[i],
604 SNDRV_PCM_STREAM_PLAYBACK,
605 SND_SOC_DAPM_STREAM_SUSPEND);
607 snd_soc_dapm_stream_event(&card->rtd[i],
608 SNDRV_PCM_STREAM_CAPTURE,
609 SND_SOC_DAPM_STREAM_SUSPEND);
612 /* Recheck all analogue paths too */
613 dapm_mark_io_dirty(&card->dapm);
614 snd_soc_dapm_sync(&card->dapm);
616 /* suspend all CODECs */
617 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
618 /* If there are paths active then the CODEC will be held with
619 * bias _ON and should not be suspended. */
620 if (!codec->suspended && codec->driver->suspend) {
621 switch (codec->dapm.bias_level) {
622 case SND_SOC_BIAS_STANDBY:
624 * If the CODEC is capable of idle
625 * bias off then being in STANDBY
626 * means it's doing something,
627 * otherwise fall through.
629 if (codec->dapm.idle_bias_off) {
631 "idle_bias_off CODEC on over suspend\n");
634 case SND_SOC_BIAS_OFF:
635 codec->driver->suspend(codec);
636 codec->suspended = 1;
637 codec->cache_sync = 1;
640 dev_dbg(codec->dev, "CODEC is on over suspend\n");
646 for (i = 0; i < card->num_rtd; i++) {
647 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
649 if (card->rtd[i].dai_link->ignore_suspend)
652 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
653 cpu_dai->driver->suspend(cpu_dai);
656 if (card->suspend_post)
657 card->suspend_post(card);
661 EXPORT_SYMBOL_GPL(snd_soc_suspend);
663 /* deferred resume work, so resume can complete before we finished
664 * setting our codec back up, which can be very slow on I2C
666 static void soc_resume_deferred(struct work_struct *work)
668 struct snd_soc_card *card =
669 container_of(work, struct snd_soc_card, deferred_resume_work);
670 struct snd_soc_codec *codec;
673 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
674 * so userspace apps are blocked from touching us
677 dev_dbg(card->dev, "starting resume work\n");
679 /* Bring us up into D2 so that DAPM starts enabling things */
680 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
682 if (card->resume_pre)
683 card->resume_pre(card);
685 /* resume AC97 DAIs */
686 for (i = 0; i < card->num_rtd; i++) {
687 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
689 if (card->rtd[i].dai_link->ignore_suspend)
692 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
693 cpu_dai->driver->resume(cpu_dai);
696 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
697 /* If the CODEC was idle over suspend then it will have been
698 * left with bias OFF or STANDBY and suspended so we must now
699 * resume. Otherwise the suspend was suppressed.
701 if (codec->driver->resume && codec->suspended) {
702 switch (codec->dapm.bias_level) {
703 case SND_SOC_BIAS_STANDBY:
704 case SND_SOC_BIAS_OFF:
705 codec->driver->resume(codec);
706 codec->suspended = 0;
709 dev_dbg(codec->dev, "CODEC was on over suspend\n");
715 for (i = 0; i < card->num_rtd; i++) {
717 if (card->rtd[i].dai_link->ignore_suspend)
720 snd_soc_dapm_stream_event(&card->rtd[i],
721 SNDRV_PCM_STREAM_PLAYBACK,
722 SND_SOC_DAPM_STREAM_RESUME);
724 snd_soc_dapm_stream_event(&card->rtd[i],
725 SNDRV_PCM_STREAM_CAPTURE,
726 SND_SOC_DAPM_STREAM_RESUME);
729 /* unmute any active DACs */
730 for (i = 0; i < card->num_rtd; i++) {
731 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
732 struct snd_soc_dai_driver *drv = dai->driver;
734 if (card->rtd[i].dai_link->ignore_suspend)
737 if (drv->ops->digital_mute && dai->playback_active)
738 drv->ops->digital_mute(dai, 0);
741 for (i = 0; i < card->num_rtd; i++) {
742 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
743 struct snd_soc_platform *platform = card->rtd[i].platform;
745 if (card->rtd[i].dai_link->ignore_suspend)
748 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
749 cpu_dai->driver->resume(cpu_dai);
750 if (platform->driver->resume && platform->suspended) {
751 platform->driver->resume(cpu_dai);
752 platform->suspended = 0;
756 if (card->resume_post)
757 card->resume_post(card);
759 dev_dbg(card->dev, "resume work completed\n");
761 /* userspace can access us now we are back as we were before */
762 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
764 /* Recheck all analogue paths too */
765 dapm_mark_io_dirty(&card->dapm);
766 snd_soc_dapm_sync(&card->dapm);
769 /* powers up audio subsystem after a suspend */
770 int snd_soc_resume(struct device *dev)
772 struct snd_soc_card *card = dev_get_drvdata(dev);
773 int i, ac97_control = 0;
775 /* If the initialization of this soc device failed, there is no codec
776 * associated with it. Just bail out in this case.
778 if (list_empty(&card->codec_dev_list))
781 /* AC97 devices might have other drivers hanging off them so
782 * need to resume immediately. Other drivers don't have that
783 * problem and may take a substantial amount of time to resume
784 * due to I/O costs and anti-pop so handle them out of line.
786 for (i = 0; i < card->num_rtd; i++) {
787 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
788 ac97_control |= cpu_dai->driver->ac97_control;
791 dev_dbg(dev, "Resuming AC97 immediately\n");
792 soc_resume_deferred(&card->deferred_resume_work);
794 dev_dbg(dev, "Scheduling resume work\n");
795 if (!schedule_work(&card->deferred_resume_work))
796 dev_err(dev, "resume work item may be lost\n");
801 EXPORT_SYMBOL_GPL(snd_soc_resume);
803 #define snd_soc_suspend NULL
804 #define snd_soc_resume NULL
807 static const struct snd_soc_dai_ops null_dai_ops = {
810 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
812 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
813 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
814 struct snd_soc_codec *codec;
815 struct snd_soc_platform *platform;
816 struct snd_soc_dai *codec_dai, *cpu_dai;
817 const char *platform_name;
819 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
821 /* Find CPU DAI from registered DAIs*/
822 list_for_each_entry(cpu_dai, &dai_list, list) {
823 if (dai_link->cpu_of_node &&
824 (cpu_dai->dev->of_node != dai_link->cpu_of_node))
826 if (dai_link->cpu_name &&
827 strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name))
829 if (dai_link->cpu_dai_name &&
830 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
833 rtd->cpu_dai = cpu_dai;
837 dev_err(card->dev, "CPU DAI %s not registered\n",
838 dai_link->cpu_dai_name);
839 return -EPROBE_DEFER;
842 /* Find CODEC from registered CODECs */
843 list_for_each_entry(codec, &codec_list, list) {
844 if (dai_link->codec_of_node) {
845 if (codec->dev->of_node != dai_link->codec_of_node)
848 if (strcmp(codec->name, dai_link->codec_name))
855 * CODEC found, so find CODEC DAI from registered DAIs from
858 list_for_each_entry(codec_dai, &dai_list, list) {
859 if (codec->dev == codec_dai->dev &&
860 !strcmp(codec_dai->name,
861 dai_link->codec_dai_name)) {
863 rtd->codec_dai = codec_dai;
867 if (!rtd->codec_dai) {
868 dev_err(card->dev, "CODEC DAI %s not registered\n",
869 dai_link->codec_dai_name);
870 return -EPROBE_DEFER;
875 dev_err(card->dev, "CODEC %s not registered\n",
876 dai_link->codec_name);
877 return -EPROBE_DEFER;
880 /* if there's no platform we match on the empty platform */
881 platform_name = dai_link->platform_name;
882 if (!platform_name && !dai_link->platform_of_node)
883 platform_name = "snd-soc-dummy";
885 /* find one from the set of registered platforms */
886 list_for_each_entry(platform, &platform_list, list) {
887 if (dai_link->platform_of_node) {
888 if (platform->dev->of_node !=
889 dai_link->platform_of_node)
892 if (strcmp(platform->name, platform_name))
896 rtd->platform = platform;
898 if (!rtd->platform) {
899 dev_err(card->dev, "platform %s not registered\n",
900 dai_link->platform_name);
901 return -EPROBE_DEFER;
909 static int soc_remove_platform(struct snd_soc_platform *platform)
913 if (platform->driver->remove) {
914 ret = platform->driver->remove(platform);
916 pr_err("asoc: failed to remove %s: %d\n",
917 platform->name, ret);
920 /* Make sure all DAPM widgets are freed */
921 snd_soc_dapm_free(&platform->dapm);
923 soc_cleanup_platform_debugfs(platform);
924 platform->probed = 0;
925 list_del(&platform->card_list);
926 module_put(platform->dev->driver->owner);
931 static void soc_remove_codec(struct snd_soc_codec *codec)
935 if (codec->driver->remove) {
936 err = codec->driver->remove(codec);
939 "asoc: failed to remove %s: %d\n",
943 /* Make sure all DAPM widgets are freed */
944 snd_soc_dapm_free(&codec->dapm);
946 soc_cleanup_codec_debugfs(codec);
948 list_del(&codec->card_list);
949 module_put(codec->dev->driver->owner);
952 static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
954 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
955 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
958 /* unregister the rtd device */
959 if (rtd->dev_registered) {
960 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
961 device_remove_file(rtd->dev, &dev_attr_codec_reg);
962 device_unregister(rtd->dev);
963 rtd->dev_registered = 0;
966 /* remove the CODEC DAI */
967 if (codec_dai && codec_dai->probed &&
968 codec_dai->driver->remove_order == order) {
969 if (codec_dai->driver->remove) {
970 err = codec_dai->driver->remove(codec_dai);
972 pr_err("asoc: failed to remove %s: %d\n",
973 codec_dai->name, err);
975 codec_dai->probed = 0;
976 list_del(&codec_dai->card_list);
979 /* remove the cpu_dai */
980 if (cpu_dai && cpu_dai->probed &&
981 cpu_dai->driver->remove_order == order) {
982 if (cpu_dai->driver->remove) {
983 err = cpu_dai->driver->remove(cpu_dai);
985 pr_err("asoc: failed to remove %s: %d\n",
989 list_del(&cpu_dai->card_list);
991 if (!cpu_dai->codec) {
992 snd_soc_dapm_free(&cpu_dai->dapm);
993 module_put(cpu_dai->dev->driver->owner);
998 static void soc_remove_link_components(struct snd_soc_card *card, int num,
1001 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1002 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1003 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1004 struct snd_soc_platform *platform = rtd->platform;
1005 struct snd_soc_codec *codec;
1007 /* remove the platform */
1008 if (platform && platform->probed &&
1009 platform->driver->remove_order == order) {
1010 soc_remove_platform(platform);
1013 /* remove the CODEC-side CODEC */
1015 codec = codec_dai->codec;
1016 if (codec && codec->probed &&
1017 codec->driver->remove_order == order)
1018 soc_remove_codec(codec);
1021 /* remove any CPU-side CODEC */
1023 codec = cpu_dai->codec;
1024 if (codec && codec->probed &&
1025 codec->driver->remove_order == order)
1026 soc_remove_codec(codec);
1030 static void soc_remove_dai_links(struct snd_soc_card *card)
1034 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1036 for (dai = 0; dai < card->num_rtd; dai++)
1037 soc_remove_link_dais(card, dai, order);
1040 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1042 for (dai = 0; dai < card->num_rtd; dai++)
1043 soc_remove_link_components(card, dai, order);
1049 static void soc_set_name_prefix(struct snd_soc_card *card,
1050 struct snd_soc_codec *codec)
1054 if (card->codec_conf == NULL)
1057 for (i = 0; i < card->num_configs; i++) {
1058 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1059 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1060 codec->name_prefix = map->name_prefix;
1066 static int soc_probe_codec(struct snd_soc_card *card,
1067 struct snd_soc_codec *codec)
1070 const struct snd_soc_codec_driver *driver = codec->driver;
1071 struct snd_soc_dai *dai;
1074 codec->dapm.card = card;
1075 soc_set_name_prefix(card, codec);
1077 if (!try_module_get(codec->dev->driver->owner))
1080 soc_init_codec_debugfs(codec);
1082 if (driver->dapm_widgets)
1083 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
1084 driver->num_dapm_widgets);
1086 /* Create DAPM widgets for each DAI stream */
1087 list_for_each_entry(dai, &dai_list, list) {
1088 if (dai->dev != codec->dev)
1091 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
1094 codec->dapm.idle_bias_off = driver->idle_bias_off;
1096 if (driver->probe) {
1097 ret = driver->probe(codec);
1100 "asoc: failed to probe CODEC %s: %d\n",
1106 /* If the driver didn't set I/O up try regmap */
1107 if (!codec->write && dev_get_regmap(codec->dev, NULL))
1108 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1110 if (driver->controls)
1111 snd_soc_add_codec_controls(codec, driver->controls,
1112 driver->num_controls);
1113 if (driver->dapm_routes)
1114 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1115 driver->num_dapm_routes);
1117 /* mark codec as probed and add to card codec list */
1119 list_add(&codec->card_list, &card->codec_dev_list);
1120 list_add(&codec->dapm.list, &card->dapm_list);
1125 soc_cleanup_codec_debugfs(codec);
1126 module_put(codec->dev->driver->owner);
1131 static int soc_probe_platform(struct snd_soc_card *card,
1132 struct snd_soc_platform *platform)
1135 const struct snd_soc_platform_driver *driver = platform->driver;
1136 struct snd_soc_dai *dai;
1138 platform->card = card;
1139 platform->dapm.card = card;
1141 if (!try_module_get(platform->dev->driver->owner))
1144 soc_init_platform_debugfs(platform);
1146 if (driver->dapm_widgets)
1147 snd_soc_dapm_new_controls(&platform->dapm,
1148 driver->dapm_widgets, driver->num_dapm_widgets);
1150 /* Create DAPM widgets for each DAI stream */
1151 list_for_each_entry(dai, &dai_list, list) {
1152 if (dai->dev != platform->dev)
1155 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
1158 platform->dapm.idle_bias_off = 1;
1160 if (driver->probe) {
1161 ret = driver->probe(platform);
1163 dev_err(platform->dev,
1164 "asoc: failed to probe platform %s: %d\n",
1165 platform->name, ret);
1170 if (driver->controls)
1171 snd_soc_add_platform_controls(platform, driver->controls,
1172 driver->num_controls);
1173 if (driver->dapm_routes)
1174 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1175 driver->num_dapm_routes);
1177 /* mark platform as probed and add to card platform list */
1178 platform->probed = 1;
1179 list_add(&platform->card_list, &card->platform_dev_list);
1180 list_add(&platform->dapm.list, &card->dapm_list);
1185 soc_cleanup_platform_debugfs(platform);
1186 module_put(platform->dev->driver->owner);
1191 static void rtd_release(struct device *dev)
1196 static int soc_post_component_init(struct snd_soc_card *card,
1197 struct snd_soc_codec *codec,
1198 int num, int dailess)
1200 struct snd_soc_dai_link *dai_link = NULL;
1201 struct snd_soc_aux_dev *aux_dev = NULL;
1202 struct snd_soc_pcm_runtime *rtd;
1203 const char *temp, *name;
1207 dai_link = &card->dai_link[num];
1208 rtd = &card->rtd[num];
1209 name = dai_link->name;
1211 aux_dev = &card->aux_dev[num];
1212 rtd = &card->rtd_aux[num];
1213 name = aux_dev->name;
1217 /* Make sure all DAPM widgets are instantiated */
1218 snd_soc_dapm_new_widgets(&codec->dapm);
1220 /* machine controls, routes and widgets are not prefixed */
1221 temp = codec->name_prefix;
1222 codec->name_prefix = NULL;
1224 /* do machine specific initialization */
1225 if (!dailess && dai_link->init)
1226 ret = dai_link->init(rtd);
1227 else if (dailess && aux_dev->init)
1228 ret = aux_dev->init(&codec->dapm);
1230 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1233 codec->name_prefix = temp;
1235 /* register the rtd device */
1238 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1241 device_initialize(rtd->dev);
1242 rtd->dev->parent = card->dev;
1243 rtd->dev->release = rtd_release;
1244 rtd->dev->init_name = name;
1245 dev_set_drvdata(rtd->dev, rtd);
1246 mutex_init(&rtd->pcm_mutex);
1247 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1248 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1249 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1250 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1251 ret = device_add(rtd->dev);
1254 "asoc: failed to register runtime device: %d\n", ret);
1257 rtd->dev_registered = 1;
1259 /* add DAPM sysfs entries for this codec */
1260 ret = snd_soc_dapm_sys_add(rtd->dev);
1263 "asoc: failed to add codec dapm sysfs entries: %d\n",
1266 /* add codec sysfs entries */
1267 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
1270 "asoc: failed to add codec sysfs files: %d\n", ret);
1272 #ifdef CONFIG_DEBUG_FS
1273 /* add DPCM sysfs entries */
1274 if (!dailess && !dai_link->dynamic)
1277 ret = soc_dpcm_debugfs_add(rtd);
1279 dev_err(rtd->dev, "asoc: failed to add dpcm sysfs entries: %d\n", ret);
1286 static int soc_probe_link_components(struct snd_soc_card *card, int num,
1289 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1290 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1291 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1292 struct snd_soc_platform *platform = rtd->platform;
1295 /* probe the CPU-side component, if it is a CODEC */
1296 if (cpu_dai->codec &&
1297 !cpu_dai->codec->probed &&
1298 cpu_dai->codec->driver->probe_order == order) {
1299 ret = soc_probe_codec(card, cpu_dai->codec);
1304 /* probe the CODEC-side component */
1305 if (!codec_dai->codec->probed &&
1306 codec_dai->codec->driver->probe_order == order) {
1307 ret = soc_probe_codec(card, codec_dai->codec);
1312 /* probe the platform */
1313 if (!platform->probed &&
1314 platform->driver->probe_order == order) {
1315 ret = soc_probe_platform(card, platform);
1323 static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1325 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1326 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1327 struct snd_soc_codec *codec = rtd->codec;
1328 struct snd_soc_platform *platform = rtd->platform;
1329 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1330 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1331 struct snd_soc_dapm_widget *play_w, *capture_w;
1334 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1335 card->name, num, order);
1337 /* config components */
1338 cpu_dai->platform = platform;
1339 codec_dai->card = card;
1340 cpu_dai->card = card;
1342 /* set default power off timeout */
1343 rtd->pmdown_time = pmdown_time;
1345 /* probe the cpu_dai */
1346 if (!cpu_dai->probed &&
1347 cpu_dai->driver->probe_order == order) {
1348 if (!cpu_dai->codec) {
1349 cpu_dai->dapm.card = card;
1350 if (!try_module_get(cpu_dai->dev->driver->owner))
1353 list_add(&cpu_dai->dapm.list, &card->dapm_list);
1354 snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
1357 if (cpu_dai->driver->probe) {
1358 ret = cpu_dai->driver->probe(cpu_dai);
1360 pr_err("asoc: failed to probe CPU DAI %s: %d\n",
1361 cpu_dai->name, ret);
1362 module_put(cpu_dai->dev->driver->owner);
1366 cpu_dai->probed = 1;
1367 /* mark cpu_dai as probed and add to card dai list */
1368 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1371 /* probe the CODEC DAI */
1372 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1373 if (codec_dai->driver->probe) {
1374 ret = codec_dai->driver->probe(codec_dai);
1376 pr_err("asoc: failed to probe CODEC DAI %s: %d\n",
1377 codec_dai->name, ret);
1382 /* mark codec_dai as probed and add to card dai list */
1383 codec_dai->probed = 1;
1384 list_add(&codec_dai->card_list, &card->dai_dev_list);
1387 /* complete DAI probe during last probe */
1388 if (order != SND_SOC_COMP_ORDER_LAST)
1391 ret = soc_post_component_init(card, codec, num, 0);
1395 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1397 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret);
1399 if (cpu_dai->driver->compress_dai) {
1400 /*create compress_device"*/
1401 ret = soc_new_compress(rtd, num);
1403 pr_err("asoc: can't create compress %s\n",
1404 dai_link->stream_name);
1409 if (!dai_link->params) {
1410 /* create the pcm */
1411 ret = soc_new_pcm(rtd, num);
1413 pr_err("asoc: can't create pcm %s :%d\n",
1414 dai_link->stream_name, ret);
1418 /* link the DAI widgets */
1419 play_w = codec_dai->playback_widget;
1420 capture_w = cpu_dai->capture_widget;
1421 if (play_w && capture_w) {
1422 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1425 dev_err(card->dev, "Can't link %s to %s: %d\n",
1426 play_w->name, capture_w->name, ret);
1431 play_w = cpu_dai->playback_widget;
1432 capture_w = codec_dai->capture_widget;
1433 if (play_w && capture_w) {
1434 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1437 dev_err(card->dev, "Can't link %s to %s: %d\n",
1438 play_w->name, capture_w->name, ret);
1445 /* add platform data for AC97 devices */
1446 if (rtd->codec_dai->driver->ac97_control)
1447 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1452 #ifdef CONFIG_SND_SOC_AC97_BUS
1453 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1457 /* Only instantiate AC97 if not already done by the adaptor
1458 * for the generic AC97 subsystem.
1460 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1462 * It is possible that the AC97 device is already registered to
1463 * the device subsystem. This happens when the device is created
1464 * via snd_ac97_mixer(). Currently only SoC codec that does so
1465 * is the generic AC97 glue but others migh emerge.
1467 * In those cases we don't try to register the device again.
1469 if (!rtd->codec->ac97_created)
1472 ret = soc_ac97_dev_register(rtd->codec);
1474 pr_err("asoc: AC97 device register failed:%d\n", ret);
1478 rtd->codec->ac97_registered = 1;
1483 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1485 if (codec->ac97_registered) {
1486 soc_ac97_dev_unregister(codec);
1487 codec->ac97_registered = 0;
1492 static int soc_check_aux_dev(struct snd_soc_card *card, int num)
1494 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1495 struct snd_soc_codec *codec;
1497 /* find CODEC from registered CODECs*/
1498 list_for_each_entry(codec, &codec_list, list) {
1499 if (!strcmp(codec->name, aux_dev->codec_name))
1503 dev_err(card->dev, "%s not registered\n", aux_dev->codec_name);
1505 return -EPROBE_DEFER;
1508 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1510 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1511 struct snd_soc_codec *codec;
1514 /* find CODEC from registered CODECs*/
1515 list_for_each_entry(codec, &codec_list, list) {
1516 if (!strcmp(codec->name, aux_dev->codec_name)) {
1517 if (codec->probed) {
1519 "asoc: codec already probed");
1526 /* codec not found */
1527 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1528 return -EPROBE_DEFER;
1531 ret = soc_probe_codec(card, codec);
1535 ret = soc_post_component_init(card, codec, num, 1);
1541 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1543 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1544 struct snd_soc_codec *codec = rtd->codec;
1546 /* unregister the rtd device */
1547 if (rtd->dev_registered) {
1548 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1549 device_del(rtd->dev);
1550 rtd->dev_registered = 0;
1553 if (codec && codec->probed)
1554 soc_remove_codec(codec);
1557 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1558 enum snd_soc_compress_type compress_type)
1562 if (codec->cache_init)
1565 /* override the compress_type if necessary */
1566 if (compress_type && codec->compress_type != compress_type)
1567 codec->compress_type = compress_type;
1568 ret = snd_soc_cache_init(codec);
1570 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1574 codec->cache_init = 1;
1578 static int snd_soc_instantiate_card(struct snd_soc_card *card)
1580 struct snd_soc_codec *codec;
1581 struct snd_soc_codec_conf *codec_conf;
1582 enum snd_soc_compress_type compress_type;
1583 struct snd_soc_dai_link *dai_link;
1584 int ret, i, order, dai_fmt;
1586 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1589 for (i = 0; i < card->num_links; i++) {
1590 ret = soc_bind_dai_link(card, i);
1595 /* check aux_devs too */
1596 for (i = 0; i < card->num_aux_devs; i++) {
1597 ret = soc_check_aux_dev(card, i);
1602 /* initialize the register cache for each available codec */
1603 list_for_each_entry(codec, &codec_list, list) {
1604 if (codec->cache_init)
1606 /* by default we don't override the compress_type */
1608 /* check to see if we need to override the compress_type */
1609 for (i = 0; i < card->num_configs; ++i) {
1610 codec_conf = &card->codec_conf[i];
1611 if (!strcmp(codec->name, codec_conf->dev_name)) {
1612 compress_type = codec_conf->compress_type;
1613 if (compress_type && compress_type
1614 != codec->compress_type)
1618 ret = snd_soc_init_codec_cache(codec, compress_type);
1623 /* card bind complete so register a sound card */
1624 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1625 card->owner, 0, &card->snd_card);
1627 pr_err("asoc: can't create sound card for card %s: %d\n",
1631 card->snd_card->dev = card->dev;
1633 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1634 card->dapm.dev = card->dev;
1635 card->dapm.card = card;
1636 list_add(&card->dapm.list, &card->dapm_list);
1638 #ifdef CONFIG_DEBUG_FS
1639 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1642 #ifdef CONFIG_PM_SLEEP
1643 /* deferred resume work */
1644 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1647 if (card->dapm_widgets)
1648 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1649 card->num_dapm_widgets);
1651 /* initialise the sound card only once */
1653 ret = card->probe(card);
1655 goto card_probe_error;
1658 /* probe all components used by DAI links on this card */
1659 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1661 for (i = 0; i < card->num_links; i++) {
1662 ret = soc_probe_link_components(card, i, order);
1664 pr_err("asoc: failed to instantiate card %s: %d\n",
1671 /* probe all DAI links on this card */
1672 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1674 for (i = 0; i < card->num_links; i++) {
1675 ret = soc_probe_link_dais(card, i, order);
1677 pr_err("asoc: failed to instantiate card %s: %d\n",
1684 for (i = 0; i < card->num_aux_devs; i++) {
1685 ret = soc_probe_aux_dev(card, i);
1687 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1689 goto probe_aux_dev_err;
1693 snd_soc_dapm_link_dai_widgets(card);
1696 snd_soc_add_card_controls(card, card->controls, card->num_controls);
1698 if (card->dapm_routes)
1699 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1700 card->num_dapm_routes);
1702 snd_soc_dapm_new_widgets(&card->dapm);
1704 for (i = 0; i < card->num_links; i++) {
1705 dai_link = &card->dai_link[i];
1706 dai_fmt = dai_link->dai_fmt;
1709 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1711 if (ret != 0 && ret != -ENOTSUPP)
1712 dev_warn(card->rtd[i].codec_dai->dev,
1713 "Failed to set DAI format: %d\n",
1717 /* If this is a regular CPU link there will be a platform */
1719 (dai_link->platform_name || dai_link->platform_of_node)) {
1720 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1722 if (ret != 0 && ret != -ENOTSUPP)
1723 dev_warn(card->rtd[i].cpu_dai->dev,
1724 "Failed to set DAI format: %d\n",
1726 } else if (dai_fmt) {
1727 /* Flip the polarity for the "CPU" end */
1728 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1729 switch (dai_link->dai_fmt &
1730 SND_SOC_DAIFMT_MASTER_MASK) {
1731 case SND_SOC_DAIFMT_CBM_CFM:
1732 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1734 case SND_SOC_DAIFMT_CBM_CFS:
1735 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1737 case SND_SOC_DAIFMT_CBS_CFM:
1738 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1740 case SND_SOC_DAIFMT_CBS_CFS:
1741 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1745 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1747 if (ret != 0 && ret != -ENOTSUPP)
1748 dev_warn(card->rtd[i].cpu_dai->dev,
1749 "Failed to set DAI format: %d\n",
1754 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1756 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1757 "%s", card->long_name ? card->long_name : card->name);
1758 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1759 "%s", card->driver_name ? card->driver_name : card->name);
1760 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1761 switch (card->snd_card->driver[i]) {
1767 if (!isalnum(card->snd_card->driver[i]))
1768 card->snd_card->driver[i] = '_';
1773 if (card->late_probe) {
1774 ret = card->late_probe(card);
1776 dev_err(card->dev, "%s late_probe() failed: %d\n",
1778 goto probe_aux_dev_err;
1782 snd_soc_dapm_new_widgets(&card->dapm);
1784 if (card->fully_routed)
1785 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1786 snd_soc_dapm_auto_nc_codec_pins(codec);
1788 ret = snd_card_register(card->snd_card);
1790 pr_err("asoc: failed to register soundcard for %s: %d\n",
1792 goto probe_aux_dev_err;
1795 #ifdef CONFIG_SND_SOC_AC97_BUS
1796 /* register any AC97 codecs */
1797 for (i = 0; i < card->num_rtd; i++) {
1798 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1800 pr_err("asoc: failed to register AC97 %s: %d\n",
1803 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1804 goto probe_aux_dev_err;
1809 card->instantiated = 1;
1810 snd_soc_dapm_sync(&card->dapm);
1811 mutex_unlock(&card->mutex);
1816 for (i = 0; i < card->num_aux_devs; i++)
1817 soc_remove_aux_dev(card, i);
1820 soc_remove_dai_links(card);
1826 snd_card_free(card->snd_card);
1829 mutex_unlock(&card->mutex);
1834 /* probes a new socdev */
1835 static int soc_probe(struct platform_device *pdev)
1837 struct snd_soc_card *card = platform_get_drvdata(pdev);
1840 * no card, so machine driver should be registering card
1841 * we should not be here in that case so ret error
1846 dev_warn(&pdev->dev,
1847 "ASoC machine %s should use snd_soc_register_card()\n",
1850 /* Bodge while we unpick instantiation */
1851 card->dev = &pdev->dev;
1853 return snd_soc_register_card(card);
1856 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1860 /* make sure any delayed work runs */
1861 for (i = 0; i < card->num_rtd; i++) {
1862 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1863 flush_delayed_work_sync(&rtd->delayed_work);
1866 /* remove auxiliary devices */
1867 for (i = 0; i < card->num_aux_devs; i++)
1868 soc_remove_aux_dev(card, i);
1870 /* remove and free each DAI */
1871 soc_remove_dai_links(card);
1873 soc_cleanup_card_debugfs(card);
1875 /* remove the card */
1879 snd_soc_dapm_free(&card->dapm);
1881 snd_card_free(card->snd_card);
1886 /* removes a socdev */
1887 static int soc_remove(struct platform_device *pdev)
1889 struct snd_soc_card *card = platform_get_drvdata(pdev);
1891 snd_soc_unregister_card(card);
1895 int snd_soc_poweroff(struct device *dev)
1897 struct snd_soc_card *card = dev_get_drvdata(dev);
1900 if (!card->instantiated)
1903 /* Flush out pmdown_time work - we actually do want to run it
1904 * now, we're shutting down so no imminent restart. */
1905 for (i = 0; i < card->num_rtd; i++) {
1906 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1907 flush_delayed_work_sync(&rtd->delayed_work);
1910 snd_soc_dapm_shutdown(card);
1914 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1916 const struct dev_pm_ops snd_soc_pm_ops = {
1917 .suspend = snd_soc_suspend,
1918 .resume = snd_soc_resume,
1919 .freeze = snd_soc_suspend,
1920 .thaw = snd_soc_resume,
1921 .poweroff = snd_soc_poweroff,
1922 .restore = snd_soc_resume,
1924 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1926 /* ASoC platform driver */
1927 static struct platform_driver soc_driver = {
1929 .name = "soc-audio",
1930 .owner = THIS_MODULE,
1931 .pm = &snd_soc_pm_ops,
1934 .remove = soc_remove,
1938 * snd_soc_codec_volatile_register: Report if a register is volatile.
1940 * @codec: CODEC to query.
1941 * @reg: Register to query.
1943 * Boolean function indiciating if a CODEC register is volatile.
1945 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1948 if (codec->volatile_register)
1949 return codec->volatile_register(codec, reg);
1953 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1956 * snd_soc_codec_readable_register: Report if a register is readable.
1958 * @codec: CODEC to query.
1959 * @reg: Register to query.
1961 * Boolean function indicating if a CODEC register is readable.
1963 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1966 if (codec->readable_register)
1967 return codec->readable_register(codec, reg);
1971 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1974 * snd_soc_codec_writable_register: Report if a register is writable.
1976 * @codec: CODEC to query.
1977 * @reg: Register to query.
1979 * Boolean function indicating if a CODEC register is writable.
1981 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1984 if (codec->writable_register)
1985 return codec->writable_register(codec, reg);
1989 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1991 int snd_soc_platform_read(struct snd_soc_platform *platform,
1996 if (!platform->driver->read) {
1997 dev_err(platform->dev, "platform has no read back\n");
2001 ret = platform->driver->read(platform, reg);
2002 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
2003 trace_snd_soc_preg_read(platform, reg, ret);
2007 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
2009 int snd_soc_platform_write(struct snd_soc_platform *platform,
2010 unsigned int reg, unsigned int val)
2012 if (!platform->driver->write) {
2013 dev_err(platform->dev, "platform has no write back\n");
2017 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
2018 trace_snd_soc_preg_write(platform, reg, val);
2019 return platform->driver->write(platform, reg, val);
2021 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
2024 * snd_soc_new_ac97_codec - initailise AC97 device
2025 * @codec: audio codec
2026 * @ops: AC97 bus operations
2027 * @num: AC97 codec number
2029 * Initialises AC97 codec resources for use by ad-hoc devices only.
2031 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
2032 struct snd_ac97_bus_ops *ops, int num)
2034 mutex_lock(&codec->mutex);
2036 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
2037 if (codec->ac97 == NULL) {
2038 mutex_unlock(&codec->mutex);
2042 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
2043 if (codec->ac97->bus == NULL) {
2046 mutex_unlock(&codec->mutex);
2050 codec->ac97->bus->ops = ops;
2051 codec->ac97->num = num;
2054 * Mark the AC97 device to be created by us. This way we ensure that the
2055 * device will be registered with the device subsystem later on.
2057 codec->ac97_created = 1;
2059 mutex_unlock(&codec->mutex);
2062 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
2065 * snd_soc_free_ac97_codec - free AC97 codec device
2066 * @codec: audio codec
2068 * Frees AC97 codec device resources.
2070 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
2072 mutex_lock(&codec->mutex);
2073 #ifdef CONFIG_SND_SOC_AC97_BUS
2074 soc_unregister_ac97_dai_link(codec);
2076 kfree(codec->ac97->bus);
2079 codec->ac97_created = 0;
2080 mutex_unlock(&codec->mutex);
2082 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
2084 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
2088 ret = codec->read(codec, reg);
2089 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
2090 trace_snd_soc_reg_read(codec, reg, ret);
2094 EXPORT_SYMBOL_GPL(snd_soc_read);
2096 unsigned int snd_soc_write(struct snd_soc_codec *codec,
2097 unsigned int reg, unsigned int val)
2099 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
2100 trace_snd_soc_reg_write(codec, reg, val);
2101 return codec->write(codec, reg, val);
2103 EXPORT_SYMBOL_GPL(snd_soc_write);
2105 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
2106 unsigned int reg, const void *data, size_t len)
2108 return codec->bulk_write_raw(codec, reg, data, len);
2110 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
2113 * snd_soc_update_bits - update codec register bits
2114 * @codec: audio codec
2115 * @reg: codec register
2116 * @mask: register mask
2119 * Writes new register value.
2121 * Returns 1 for change, 0 for no change, or negative error code.
2123 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
2124 unsigned int mask, unsigned int value)
2127 unsigned int old, new;
2130 if (codec->using_regmap) {
2131 ret = regmap_update_bits_check(codec->control_data, reg,
2132 mask, value, &change);
2134 ret = snd_soc_read(codec, reg);
2139 new = (old & ~mask) | (value & mask);
2140 change = old != new;
2142 ret = snd_soc_write(codec, reg, new);
2150 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
2153 * snd_soc_update_bits_locked - update codec register bits
2154 * @codec: audio codec
2155 * @reg: codec register
2156 * @mask: register mask
2159 * Writes new register value, and takes the codec mutex.
2161 * Returns 1 for change else 0.
2163 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
2164 unsigned short reg, unsigned int mask,
2169 mutex_lock(&codec->mutex);
2170 change = snd_soc_update_bits(codec, reg, mask, value);
2171 mutex_unlock(&codec->mutex);
2175 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
2178 * snd_soc_test_bits - test register for change
2179 * @codec: audio codec
2180 * @reg: codec register
2181 * @mask: register mask
2184 * Tests a register with a new value and checks if the new value is
2185 * different from the old value.
2187 * Returns 1 for change else 0.
2189 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
2190 unsigned int mask, unsigned int value)
2193 unsigned int old, new;
2195 old = snd_soc_read(codec, reg);
2196 new = (old & ~mask) | value;
2197 change = old != new;
2201 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
2204 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
2205 * @substream: the pcm substream
2206 * @hw: the hardware parameters
2208 * Sets the substream runtime hardware parameters.
2210 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
2211 const struct snd_pcm_hardware *hw)
2213 struct snd_pcm_runtime *runtime = substream->runtime;
2214 runtime->hw.info = hw->info;
2215 runtime->hw.formats = hw->formats;
2216 runtime->hw.period_bytes_min = hw->period_bytes_min;
2217 runtime->hw.period_bytes_max = hw->period_bytes_max;
2218 runtime->hw.periods_min = hw->periods_min;
2219 runtime->hw.periods_max = hw->periods_max;
2220 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
2221 runtime->hw.fifo_size = hw->fifo_size;
2224 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
2227 * snd_soc_cnew - create new control
2228 * @_template: control template
2229 * @data: control private data
2230 * @long_name: control long name
2231 * @prefix: control name prefix
2233 * Create a new mixer control from a template control.
2235 * Returns 0 for success, else error.
2237 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2238 void *data, const char *long_name,
2241 struct snd_kcontrol_new template;
2242 struct snd_kcontrol *kcontrol;
2246 memcpy(&template, _template, sizeof(template));
2250 long_name = template.name;
2253 name_len = strlen(long_name) + strlen(prefix) + 2;
2254 name = kmalloc(name_len, GFP_KERNEL);
2258 snprintf(name, name_len, "%s %s", prefix, long_name);
2260 template.name = name;
2262 template.name = long_name;
2265 kcontrol = snd_ctl_new1(&template, data);
2271 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2273 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2274 const struct snd_kcontrol_new *controls, int num_controls,
2275 const char *prefix, void *data)
2279 for (i = 0; i < num_controls; i++) {
2280 const struct snd_kcontrol_new *control = &controls[i];
2281 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2282 control->name, prefix));
2284 dev_err(dev, "Failed to add %s: %d\n", control->name, err);
2293 * snd_soc_add_codec_controls - add an array of controls to a codec.
2294 * Convenience function to add a list of controls. Many codecs were
2295 * duplicating this code.
2297 * @codec: codec to add controls to
2298 * @controls: array of controls to add
2299 * @num_controls: number of elements in the array
2301 * Return 0 for success, else error.
2303 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2304 const struct snd_kcontrol_new *controls, int num_controls)
2306 struct snd_card *card = codec->card->snd_card;
2308 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2309 codec->name_prefix, codec);
2311 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2314 * snd_soc_add_platform_controls - add an array of controls to a platform.
2315 * Convenience function to add a list of controls.
2317 * @platform: platform to add controls to
2318 * @controls: array of controls to add
2319 * @num_controls: number of elements in the array
2321 * Return 0 for success, else error.
2323 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2324 const struct snd_kcontrol_new *controls, int num_controls)
2326 struct snd_card *card = platform->card->snd_card;
2328 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2331 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2334 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2335 * Convenience function to add a list of controls.
2337 * @soc_card: SoC card to add controls to
2338 * @controls: array of controls to add
2339 * @num_controls: number of elements in the array
2341 * Return 0 for success, else error.
2343 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2344 const struct snd_kcontrol_new *controls, int num_controls)
2346 struct snd_card *card = soc_card->snd_card;
2348 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2351 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2354 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2355 * Convienience function to add a list of controls.
2357 * @dai: DAI to add controls to
2358 * @controls: array of controls to add
2359 * @num_controls: number of elements in the array
2361 * Return 0 for success, else error.
2363 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2364 const struct snd_kcontrol_new *controls, int num_controls)
2366 struct snd_card *card = dai->card->snd_card;
2368 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2371 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2374 * snd_soc_info_enum_double - enumerated double mixer info callback
2375 * @kcontrol: mixer control
2376 * @uinfo: control element information
2378 * Callback to provide information about a double enumerated
2381 * Returns 0 for success.
2383 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2384 struct snd_ctl_elem_info *uinfo)
2386 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2388 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2389 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2390 uinfo->value.enumerated.items = e->max;
2392 if (uinfo->value.enumerated.item > e->max - 1)
2393 uinfo->value.enumerated.item = e->max - 1;
2394 strcpy(uinfo->value.enumerated.name,
2395 e->texts[uinfo->value.enumerated.item]);
2398 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2401 * snd_soc_get_enum_double - enumerated double mixer get callback
2402 * @kcontrol: mixer control
2403 * @ucontrol: control element information
2405 * Callback to get the value of a double enumerated mixer.
2407 * Returns 0 for success.
2409 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2410 struct snd_ctl_elem_value *ucontrol)
2412 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2413 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2414 unsigned int val, bitmask;
2416 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2418 val = snd_soc_read(codec, e->reg);
2419 ucontrol->value.enumerated.item[0]
2420 = (val >> e->shift_l) & (bitmask - 1);
2421 if (e->shift_l != e->shift_r)
2422 ucontrol->value.enumerated.item[1] =
2423 (val >> e->shift_r) & (bitmask - 1);
2427 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2430 * snd_soc_put_enum_double - enumerated double mixer put callback
2431 * @kcontrol: mixer control
2432 * @ucontrol: control element information
2434 * Callback to set the value of a double enumerated mixer.
2436 * Returns 0 for success.
2438 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2439 struct snd_ctl_elem_value *ucontrol)
2441 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2442 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2444 unsigned int mask, bitmask;
2446 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2448 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2450 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2451 mask = (bitmask - 1) << e->shift_l;
2452 if (e->shift_l != e->shift_r) {
2453 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2455 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2456 mask |= (bitmask - 1) << e->shift_r;
2459 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2461 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2464 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2465 * @kcontrol: mixer control
2466 * @ucontrol: control element information
2468 * Callback to get the value of a double semi enumerated mixer.
2470 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2471 * used for handling bitfield coded enumeration for example.
2473 * Returns 0 for success.
2475 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2476 struct snd_ctl_elem_value *ucontrol)
2478 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2479 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2480 unsigned int reg_val, val, mux;
2482 reg_val = snd_soc_read(codec, e->reg);
2483 val = (reg_val >> e->shift_l) & e->mask;
2484 for (mux = 0; mux < e->max; mux++) {
2485 if (val == e->values[mux])
2488 ucontrol->value.enumerated.item[0] = mux;
2489 if (e->shift_l != e->shift_r) {
2490 val = (reg_val >> e->shift_r) & e->mask;
2491 for (mux = 0; mux < e->max; mux++) {
2492 if (val == e->values[mux])
2495 ucontrol->value.enumerated.item[1] = mux;
2500 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2503 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2504 * @kcontrol: mixer control
2505 * @ucontrol: control element information
2507 * Callback to set the value of a double semi enumerated mixer.
2509 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2510 * used for handling bitfield coded enumeration for example.
2512 * Returns 0 for success.
2514 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2515 struct snd_ctl_elem_value *ucontrol)
2517 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2518 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2522 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2524 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2525 mask = e->mask << e->shift_l;
2526 if (e->shift_l != e->shift_r) {
2527 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2529 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2530 mask |= e->mask << e->shift_r;
2533 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2535 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2538 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2539 * @kcontrol: mixer control
2540 * @uinfo: control element information
2542 * Callback to provide information about an external enumerated
2545 * Returns 0 for success.
2547 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2548 struct snd_ctl_elem_info *uinfo)
2550 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2552 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2554 uinfo->value.enumerated.items = e->max;
2556 if (uinfo->value.enumerated.item > e->max - 1)
2557 uinfo->value.enumerated.item = e->max - 1;
2558 strcpy(uinfo->value.enumerated.name,
2559 e->texts[uinfo->value.enumerated.item]);
2562 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2565 * snd_soc_info_volsw_ext - external single mixer info callback
2566 * @kcontrol: mixer control
2567 * @uinfo: control element information
2569 * Callback to provide information about a single external mixer control.
2571 * Returns 0 for success.
2573 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2574 struct snd_ctl_elem_info *uinfo)
2576 int max = kcontrol->private_value;
2578 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2579 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2581 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2584 uinfo->value.integer.min = 0;
2585 uinfo->value.integer.max = max;
2588 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2591 * snd_soc_info_volsw - single mixer info callback
2592 * @kcontrol: mixer control
2593 * @uinfo: control element information
2595 * Callback to provide information about a single mixer control, or a double
2596 * mixer control that spans 2 registers.
2598 * Returns 0 for success.
2600 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2601 struct snd_ctl_elem_info *uinfo)
2603 struct soc_mixer_control *mc =
2604 (struct soc_mixer_control *)kcontrol->private_value;
2607 if (!mc->platform_max)
2608 mc->platform_max = mc->max;
2609 platform_max = mc->platform_max;
2611 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2612 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2614 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2616 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2617 uinfo->value.integer.min = 0;
2618 uinfo->value.integer.max = platform_max;
2621 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2624 * snd_soc_get_volsw - single mixer get callback
2625 * @kcontrol: mixer control
2626 * @ucontrol: control element information
2628 * Callback to get the value of a single mixer control, or a double mixer
2629 * control that spans 2 registers.
2631 * Returns 0 for success.
2633 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2634 struct snd_ctl_elem_value *ucontrol)
2636 struct soc_mixer_control *mc =
2637 (struct soc_mixer_control *)kcontrol->private_value;
2638 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2639 unsigned int reg = mc->reg;
2640 unsigned int reg2 = mc->rreg;
2641 unsigned int shift = mc->shift;
2642 unsigned int rshift = mc->rshift;
2644 unsigned int mask = (1 << fls(max)) - 1;
2645 unsigned int invert = mc->invert;
2647 ucontrol->value.integer.value[0] =
2648 (snd_soc_read(codec, reg) >> shift) & mask;
2650 ucontrol->value.integer.value[0] =
2651 max - ucontrol->value.integer.value[0];
2653 if (snd_soc_volsw_is_stereo(mc)) {
2655 ucontrol->value.integer.value[1] =
2656 (snd_soc_read(codec, reg) >> rshift) & mask;
2658 ucontrol->value.integer.value[1] =
2659 (snd_soc_read(codec, reg2) >> shift) & mask;
2661 ucontrol->value.integer.value[1] =
2662 max - ucontrol->value.integer.value[1];
2667 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2670 * snd_soc_put_volsw - single mixer put callback
2671 * @kcontrol: mixer control
2672 * @ucontrol: control element information
2674 * Callback to set the value of a single mixer control, or a double mixer
2675 * control that spans 2 registers.
2677 * Returns 0 for success.
2679 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2680 struct snd_ctl_elem_value *ucontrol)
2682 struct soc_mixer_control *mc =
2683 (struct soc_mixer_control *)kcontrol->private_value;
2684 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2685 unsigned int reg = mc->reg;
2686 unsigned int reg2 = mc->rreg;
2687 unsigned int shift = mc->shift;
2688 unsigned int rshift = mc->rshift;
2690 unsigned int mask = (1 << fls(max)) - 1;
2691 unsigned int invert = mc->invert;
2694 unsigned int val2 = 0;
2695 unsigned int val, val_mask;
2697 val = (ucontrol->value.integer.value[0] & mask);
2700 val_mask = mask << shift;
2702 if (snd_soc_volsw_is_stereo(mc)) {
2703 val2 = (ucontrol->value.integer.value[1] & mask);
2707 val_mask |= mask << rshift;
2708 val |= val2 << rshift;
2710 val2 = val2 << shift;
2714 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2719 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2723 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2726 * snd_soc_get_volsw_sx - single mixer get callback
2727 * @kcontrol: mixer control
2728 * @ucontrol: control element information
2730 * Callback to get the value of a single mixer control, or a double mixer
2731 * control that spans 2 registers.
2733 * Returns 0 for success.
2735 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2736 struct snd_ctl_elem_value *ucontrol)
2738 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2739 struct soc_mixer_control *mc =
2740 (struct soc_mixer_control *)kcontrol->private_value;
2742 unsigned int reg = mc->reg;
2743 unsigned int reg2 = mc->rreg;
2744 unsigned int shift = mc->shift;
2745 unsigned int rshift = mc->rshift;
2748 int mask = (1 << (fls(min + max) - 1)) - 1;
2750 ucontrol->value.integer.value[0] =
2751 ((snd_soc_read(codec, reg) >> shift) - min) & mask;
2753 if (snd_soc_volsw_is_stereo(mc))
2754 ucontrol->value.integer.value[1] =
2755 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
2759 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2762 * snd_soc_put_volsw_sx - double mixer set callback
2763 * @kcontrol: mixer control
2764 * @uinfo: control element information
2766 * Callback to set the value of a double mixer control that spans 2 registers.
2768 * Returns 0 for success.
2770 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2771 struct snd_ctl_elem_value *ucontrol)
2773 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2774 struct soc_mixer_control *mc =
2775 (struct soc_mixer_control *)kcontrol->private_value;
2777 unsigned int reg = mc->reg;
2778 unsigned int reg2 = mc->rreg;
2779 unsigned int shift = mc->shift;
2780 unsigned int rshift = mc->rshift;
2783 int mask = (1 << (fls(min + max) - 1)) - 1;
2785 unsigned short val, val_mask, val2 = 0;
2787 val_mask = mask << shift;
2788 val = (ucontrol->value.integer.value[0] + min) & mask;
2791 if (snd_soc_update_bits_locked(codec, reg, val_mask, val))
2794 if (snd_soc_volsw_is_stereo(mc)) {
2795 val_mask = mask << rshift;
2796 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2797 val2 = val2 << rshift;
2799 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
2804 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2807 * snd_soc_info_volsw_s8 - signed mixer info callback
2808 * @kcontrol: mixer control
2809 * @uinfo: control element information
2811 * Callback to provide information about a signed mixer control.
2813 * Returns 0 for success.
2815 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2816 struct snd_ctl_elem_info *uinfo)
2818 struct soc_mixer_control *mc =
2819 (struct soc_mixer_control *)kcontrol->private_value;
2823 if (!mc->platform_max)
2824 mc->platform_max = mc->max;
2825 platform_max = mc->platform_max;
2827 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2829 uinfo->value.integer.min = 0;
2830 uinfo->value.integer.max = platform_max - min;
2833 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2836 * snd_soc_get_volsw_s8 - signed mixer get callback
2837 * @kcontrol: mixer control
2838 * @ucontrol: control element information
2840 * Callback to get the value of a signed mixer control.
2842 * Returns 0 for success.
2844 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2845 struct snd_ctl_elem_value *ucontrol)
2847 struct soc_mixer_control *mc =
2848 (struct soc_mixer_control *)kcontrol->private_value;
2849 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2850 unsigned int reg = mc->reg;
2852 int val = snd_soc_read(codec, reg);
2854 ucontrol->value.integer.value[0] =
2855 ((signed char)(val & 0xff))-min;
2856 ucontrol->value.integer.value[1] =
2857 ((signed char)((val >> 8) & 0xff))-min;
2860 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2863 * snd_soc_put_volsw_sgn - signed mixer put callback
2864 * @kcontrol: mixer control
2865 * @ucontrol: control element information
2867 * Callback to set the value of a signed mixer control.
2869 * Returns 0 for success.
2871 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2872 struct snd_ctl_elem_value *ucontrol)
2874 struct soc_mixer_control *mc =
2875 (struct soc_mixer_control *)kcontrol->private_value;
2876 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2877 unsigned int reg = mc->reg;
2881 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2882 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2884 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2886 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2889 * snd_soc_info_volsw_range - single mixer info callback with range.
2890 * @kcontrol: mixer control
2891 * @uinfo: control element information
2893 * Callback to provide information, within a range, about a single
2896 * returns 0 for success.
2898 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
2899 struct snd_ctl_elem_info *uinfo)
2901 struct soc_mixer_control *mc =
2902 (struct soc_mixer_control *)kcontrol->private_value;
2906 if (!mc->platform_max)
2907 mc->platform_max = mc->max;
2908 platform_max = mc->platform_max;
2910 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2912 uinfo->value.integer.min = 0;
2913 uinfo->value.integer.max = platform_max - min;
2917 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
2920 * snd_soc_put_volsw_range - single mixer put value callback with range.
2921 * @kcontrol: mixer control
2922 * @ucontrol: control element information
2924 * Callback to set the value, within a range, for a single mixer control.
2926 * Returns 0 for success.
2928 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2929 struct snd_ctl_elem_value *ucontrol)
2931 struct soc_mixer_control *mc =
2932 (struct soc_mixer_control *)kcontrol->private_value;
2933 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2934 unsigned int reg = mc->reg;
2935 unsigned int shift = mc->shift;
2938 unsigned int mask = (1 << fls(max)) - 1;
2939 unsigned int invert = mc->invert;
2940 unsigned int val, val_mask;
2942 val = ((ucontrol->value.integer.value[0] + min) & mask);
2945 val_mask = mask << shift;
2948 return snd_soc_update_bits_locked(codec, reg, val_mask, val);
2950 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
2953 * snd_soc_get_volsw_range - single mixer get callback with range
2954 * @kcontrol: mixer control
2955 * @ucontrol: control element information
2957 * Callback to get the value, within a range, of a single mixer control.
2959 * Returns 0 for success.
2961 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2962 struct snd_ctl_elem_value *ucontrol)
2964 struct soc_mixer_control *mc =
2965 (struct soc_mixer_control *)kcontrol->private_value;
2966 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2967 unsigned int reg = mc->reg;
2968 unsigned int shift = mc->shift;
2971 unsigned int mask = (1 << fls(max)) - 1;
2972 unsigned int invert = mc->invert;
2974 ucontrol->value.integer.value[0] =
2975 (snd_soc_read(codec, reg) >> shift) & mask;
2977 ucontrol->value.integer.value[0] =
2978 max - ucontrol->value.integer.value[0];
2979 ucontrol->value.integer.value[0] =
2980 ucontrol->value.integer.value[0] - min;
2984 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
2987 * snd_soc_limit_volume - Set new limit to an existing volume control.
2989 * @codec: where to look for the control
2990 * @name: Name of the control
2991 * @max: new maximum limit
2993 * Return 0 for success, else error.
2995 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2996 const char *name, int max)
2998 struct snd_card *card = codec->card->snd_card;
2999 struct snd_kcontrol *kctl;
3000 struct soc_mixer_control *mc;
3004 /* Sanity check for name and max */
3005 if (unlikely(!name || max <= 0))
3008 list_for_each_entry(kctl, &card->controls, list) {
3009 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
3015 mc = (struct soc_mixer_control *)kctl->private_value;
3016 if (max <= mc->max) {
3017 mc->platform_max = max;
3023 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
3025 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
3026 struct snd_ctl_elem_info *uinfo)
3028 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3029 struct soc_bytes *params = (void *)kcontrol->private_value;
3031 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3032 uinfo->count = params->num_regs * codec->val_bytes;
3036 EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3038 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3039 struct snd_ctl_elem_value *ucontrol)
3041 struct soc_bytes *params = (void *)kcontrol->private_value;
3042 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3045 if (codec->using_regmap)
3046 ret = regmap_raw_read(codec->control_data, params->base,
3047 ucontrol->value.bytes.data,
3048 params->num_regs * codec->val_bytes);
3052 /* Hide any masked bytes to ensure consistent data reporting */
3053 if (ret == 0 && params->mask) {
3054 switch (codec->val_bytes) {
3056 ucontrol->value.bytes.data[0] &= ~params->mask;
3059 ((u16 *)(&ucontrol->value.bytes.data))[0]
3063 ((u32 *)(&ucontrol->value.bytes.data))[0]
3073 EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3075 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3076 struct snd_ctl_elem_value *ucontrol)
3078 struct soc_bytes *params = (void *)kcontrol->private_value;
3079 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3084 if (!codec->using_regmap)
3087 data = ucontrol->value.bytes.data;
3088 len = params->num_regs * codec->val_bytes;
3091 * If we've got a mask then we need to preserve the register
3092 * bits. We shouldn't modify the incoming data so take a
3096 ret = regmap_read(codec->control_data, params->base, &val);
3100 val &= params->mask;
3102 data = kmemdup(data, len, GFP_KERNEL);
3106 switch (codec->val_bytes) {
3108 ((u8 *)data)[0] &= ~params->mask;
3109 ((u8 *)data)[0] |= val;
3112 ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
3113 ((u16 *)data)[0] |= cpu_to_be16(val);
3116 ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
3117 ((u32 *)data)[0] |= cpu_to_be32(val);
3124 ret = regmap_raw_write(codec->control_data, params->base,
3132 EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
3135 * snd_soc_info_xr_sx - signed multi register info callback
3136 * @kcontrol: mreg control
3137 * @uinfo: control element information
3139 * Callback to provide information of a control that can
3140 * span multiple codec registers which together
3141 * forms a single signed value in a MSB/LSB manner.
3143 * Returns 0 for success.
3145 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
3146 struct snd_ctl_elem_info *uinfo)
3148 struct soc_mreg_control *mc =
3149 (struct soc_mreg_control *)kcontrol->private_value;
3150 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3152 uinfo->value.integer.min = mc->min;
3153 uinfo->value.integer.max = mc->max;
3157 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3160 * snd_soc_get_xr_sx - signed multi register get callback
3161 * @kcontrol: mreg control
3162 * @ucontrol: control element information
3164 * Callback to get the value of a control that can span
3165 * multiple codec registers which together forms a single
3166 * signed value in a MSB/LSB manner. The control supports
3167 * specifying total no of bits used to allow for bitfields
3168 * across the multiple codec registers.
3170 * Returns 0 for success.
3172 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3173 struct snd_ctl_elem_value *ucontrol)
3175 struct soc_mreg_control *mc =
3176 (struct soc_mreg_control *)kcontrol->private_value;
3177 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3178 unsigned int regbase = mc->regbase;
3179 unsigned int regcount = mc->regcount;
3180 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3181 unsigned int regwmask = (1<<regwshift)-1;
3182 unsigned int invert = mc->invert;
3183 unsigned long mask = (1UL<<mc->nbits)-1;
3187 unsigned long regval;
3190 for (i = 0; i < regcount; i++) {
3191 regval = snd_soc_read(codec, regbase+i) & regwmask;
3192 val |= regval << (regwshift*(regcount-i-1));
3195 if (min < 0 && val > max)
3199 ucontrol->value.integer.value[0] = val;
3203 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3206 * snd_soc_put_xr_sx - signed multi register get callback
3207 * @kcontrol: mreg control
3208 * @ucontrol: control element information
3210 * Callback to set the value of a control that can span
3211 * multiple codec registers which together forms a single
3212 * signed value in a MSB/LSB manner. The control supports
3213 * specifying total no of bits used to allow for bitfields
3214 * across the multiple codec registers.
3216 * Returns 0 for success.
3218 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3219 struct snd_ctl_elem_value *ucontrol)
3221 struct soc_mreg_control *mc =
3222 (struct soc_mreg_control *)kcontrol->private_value;
3223 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3224 unsigned int regbase = mc->regbase;
3225 unsigned int regcount = mc->regcount;
3226 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3227 unsigned int regwmask = (1<<regwshift)-1;
3228 unsigned int invert = mc->invert;
3229 unsigned long mask = (1UL<<mc->nbits)-1;
3231 long val = ucontrol->value.integer.value[0];
3232 unsigned int i, regval, regmask;
3238 for (i = 0; i < regcount; i++) {
3239 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3240 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3241 err = snd_soc_update_bits_locked(codec, regbase+i,
3249 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3252 * snd_soc_get_strobe - strobe get callback
3253 * @kcontrol: mixer control
3254 * @ucontrol: control element information
3256 * Callback get the value of a strobe mixer control.
3258 * Returns 0 for success.
3260 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3261 struct snd_ctl_elem_value *ucontrol)
3263 struct soc_mixer_control *mc =
3264 (struct soc_mixer_control *)kcontrol->private_value;
3265 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3266 unsigned int reg = mc->reg;
3267 unsigned int shift = mc->shift;
3268 unsigned int mask = 1 << shift;
3269 unsigned int invert = mc->invert != 0;
3270 unsigned int val = snd_soc_read(codec, reg) & mask;
3272 if (shift != 0 && val != 0)
3274 ucontrol->value.enumerated.item[0] = val ^ invert;
3278 EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3281 * snd_soc_put_strobe - strobe put callback
3282 * @kcontrol: mixer control
3283 * @ucontrol: control element information
3285 * Callback strobe a register bit to high then low (or the inverse)
3286 * in one pass of a single mixer enum control.
3288 * Returns 1 for success.
3290 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3291 struct snd_ctl_elem_value *ucontrol)
3293 struct soc_mixer_control *mc =
3294 (struct soc_mixer_control *)kcontrol->private_value;
3295 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3296 unsigned int reg = mc->reg;
3297 unsigned int shift = mc->shift;
3298 unsigned int mask = 1 << shift;
3299 unsigned int invert = mc->invert != 0;
3300 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3301 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3302 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3305 err = snd_soc_update_bits_locked(codec, reg, mask, val1);
3309 err = snd_soc_update_bits_locked(codec, reg, mask, val2);
3312 EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3315 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3317 * @clk_id: DAI specific clock ID
3318 * @freq: new clock frequency in Hz
3319 * @dir: new clock direction - input/output.
3321 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3323 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
3324 unsigned int freq, int dir)
3326 if (dai->driver && dai->driver->ops->set_sysclk)
3327 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
3328 else if (dai->codec && dai->codec->driver->set_sysclk)
3329 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
3334 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
3337 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3339 * @clk_id: DAI specific clock ID
3340 * @source: Source for the clock
3341 * @freq: new clock frequency in Hz
3342 * @dir: new clock direction - input/output.
3344 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3346 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
3347 int source, unsigned int freq, int dir)
3349 if (codec->driver->set_sysclk)
3350 return codec->driver->set_sysclk(codec, clk_id, source,
3355 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
3358 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3360 * @div_id: DAI specific clock divider ID
3361 * @div: new clock divisor.
3363 * Configures the clock dividers. This is used to derive the best DAI bit and
3364 * frame clocks from the system or master clock. It's best to set the DAI bit
3365 * and frame clocks as low as possible to save system power.
3367 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
3368 int div_id, int div)
3370 if (dai->driver && dai->driver->ops->set_clkdiv)
3371 return dai->driver->ops->set_clkdiv(dai, div_id, div);
3375 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
3378 * snd_soc_dai_set_pll - configure DAI PLL.
3380 * @pll_id: DAI specific PLL ID
3381 * @source: DAI specific source for the PLL
3382 * @freq_in: PLL input clock frequency in Hz
3383 * @freq_out: requested PLL output clock frequency in Hz
3385 * Configures and enables PLL to generate output clock based on input clock.
3387 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
3388 unsigned int freq_in, unsigned int freq_out)
3390 if (dai->driver && dai->driver->ops->set_pll)
3391 return dai->driver->ops->set_pll(dai, pll_id, source,
3393 else if (dai->codec && dai->codec->driver->set_pll)
3394 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
3399 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
3402 * snd_soc_codec_set_pll - configure codec PLL.
3404 * @pll_id: DAI specific PLL ID
3405 * @source: DAI specific source for the PLL
3406 * @freq_in: PLL input clock frequency in Hz
3407 * @freq_out: requested PLL output clock frequency in Hz
3409 * Configures and enables PLL to generate output clock based on input clock.
3411 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
3412 unsigned int freq_in, unsigned int freq_out)
3414 if (codec->driver->set_pll)
3415 return codec->driver->set_pll(codec, pll_id, source,
3420 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
3423 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3425 * @fmt: SND_SOC_DAIFMT_ format value.
3427 * Configures the DAI hardware format and clocking.
3429 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3431 if (dai->driver == NULL)
3433 if (dai->driver->ops->set_fmt == NULL)
3435 return dai->driver->ops->set_fmt(dai, fmt);
3437 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3440 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3442 * @tx_mask: bitmask representing active TX slots.
3443 * @rx_mask: bitmask representing active RX slots.
3444 * @slots: Number of slots in use.
3445 * @slot_width: Width in bits for each slot.
3447 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3450 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
3451 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
3453 if (dai->driver && dai->driver->ops->set_tdm_slot)
3454 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
3459 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
3462 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3464 * @tx_num: how many TX channels
3465 * @tx_slot: pointer to an array which imply the TX slot number channel
3467 * @rx_num: how many RX channels
3468 * @rx_slot: pointer to an array which imply the RX slot number channel
3471 * configure the relationship between channel number and TDM slot number.
3473 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
3474 unsigned int tx_num, unsigned int *tx_slot,
3475 unsigned int rx_num, unsigned int *rx_slot)
3477 if (dai->driver && dai->driver->ops->set_channel_map)
3478 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
3483 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
3486 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3488 * @tristate: tristate enable
3490 * Tristates the DAI so that others can use it.
3492 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
3494 if (dai->driver && dai->driver->ops->set_tristate)
3495 return dai->driver->ops->set_tristate(dai, tristate);
3499 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
3502 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3504 * @mute: mute enable
3506 * Mutes the DAI DAC.
3508 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
3510 if (dai->driver && dai->driver->ops->digital_mute)
3511 return dai->driver->ops->digital_mute(dai, mute);
3515 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3518 * snd_soc_register_card - Register a card with the ASoC core
3520 * @card: Card to register
3523 int snd_soc_register_card(struct snd_soc_card *card)
3527 if (!card->name || !card->dev)
3530 for (i = 0; i < card->num_links; i++) {
3531 struct snd_soc_dai_link *link = &card->dai_link[i];
3534 * Codec must be specified by 1 of name or OF node,
3535 * not both or neither.
3537 if (!!link->codec_name == !!link->codec_of_node) {
3539 "Neither/both codec name/of_node are set for %s\n",
3543 /* Codec DAI name must be specified */
3544 if (!link->codec_dai_name) {
3545 dev_err(card->dev, "codec_dai_name not set for %s\n",
3551 * Platform may be specified by either name or OF node, but
3552 * can be left unspecified, and a dummy platform will be used.
3554 if (link->platform_name && link->platform_of_node) {
3556 "Both platform name/of_node are set for %s\n", link->name);
3561 * CPU device may be specified by either name or OF node, but
3562 * can be left unspecified, and will be matched based on DAI
3565 if (link->cpu_name && link->cpu_of_node) {
3567 "Neither/both cpu name/of_node are set for %s\n",
3572 * At least one of CPU DAI name or CPU device name/node must be
3575 if (!link->cpu_dai_name &&
3576 !(link->cpu_name || link->cpu_of_node)) {
3578 "Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3584 dev_set_drvdata(card->dev, card);
3586 snd_soc_initialize_card_lists(card);
3588 soc_init_card_debugfs(card);
3590 card->rtd = devm_kzalloc(card->dev,
3591 sizeof(struct snd_soc_pcm_runtime) *
3592 (card->num_links + card->num_aux_devs),
3594 if (card->rtd == NULL)
3597 card->rtd_aux = &card->rtd[card->num_links];
3599 for (i = 0; i < card->num_links; i++)
3600 card->rtd[i].dai_link = &card->dai_link[i];
3602 INIT_LIST_HEAD(&card->list);
3603 INIT_LIST_HEAD(&card->dapm_dirty);
3604 card->instantiated = 0;
3605 mutex_init(&card->mutex);
3606 mutex_init(&card->dapm_mutex);
3608 ret = snd_soc_instantiate_card(card);
3610 soc_cleanup_card_debugfs(card);
3614 EXPORT_SYMBOL_GPL(snd_soc_register_card);
3617 * snd_soc_unregister_card - Unregister a card with the ASoC core
3619 * @card: Card to unregister
3622 int snd_soc_unregister_card(struct snd_soc_card *card)
3624 if (card->instantiated)
3625 soc_cleanup_card_resources(card);
3626 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
3630 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
3633 * Simplify DAI link configuration by removing ".-1" from device names
3634 * and sanitizing names.
3636 static char *fmt_single_name(struct device *dev, int *id)
3638 char *found, name[NAME_SIZE];
3641 if (dev_name(dev) == NULL)
3644 strlcpy(name, dev_name(dev), NAME_SIZE);
3646 /* are we a "%s.%d" name (platform and SPI components) */
3647 found = strstr(name, dev->driver->name);
3650 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3652 /* discard ID from name if ID == -1 */
3654 found[strlen(dev->driver->name)] = '\0';
3658 /* I2C component devices are named "bus-addr" */
3659 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3660 char tmp[NAME_SIZE];
3662 /* create unique ID number from I2C addr and bus */
3663 *id = ((id1 & 0xffff) << 16) + id2;
3665 /* sanitize component name for DAI link creation */
3666 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
3667 strlcpy(name, tmp, NAME_SIZE);
3672 return kstrdup(name, GFP_KERNEL);
3676 * Simplify DAI link naming for single devices with multiple DAIs by removing
3677 * any ".-1" and using the DAI name (instead of device name).
3679 static inline char *fmt_multiple_name(struct device *dev,
3680 struct snd_soc_dai_driver *dai_drv)
3682 if (dai_drv->name == NULL) {
3683 pr_err("asoc: error - multiple DAI %s registered with no name\n",
3688 return kstrdup(dai_drv->name, GFP_KERNEL);
3692 * snd_soc_register_dai - Register a DAI with the ASoC core
3694 * @dai: DAI to register
3696 int snd_soc_register_dai(struct device *dev,
3697 struct snd_soc_dai_driver *dai_drv)
3699 struct snd_soc_codec *codec;
3700 struct snd_soc_dai *dai;
3702 dev_dbg(dev, "dai register %s\n", dev_name(dev));
3704 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3708 /* create DAI component name */
3709 dai->name = fmt_single_name(dev, &dai->id);
3710 if (dai->name == NULL) {
3716 dai->driver = dai_drv;
3717 dai->dapm.dev = dev;
3718 if (!dai->driver->ops)
3719 dai->driver->ops = &null_dai_ops;
3721 mutex_lock(&client_mutex);
3723 list_for_each_entry(codec, &codec_list, list) {
3724 if (codec->dev == dev) {
3725 dev_dbg(dev, "Mapped DAI %s to CODEC %s\n",
3726 dai->name, codec->name);
3733 dai->dapm.idle_bias_off = 1;
3735 list_add(&dai->list, &dai_list);
3737 mutex_unlock(&client_mutex);
3739 pr_debug("Registered DAI '%s'\n", dai->name);
3743 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3746 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3748 * @dai: DAI to unregister
3750 void snd_soc_unregister_dai(struct device *dev)
3752 struct snd_soc_dai *dai;
3754 list_for_each_entry(dai, &dai_list, list) {
3755 if (dev == dai->dev)
3761 mutex_lock(&client_mutex);
3762 list_del(&dai->list);
3763 mutex_unlock(&client_mutex);
3765 pr_debug("Unregistered DAI '%s'\n", dai->name);
3769 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3772 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3774 * @dai: Array of DAIs to register
3775 * @count: Number of DAIs
3777 int snd_soc_register_dais(struct device *dev,
3778 struct snd_soc_dai_driver *dai_drv, size_t count)
3780 struct snd_soc_codec *codec;
3781 struct snd_soc_dai *dai;
3784 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3786 for (i = 0; i < count; i++) {
3788 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3794 /* create DAI component name */
3795 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3796 if (dai->name == NULL) {
3803 dai->driver = &dai_drv[i];
3804 if (dai->driver->id)
3805 dai->id = dai->driver->id;
3808 dai->dapm.dev = dev;
3809 if (!dai->driver->ops)
3810 dai->driver->ops = &null_dai_ops;
3812 mutex_lock(&client_mutex);
3814 list_for_each_entry(codec, &codec_list, list) {
3815 if (codec->dev == dev) {
3816 dev_dbg(dev, "Mapped DAI %s to CODEC %s\n",
3817 dai->name, codec->name);
3824 dai->dapm.idle_bias_off = 1;
3826 list_add(&dai->list, &dai_list);
3828 mutex_unlock(&client_mutex);
3830 pr_debug("Registered DAI '%s'\n", dai->name);
3836 for (i--; i >= 0; i--)
3837 snd_soc_unregister_dai(dev);
3841 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3844 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3846 * @dai: Array of DAIs to unregister
3847 * @count: Number of DAIs
3849 void snd_soc_unregister_dais(struct device *dev, size_t count)
3853 for (i = 0; i < count; i++)
3854 snd_soc_unregister_dai(dev);
3856 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3859 * snd_soc_register_platform - Register a platform with the ASoC core
3861 * @platform: platform to register
3863 int snd_soc_register_platform(struct device *dev,
3864 struct snd_soc_platform_driver *platform_drv)
3866 struct snd_soc_platform *platform;
3868 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3870 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3871 if (platform == NULL)
3874 /* create platform component name */
3875 platform->name = fmt_single_name(dev, &platform->id);
3876 if (platform->name == NULL) {
3881 platform->dev = dev;
3882 platform->driver = platform_drv;
3883 platform->dapm.dev = dev;
3884 platform->dapm.platform = platform;
3885 platform->dapm.stream_event = platform_drv->stream_event;
3886 mutex_init(&platform->mutex);
3888 mutex_lock(&client_mutex);
3889 list_add(&platform->list, &platform_list);
3890 mutex_unlock(&client_mutex);
3892 pr_debug("Registered platform '%s'\n", platform->name);
3896 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3899 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3901 * @platform: platform to unregister
3903 void snd_soc_unregister_platform(struct device *dev)
3905 struct snd_soc_platform *platform;
3907 list_for_each_entry(platform, &platform_list, list) {
3908 if (dev == platform->dev)
3914 mutex_lock(&client_mutex);
3915 list_del(&platform->list);
3916 mutex_unlock(&client_mutex);
3918 pr_debug("Unregistered platform '%s'\n", platform->name);
3919 kfree(platform->name);
3922 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3924 static u64 codec_format_map[] = {
3925 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3926 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3927 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3928 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3929 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3930 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3931 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3932 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3933 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3934 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3935 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3936 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3937 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3938 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3939 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3940 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3943 /* Fix up the DAI formats for endianness: codecs don't actually see
3944 * the endianness of the data but we're using the CPU format
3945 * definitions which do need to include endianness so we ensure that
3946 * codec DAIs always have both big and little endian variants set.
3948 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3952 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3953 if (stream->formats & codec_format_map[i])
3954 stream->formats |= codec_format_map[i];
3958 * snd_soc_register_codec - Register a codec with the ASoC core
3960 * @codec: codec to register
3962 int snd_soc_register_codec(struct device *dev,
3963 const struct snd_soc_codec_driver *codec_drv,
3964 struct snd_soc_dai_driver *dai_drv,
3968 struct snd_soc_codec *codec;
3971 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3973 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3977 /* create CODEC component name */
3978 codec->name = fmt_single_name(dev, &codec->id);
3979 if (codec->name == NULL) {
3984 if (codec_drv->compress_type)
3985 codec->compress_type = codec_drv->compress_type;
3987 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3989 codec->write = codec_drv->write;
3990 codec->read = codec_drv->read;
3991 codec->volatile_register = codec_drv->volatile_register;
3992 codec->readable_register = codec_drv->readable_register;
3993 codec->writable_register = codec_drv->writable_register;
3994 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
3995 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3996 codec->dapm.dev = dev;
3997 codec->dapm.codec = codec;
3998 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3999 codec->dapm.stream_event = codec_drv->stream_event;
4001 codec->driver = codec_drv;
4002 codec->num_dai = num_dai;
4003 mutex_init(&codec->mutex);
4005 /* allocate CODEC register cache */
4006 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
4007 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
4008 codec->reg_size = reg_size;
4009 /* it is necessary to make a copy of the default register cache
4010 * because in the case of using a compression type that requires
4011 * the default register cache to be marked as __devinitconst the
4012 * kernel might have freed the array by the time we initialize
4015 if (codec_drv->reg_cache_default) {
4016 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
4017 reg_size, GFP_KERNEL);
4018 if (!codec->reg_def_copy) {
4025 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
4026 if (!codec->volatile_register)
4027 codec->volatile_register = snd_soc_default_volatile_register;
4028 if (!codec->readable_register)
4029 codec->readable_register = snd_soc_default_readable_register;
4030 if (!codec->writable_register)
4031 codec->writable_register = snd_soc_default_writable_register;
4034 for (i = 0; i < num_dai; i++) {
4035 fixup_codec_formats(&dai_drv[i].playback);
4036 fixup_codec_formats(&dai_drv[i].capture);
4039 mutex_lock(&client_mutex);
4040 list_add(&codec->list, &codec_list);
4041 mutex_unlock(&client_mutex);
4043 /* register any DAIs */
4045 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4047 dev_err(codec->dev, "Failed to regster DAIs: %d\n",
4051 pr_debug("Registered codec '%s'\n", codec->name);
4055 kfree(codec->reg_def_copy);
4056 codec->reg_def_copy = NULL;
4061 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
4064 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4066 * @codec: codec to unregister
4068 void snd_soc_unregister_codec(struct device *dev)
4070 struct snd_soc_codec *codec;
4073 list_for_each_entry(codec, &codec_list, list) {
4074 if (dev == codec->dev)
4081 for (i = 0; i < codec->num_dai; i++)
4082 snd_soc_unregister_dai(dev);
4084 mutex_lock(&client_mutex);
4085 list_del(&codec->list);
4086 mutex_unlock(&client_mutex);
4088 pr_debug("Unregistered codec '%s'\n", codec->name);
4090 snd_soc_cache_exit(codec);
4091 kfree(codec->reg_def_copy);
4095 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4097 /* Retrieve a card's name from device tree */
4098 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4099 const char *propname)
4101 struct device_node *np = card->dev->of_node;
4104 ret = of_property_read_string_index(np, propname, 0, &card->name);
4106 * EINVAL means the property does not exist. This is fine providing
4107 * card->name was previously set, which is checked later in
4108 * snd_soc_register_card.
4110 if (ret < 0 && ret != -EINVAL) {
4112 "Property '%s' could not be read: %d\n",
4119 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4121 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4122 const char *propname)
4124 struct device_node *np = card->dev->of_node;
4126 struct snd_soc_dapm_route *routes;
4129 num_routes = of_property_count_strings(np, propname);
4130 if (num_routes < 0 || num_routes & 1) {
4132 "Property '%s' does not exist or its length is not even\n",
4139 "Property '%s's length is zero\n",
4144 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
4148 "Could not allocate DAPM route table\n");
4152 for (i = 0; i < num_routes; i++) {
4153 ret = of_property_read_string_index(np, propname,
4154 2 * i, &routes[i].sink);
4157 "Property '%s' index %d could not be read: %d\n",
4158 propname, 2 * i, ret);
4162 ret = of_property_read_string_index(np, propname,
4163 (2 * i) + 1, &routes[i].source);
4166 "Property '%s' index %d could not be read: %d\n",
4167 propname, (2 * i) + 1, ret);
4173 card->num_dapm_routes = num_routes;
4174 card->dapm_routes = routes;
4178 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4180 static int __init snd_soc_init(void)
4182 #ifdef CONFIG_DEBUG_FS
4183 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
4184 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
4185 pr_warn("ASoC: Failed to create debugfs directory\n");
4186 snd_soc_debugfs_root = NULL;
4189 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
4191 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4193 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
4195 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4197 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
4198 &platform_list_fops))
4199 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4202 snd_soc_util_init();
4204 return platform_driver_register(&soc_driver);
4206 module_init(snd_soc_init);
4208 static void __exit snd_soc_exit(void)
4210 snd_soc_util_exit();
4212 #ifdef CONFIG_DEBUG_FS
4213 debugfs_remove_recursive(snd_soc_debugfs_root);
4215 platform_driver_unregister(&soc_driver);
4217 module_exit(snd_soc_exit);
4219 /* Module information */
4220 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4221 MODULE_DESCRIPTION("ALSA SoC Core");
4222 MODULE_LICENSE("GPL");
4223 MODULE_ALIAS("platform:soc-audio");