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/initval.h>
44 #define CREATE_TRACE_POINTS
45 #include <trace/events/asoc.h>
49 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
51 #ifdef CONFIG_DEBUG_FS
52 struct dentry *snd_soc_debugfs_root;
53 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
56 static DEFINE_MUTEX(client_mutex);
57 static LIST_HEAD(card_list);
58 static LIST_HEAD(dai_list);
59 static LIST_HEAD(platform_list);
60 static LIST_HEAD(codec_list);
62 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
65 * This is a timeout to do a DAPM powerdown after a stream is closed().
66 * It can be used to eliminate pops between different playback streams, e.g.
67 * between two audio tracks.
69 static int pmdown_time = 5000;
70 module_param(pmdown_time, int, 0);
71 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
73 /* returns the minimum number of bytes needed to represent
74 * a particular given value */
75 static int min_bytes_needed(unsigned long val)
80 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
83 c = (sizeof val * 8) - c;
91 /* fill buf which is 'len' bytes with a formatted
92 * string of the form 'reg: value\n' */
93 static int format_register_str(struct snd_soc_codec *codec,
94 unsigned int reg, char *buf, size_t len)
96 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
97 int regsize = codec->driver->reg_word_size * 2;
100 char regbuf[regsize + 1];
102 /* since tmpbuf is allocated on the stack, warn the callers if they
103 * try to abuse this function */
106 /* +2 for ': ' and + 1 for '\n' */
107 if (wordsize + regsize + 2 + 1 != len)
110 ret = snd_soc_read(codec, reg);
112 memset(regbuf, 'X', regsize);
113 regbuf[regsize] = '\0';
115 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
118 /* prepare the buffer */
119 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
120 /* copy it back to the caller without the '\0' */
121 memcpy(buf, tmpbuf, len);
126 /* codec register dump */
127 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
128 size_t count, loff_t pos)
131 int wordsize, regsize;
136 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
137 regsize = codec->driver->reg_word_size * 2;
139 len = wordsize + regsize + 2 + 1;
141 if (!codec->driver->reg_cache_size)
144 if (codec->driver->reg_cache_step)
145 step = codec->driver->reg_cache_step;
147 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
148 if (!snd_soc_codec_readable_register(codec, i))
150 if (codec->driver->display_register) {
151 count += codec->driver->display_register(codec, buf + count,
152 PAGE_SIZE - count, i);
154 /* only support larger than PAGE_SIZE bytes debugfs
155 * entries for the default case */
157 if (total + len >= count - 1)
159 format_register_str(codec, i, buf + total, len);
166 total = min(total, count - 1);
171 static ssize_t codec_reg_show(struct device *dev,
172 struct device_attribute *attr, char *buf)
174 struct snd_soc_pcm_runtime *rtd =
175 container_of(dev, struct snd_soc_pcm_runtime, dev);
177 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
180 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
182 static ssize_t pmdown_time_show(struct device *dev,
183 struct device_attribute *attr, char *buf)
185 struct snd_soc_pcm_runtime *rtd =
186 container_of(dev, struct snd_soc_pcm_runtime, dev);
188 return sprintf(buf, "%ld\n", rtd->pmdown_time);
191 static ssize_t pmdown_time_set(struct device *dev,
192 struct device_attribute *attr,
193 const char *buf, size_t count)
195 struct snd_soc_pcm_runtime *rtd =
196 container_of(dev, struct snd_soc_pcm_runtime, dev);
199 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
206 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
208 #ifdef CONFIG_DEBUG_FS
209 static int codec_reg_open_file(struct inode *inode, struct file *file)
211 file->private_data = inode->i_private;
215 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
216 size_t count, loff_t *ppos)
219 struct snd_soc_codec *codec = file->private_data;
222 if (*ppos < 0 || !count)
225 buf = kmalloc(count, GFP_KERNEL);
229 ret = soc_codec_reg_show(codec, buf, count, *ppos);
231 if (copy_to_user(user_buf, buf, ret)) {
242 static ssize_t codec_reg_write_file(struct file *file,
243 const char __user *user_buf, size_t count, loff_t *ppos)
248 unsigned long reg, value;
249 struct snd_soc_codec *codec = file->private_data;
251 buf_size = min(count, (sizeof(buf)-1));
252 if (copy_from_user(buf, user_buf, buf_size))
256 while (*start == ' ')
258 reg = simple_strtoul(start, &start, 16);
259 while (*start == ' ')
261 if (strict_strtoul(start, 16, &value))
264 /* Userspace has been fiddling around behind the kernel's back */
265 add_taint(TAINT_USER);
267 snd_soc_write(codec, reg, value);
271 static const struct file_operations codec_reg_fops = {
272 .open = codec_reg_open_file,
273 .read = codec_reg_read_file,
274 .write = codec_reg_write_file,
275 .llseek = default_llseek,
278 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
280 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
282 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
284 if (!codec->debugfs_codec_root) {
286 "ASoC: Failed to create codec debugfs directory\n");
290 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
292 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
295 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
296 codec->debugfs_codec_root,
297 codec, &codec_reg_fops);
298 if (!codec->debugfs_reg)
300 "ASoC: Failed to create codec register debugfs file\n");
302 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
305 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
307 debugfs_remove_recursive(codec->debugfs_codec_root);
310 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
311 size_t count, loff_t *ppos)
313 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
314 ssize_t len, ret = 0;
315 struct snd_soc_codec *codec;
320 list_for_each_entry(codec, &codec_list, list) {
321 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
325 if (ret > PAGE_SIZE) {
332 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
339 static const struct file_operations codec_list_fops = {
340 .read = codec_list_read_file,
341 .llseek = default_llseek,/* read accesses f_pos */
344 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
345 size_t count, loff_t *ppos)
347 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
348 ssize_t len, ret = 0;
349 struct snd_soc_dai *dai;
354 list_for_each_entry(dai, &dai_list, list) {
355 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
358 if (ret > PAGE_SIZE) {
364 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
371 static const struct file_operations dai_list_fops = {
372 .read = dai_list_read_file,
373 .llseek = default_llseek,/* read accesses f_pos */
376 static ssize_t platform_list_read_file(struct file *file,
377 char __user *user_buf,
378 size_t count, loff_t *ppos)
380 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
381 ssize_t len, ret = 0;
382 struct snd_soc_platform *platform;
387 list_for_each_entry(platform, &platform_list, list) {
388 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
392 if (ret > PAGE_SIZE) {
398 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
405 static const struct file_operations platform_list_fops = {
406 .read = platform_list_read_file,
407 .llseek = default_llseek,/* read accesses f_pos */
410 static void soc_init_card_debugfs(struct snd_soc_card *card)
412 card->debugfs_card_root = debugfs_create_dir(card->name,
413 snd_soc_debugfs_root);
414 if (!card->debugfs_card_root) {
416 "ASoC: Failed to create card debugfs directory\n");
420 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
421 card->debugfs_card_root,
423 if (!card->debugfs_pop_time)
425 "Failed to create pop time debugfs file\n");
428 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
430 debugfs_remove_recursive(card->debugfs_card_root);
435 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
439 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
443 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
447 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
452 #ifdef CONFIG_SND_SOC_AC97_BUS
453 /* unregister ac97 codec */
454 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
456 if (codec->ac97->dev.bus)
457 device_unregister(&codec->ac97->dev);
461 /* stop no dev release warning */
462 static void soc_ac97_device_release(struct device *dev){}
464 /* register ac97 codec to bus */
465 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
469 codec->ac97->dev.bus = &ac97_bus_type;
470 codec->ac97->dev.parent = codec->card->dev;
471 codec->ac97->dev.release = soc_ac97_device_release;
473 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
474 codec->card->snd_card->number, 0, codec->name);
475 err = device_register(&codec->ac97->dev);
477 snd_printk(KERN_ERR "Can't register ac97 bus\n");
478 codec->ac97->dev.bus = NULL;
485 #ifdef CONFIG_PM_SLEEP
486 /* powers down audio subsystem for suspend */
487 int snd_soc_suspend(struct device *dev)
489 struct snd_soc_card *card = dev_get_drvdata(dev);
490 struct snd_soc_codec *codec;
493 /* If the initialization of this soc device failed, there is no codec
494 * associated with it. Just bail out in this case.
496 if (list_empty(&card->codec_dev_list))
499 /* Due to the resume being scheduled into a workqueue we could
500 * suspend before that's finished - wait for it to complete.
502 snd_power_lock(card->snd_card);
503 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
504 snd_power_unlock(card->snd_card);
506 /* we're going to block userspace touching us until resume completes */
507 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
509 /* mute any active DACs */
510 for (i = 0; i < card->num_rtd; i++) {
511 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
512 struct snd_soc_dai_driver *drv = dai->driver;
514 if (card->rtd[i].dai_link->ignore_suspend)
517 if (drv->ops->digital_mute && dai->playback_active)
518 drv->ops->digital_mute(dai, 1);
521 /* suspend all pcms */
522 for (i = 0; i < card->num_rtd; i++) {
523 if (card->rtd[i].dai_link->ignore_suspend)
526 snd_pcm_suspend_all(card->rtd[i].pcm);
529 if (card->suspend_pre)
530 card->suspend_pre(card);
532 for (i = 0; i < card->num_rtd; i++) {
533 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
534 struct snd_soc_platform *platform = card->rtd[i].platform;
536 if (card->rtd[i].dai_link->ignore_suspend)
539 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
540 cpu_dai->driver->suspend(cpu_dai);
541 if (platform->driver->suspend && !platform->suspended) {
542 platform->driver->suspend(cpu_dai);
543 platform->suspended = 1;
547 /* close any waiting streams and save state */
548 for (i = 0; i < card->num_rtd; i++) {
549 flush_delayed_work_sync(&card->rtd[i].delayed_work);
550 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
553 for (i = 0; i < card->num_rtd; i++) {
554 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
556 if (card->rtd[i].dai_link->ignore_suspend)
559 if (driver->playback.stream_name != NULL)
560 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
561 SND_SOC_DAPM_STREAM_SUSPEND);
563 if (driver->capture.stream_name != NULL)
564 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
565 SND_SOC_DAPM_STREAM_SUSPEND);
568 /* suspend all CODECs */
569 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
570 /* If there are paths active then the CODEC will be held with
571 * bias _ON and should not be suspended. */
572 if (!codec->suspended && codec->driver->suspend) {
573 switch (codec->dapm.bias_level) {
574 case SND_SOC_BIAS_STANDBY:
575 case SND_SOC_BIAS_OFF:
576 codec->driver->suspend(codec);
577 codec->suspended = 1;
578 codec->cache_sync = 1;
581 dev_dbg(codec->dev, "CODEC is on over suspend\n");
587 for (i = 0; i < card->num_rtd; i++) {
588 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
590 if (card->rtd[i].dai_link->ignore_suspend)
593 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
594 cpu_dai->driver->suspend(cpu_dai);
597 if (card->suspend_post)
598 card->suspend_post(card);
602 EXPORT_SYMBOL_GPL(snd_soc_suspend);
604 /* deferred resume work, so resume can complete before we finished
605 * setting our codec back up, which can be very slow on I2C
607 static void soc_resume_deferred(struct work_struct *work)
609 struct snd_soc_card *card =
610 container_of(work, struct snd_soc_card, deferred_resume_work);
611 struct snd_soc_codec *codec;
614 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
615 * so userspace apps are blocked from touching us
618 dev_dbg(card->dev, "starting resume work\n");
620 /* Bring us up into D2 so that DAPM starts enabling things */
621 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
623 if (card->resume_pre)
624 card->resume_pre(card);
626 /* resume AC97 DAIs */
627 for (i = 0; i < card->num_rtd; i++) {
628 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
630 if (card->rtd[i].dai_link->ignore_suspend)
633 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
634 cpu_dai->driver->resume(cpu_dai);
637 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
638 /* If the CODEC was idle over suspend then it will have been
639 * left with bias OFF or STANDBY and suspended so we must now
640 * resume. Otherwise the suspend was suppressed.
642 if (codec->driver->resume && codec->suspended) {
643 switch (codec->dapm.bias_level) {
644 case SND_SOC_BIAS_STANDBY:
645 case SND_SOC_BIAS_OFF:
646 codec->driver->resume(codec);
647 codec->suspended = 0;
650 dev_dbg(codec->dev, "CODEC was on over suspend\n");
656 for (i = 0; i < card->num_rtd; i++) {
657 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
659 if (card->rtd[i].dai_link->ignore_suspend)
662 if (driver->playback.stream_name != NULL)
663 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
664 SND_SOC_DAPM_STREAM_RESUME);
666 if (driver->capture.stream_name != NULL)
667 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
668 SND_SOC_DAPM_STREAM_RESUME);
671 /* unmute any active DACs */
672 for (i = 0; i < card->num_rtd; i++) {
673 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
674 struct snd_soc_dai_driver *drv = dai->driver;
676 if (card->rtd[i].dai_link->ignore_suspend)
679 if (drv->ops->digital_mute && dai->playback_active)
680 drv->ops->digital_mute(dai, 0);
683 for (i = 0; i < card->num_rtd; i++) {
684 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
685 struct snd_soc_platform *platform = card->rtd[i].platform;
687 if (card->rtd[i].dai_link->ignore_suspend)
690 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
691 cpu_dai->driver->resume(cpu_dai);
692 if (platform->driver->resume && platform->suspended) {
693 platform->driver->resume(cpu_dai);
694 platform->suspended = 0;
698 if (card->resume_post)
699 card->resume_post(card);
701 dev_dbg(card->dev, "resume work completed\n");
703 /* userspace can access us now we are back as we were before */
704 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
707 /* powers up audio subsystem after a suspend */
708 int snd_soc_resume(struct device *dev)
710 struct snd_soc_card *card = dev_get_drvdata(dev);
711 int i, ac97_control = 0;
713 /* If the initialization of this soc device failed, there is no codec
714 * associated with it. Just bail out in this case.
716 if (list_empty(&card->codec_dev_list))
719 /* AC97 devices might have other drivers hanging off them so
720 * need to resume immediately. Other drivers don't have that
721 * problem and may take a substantial amount of time to resume
722 * due to I/O costs and anti-pop so handle them out of line.
724 for (i = 0; i < card->num_rtd; i++) {
725 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
726 ac97_control |= cpu_dai->driver->ac97_control;
729 dev_dbg(dev, "Resuming AC97 immediately\n");
730 soc_resume_deferred(&card->deferred_resume_work);
732 dev_dbg(dev, "Scheduling resume work\n");
733 if (!schedule_work(&card->deferred_resume_work))
734 dev_err(dev, "resume work item may be lost\n");
739 EXPORT_SYMBOL_GPL(snd_soc_resume);
741 #define snd_soc_suspend NULL
742 #define snd_soc_resume NULL
745 static const struct snd_soc_dai_ops null_dai_ops = {
748 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
750 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
751 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
752 struct snd_soc_codec *codec;
753 struct snd_soc_platform *platform;
754 struct snd_soc_dai *codec_dai, *cpu_dai;
755 const char *platform_name;
759 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
761 /* do we already have the CPU DAI for this link ? */
765 /* no, then find CPU DAI from registered DAIs*/
766 list_for_each_entry(cpu_dai, &dai_list, list) {
767 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
770 rtd->cpu_dai = cpu_dai;
773 dev_dbg(card->dev, "CPU DAI %s not registered\n",
774 dai_link->cpu_dai_name);
777 /* do we already have the CODEC for this link ? */
782 /* no, then find CODEC from registered CODECs*/
783 list_for_each_entry(codec, &codec_list, list) {
784 if (strcmp(codec->name, dai_link->codec_name))
790 * CODEC found, so find CODEC DAI from registered DAIs from
793 list_for_each_entry(codec_dai, &dai_list, list) {
794 if (codec->dev == codec_dai->dev &&
795 !strcmp(codec_dai->name,
796 dai_link->codec_dai_name)) {
798 rtd->codec_dai = codec_dai;
802 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
803 dai_link->codec_dai_name);
807 dev_dbg(card->dev, "CODEC %s not registered\n",
808 dai_link->codec_name);
811 /* do we need a platform? */
815 /* if there's no platform we match on the empty platform */
816 platform_name = dai_link->platform_name;
818 platform_name = "snd-soc-dummy";
820 /* no, then find one from the set of registered platforms */
821 list_for_each_entry(platform, &platform_list, list) {
822 if (strcmp(platform->name, platform_name))
825 rtd->platform = platform;
829 dev_dbg(card->dev, "platform %s not registered\n",
830 dai_link->platform_name);
834 /* mark rtd as complete if we found all 4 of our client devices */
835 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
842 static void soc_remove_codec(struct snd_soc_codec *codec)
846 if (codec->driver->remove) {
847 err = codec->driver->remove(codec);
850 "asoc: failed to remove %s: %d\n",
854 /* Make sure all DAPM widgets are freed */
855 snd_soc_dapm_free(&codec->dapm);
857 soc_cleanup_codec_debugfs(codec);
859 list_del(&codec->card_list);
860 module_put(codec->dev->driver->owner);
863 static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
865 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
866 struct snd_soc_codec *codec = rtd->codec;
867 struct snd_soc_platform *platform = rtd->platform;
868 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
871 /* unregister the rtd device */
872 if (rtd->dev_registered) {
873 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
874 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
875 device_unregister(&rtd->dev);
876 rtd->dev_registered = 0;
879 /* remove the CODEC DAI */
880 if (codec_dai && codec_dai->probed &&
881 codec_dai->driver->remove_order == order) {
882 if (codec_dai->driver->remove) {
883 err = codec_dai->driver->remove(codec_dai);
885 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
887 codec_dai->probed = 0;
888 list_del(&codec_dai->card_list);
891 /* remove the platform */
892 if (platform && platform->probed &&
893 platform->driver->remove_order == order) {
894 if (platform->driver->remove) {
895 err = platform->driver->remove(platform);
897 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
899 platform->probed = 0;
900 list_del(&platform->card_list);
901 module_put(platform->dev->driver->owner);
904 /* remove the CODEC */
905 if (codec && codec->probed &&
906 codec->driver->remove_order == order)
907 soc_remove_codec(codec);
909 /* remove the cpu_dai */
910 if (cpu_dai && cpu_dai->probed &&
911 cpu_dai->driver->remove_order == order) {
912 if (cpu_dai->driver->remove) {
913 err = cpu_dai->driver->remove(cpu_dai);
915 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
918 list_del(&cpu_dai->card_list);
919 module_put(cpu_dai->dev->driver->owner);
923 static void soc_remove_dai_links(struct snd_soc_card *card)
927 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
929 for (dai = 0; dai < card->num_rtd; dai++)
930 soc_remove_dai_link(card, dai, order);
935 static void soc_set_name_prefix(struct snd_soc_card *card,
936 struct snd_soc_codec *codec)
940 if (card->codec_conf == NULL)
943 for (i = 0; i < card->num_configs; i++) {
944 struct snd_soc_codec_conf *map = &card->codec_conf[i];
945 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
946 codec->name_prefix = map->name_prefix;
952 static int soc_probe_codec(struct snd_soc_card *card,
953 struct snd_soc_codec *codec)
956 const struct snd_soc_codec_driver *driver = codec->driver;
959 codec->dapm.card = card;
960 soc_set_name_prefix(card, codec);
962 if (!try_module_get(codec->dev->driver->owner))
965 soc_init_codec_debugfs(codec);
967 if (driver->dapm_widgets)
968 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
969 driver->num_dapm_widgets);
971 codec->dapm.idle_bias_off = driver->idle_bias_off;
974 ret = driver->probe(codec);
977 "asoc: failed to probe CODEC %s: %d\n",
983 if (driver->controls)
984 snd_soc_add_controls(codec, driver->controls,
985 driver->num_controls);
986 if (driver->dapm_routes)
987 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
988 driver->num_dapm_routes);
990 /* mark codec as probed and add to card codec list */
992 list_add(&codec->card_list, &card->codec_dev_list);
993 list_add(&codec->dapm.list, &card->dapm_list);
998 soc_cleanup_codec_debugfs(codec);
999 module_put(codec->dev->driver->owner);
1004 static int soc_probe_platform(struct snd_soc_card *card,
1005 struct snd_soc_platform *platform)
1008 const struct snd_soc_platform_driver *driver = platform->driver;
1010 platform->card = card;
1011 platform->dapm.card = card;
1013 if (!try_module_get(platform->dev->driver->owner))
1016 if (driver->dapm_widgets)
1017 snd_soc_dapm_new_controls(&platform->dapm,
1018 driver->dapm_widgets, driver->num_dapm_widgets);
1020 if (driver->probe) {
1021 ret = driver->probe(platform);
1023 dev_err(platform->dev,
1024 "asoc: failed to probe platform %s: %d\n",
1025 platform->name, ret);
1030 if (driver->controls)
1031 snd_soc_add_platform_controls(platform, driver->controls,
1032 driver->num_controls);
1033 if (driver->dapm_routes)
1034 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1035 driver->num_dapm_routes);
1037 /* mark platform as probed and add to card platform list */
1038 platform->probed = 1;
1039 list_add(&platform->card_list, &card->platform_dev_list);
1040 list_add(&platform->dapm.list, &card->dapm_list);
1045 module_put(platform->dev->driver->owner);
1050 static void rtd_release(struct device *dev) {}
1052 static int soc_post_component_init(struct snd_soc_card *card,
1053 struct snd_soc_codec *codec,
1054 int num, int dailess)
1056 struct snd_soc_dai_link *dai_link = NULL;
1057 struct snd_soc_aux_dev *aux_dev = NULL;
1058 struct snd_soc_pcm_runtime *rtd;
1059 const char *temp, *name;
1063 dai_link = &card->dai_link[num];
1064 rtd = &card->rtd[num];
1065 name = dai_link->name;
1067 aux_dev = &card->aux_dev[num];
1068 rtd = &card->rtd_aux[num];
1069 name = aux_dev->name;
1073 /* Make sure all DAPM widgets are instantiated */
1074 snd_soc_dapm_new_widgets(&codec->dapm);
1076 /* machine controls, routes and widgets are not prefixed */
1077 temp = codec->name_prefix;
1078 codec->name_prefix = NULL;
1080 /* do machine specific initialization */
1081 if (!dailess && dai_link->init)
1082 ret = dai_link->init(rtd);
1083 else if (dailess && aux_dev->init)
1084 ret = aux_dev->init(&codec->dapm);
1086 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1089 codec->name_prefix = temp;
1091 /* register the rtd device */
1093 rtd->dev.parent = card->dev;
1094 rtd->dev.release = rtd_release;
1095 rtd->dev.init_name = name;
1096 mutex_init(&rtd->pcm_mutex);
1097 ret = device_register(&rtd->dev);
1100 "asoc: failed to register runtime device: %d\n", ret);
1103 rtd->dev_registered = 1;
1105 /* add DAPM sysfs entries for this codec */
1106 ret = snd_soc_dapm_sys_add(&rtd->dev);
1109 "asoc: failed to add codec dapm sysfs entries: %d\n",
1112 /* add codec sysfs entries */
1113 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1116 "asoc: failed to add codec sysfs files: %d\n", ret);
1121 static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1123 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1124 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1125 struct snd_soc_codec *codec = rtd->codec;
1126 struct snd_soc_platform *platform = rtd->platform;
1127 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1130 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1131 card->name, num, order);
1133 /* config components */
1134 codec_dai->codec = codec;
1135 cpu_dai->platform = platform;
1136 codec_dai->card = card;
1137 cpu_dai->card = card;
1139 /* set default power off timeout */
1140 rtd->pmdown_time = pmdown_time;
1142 /* probe the cpu_dai */
1143 if (!cpu_dai->probed &&
1144 cpu_dai->driver->probe_order == order) {
1145 if (!try_module_get(cpu_dai->dev->driver->owner))
1148 if (cpu_dai->driver->probe) {
1149 ret = cpu_dai->driver->probe(cpu_dai);
1151 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1153 module_put(cpu_dai->dev->driver->owner);
1157 cpu_dai->probed = 1;
1158 /* mark cpu_dai as probed and add to card dai list */
1159 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1162 /* probe the CODEC */
1163 if (!codec->probed &&
1164 codec->driver->probe_order == order) {
1165 ret = soc_probe_codec(card, codec);
1170 /* probe the platform */
1171 if (!platform->probed &&
1172 platform->driver->probe_order == order) {
1173 ret = soc_probe_platform(card, platform);
1178 /* probe the CODEC DAI */
1179 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1180 if (codec_dai->driver->probe) {
1181 ret = codec_dai->driver->probe(codec_dai);
1183 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1189 /* mark codec_dai as probed and add to card dai list */
1190 codec_dai->probed = 1;
1191 list_add(&codec_dai->card_list, &card->dai_dev_list);
1194 /* complete DAI probe during last probe */
1195 if (order != SND_SOC_COMP_ORDER_LAST)
1198 ret = soc_post_component_init(card, codec, num, 0);
1202 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1204 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1206 /* create the pcm */
1207 ret = soc_new_pcm(rtd, num);
1209 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1213 /* add platform data for AC97 devices */
1214 if (rtd->codec_dai->driver->ac97_control)
1215 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1220 #ifdef CONFIG_SND_SOC_AC97_BUS
1221 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1225 /* Only instantiate AC97 if not already done by the adaptor
1226 * for the generic AC97 subsystem.
1228 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1230 * It is possible that the AC97 device is already registered to
1231 * the device subsystem. This happens when the device is created
1232 * via snd_ac97_mixer(). Currently only SoC codec that does so
1233 * is the generic AC97 glue but others migh emerge.
1235 * In those cases we don't try to register the device again.
1237 if (!rtd->codec->ac97_created)
1240 ret = soc_ac97_dev_register(rtd->codec);
1242 printk(KERN_ERR "asoc: AC97 device register failed\n");
1246 rtd->codec->ac97_registered = 1;
1251 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1253 if (codec->ac97_registered) {
1254 soc_ac97_dev_unregister(codec);
1255 codec->ac97_registered = 0;
1260 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1262 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1263 struct snd_soc_codec *codec;
1266 /* find CODEC from registered CODECs*/
1267 list_for_each_entry(codec, &codec_list, list) {
1268 if (!strcmp(codec->name, aux_dev->codec_name)) {
1269 if (codec->probed) {
1271 "asoc: codec already probed");
1278 /* codec not found */
1279 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1283 ret = soc_probe_codec(card, codec);
1287 ret = soc_post_component_init(card, codec, num, 1);
1293 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1295 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1296 struct snd_soc_codec *codec = rtd->codec;
1298 /* unregister the rtd device */
1299 if (rtd->dev_registered) {
1300 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1301 device_unregister(&rtd->dev);
1302 rtd->dev_registered = 0;
1305 if (codec && codec->probed)
1306 soc_remove_codec(codec);
1309 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1310 enum snd_soc_compress_type compress_type)
1314 if (codec->cache_init)
1317 /* override the compress_type if necessary */
1318 if (compress_type && codec->compress_type != compress_type)
1319 codec->compress_type = compress_type;
1320 ret = snd_soc_cache_init(codec);
1322 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1326 codec->cache_init = 1;
1330 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1332 struct snd_soc_codec *codec;
1333 struct snd_soc_codec_conf *codec_conf;
1334 enum snd_soc_compress_type compress_type;
1335 struct snd_soc_dai_link *dai_link;
1338 mutex_lock(&card->mutex);
1340 if (card->instantiated) {
1341 mutex_unlock(&card->mutex);
1346 for (i = 0; i < card->num_links; i++)
1347 soc_bind_dai_link(card, i);
1349 /* bind completed ? */
1350 if (card->num_rtd != card->num_links) {
1351 mutex_unlock(&card->mutex);
1355 /* initialize the register cache for each available codec */
1356 list_for_each_entry(codec, &codec_list, list) {
1357 if (codec->cache_init)
1359 /* by default we don't override the compress_type */
1361 /* check to see if we need to override the compress_type */
1362 for (i = 0; i < card->num_configs; ++i) {
1363 codec_conf = &card->codec_conf[i];
1364 if (!strcmp(codec->name, codec_conf->dev_name)) {
1365 compress_type = codec_conf->compress_type;
1366 if (compress_type && compress_type
1367 != codec->compress_type)
1371 ret = snd_soc_init_codec_cache(codec, compress_type);
1373 mutex_unlock(&card->mutex);
1378 /* card bind complete so register a sound card */
1379 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1380 card->owner, 0, &card->snd_card);
1382 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1384 mutex_unlock(&card->mutex);
1387 card->snd_card->dev = card->dev;
1389 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1390 card->dapm.dev = card->dev;
1391 card->dapm.card = card;
1392 list_add(&card->dapm.list, &card->dapm_list);
1394 #ifdef CONFIG_DEBUG_FS
1395 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1398 #ifdef CONFIG_PM_SLEEP
1399 /* deferred resume work */
1400 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1403 if (card->dapm_widgets)
1404 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1405 card->num_dapm_widgets);
1407 /* initialise the sound card only once */
1409 ret = card->probe(card);
1411 goto card_probe_error;
1414 /* early DAI link probe */
1415 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1417 for (i = 0; i < card->num_links; i++) {
1418 ret = soc_probe_dai_link(card, i, order);
1420 pr_err("asoc: failed to instantiate card %s: %d\n",
1427 for (i = 0; i < card->num_aux_devs; i++) {
1428 ret = soc_probe_aux_dev(card, i);
1430 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1432 goto probe_aux_dev_err;
1436 /* We should have a non-codec control add function but we don't */
1438 snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
1439 struct snd_soc_codec,
1442 card->num_controls);
1444 if (card->dapm_routes)
1445 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1446 card->num_dapm_routes);
1448 snd_soc_dapm_new_widgets(&card->dapm);
1450 for (i = 0; i < card->num_links; i++) {
1451 dai_link = &card->dai_link[i];
1453 if (dai_link->dai_fmt) {
1454 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1457 dev_warn(card->rtd[i].codec_dai->dev,
1458 "Failed to set DAI format: %d\n",
1461 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1464 dev_warn(card->rtd[i].cpu_dai->dev,
1465 "Failed to set DAI format: %d\n",
1470 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1472 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1473 "%s", card->long_name ? card->long_name : card->name);
1474 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1475 "%s", card->driver_name ? card->driver_name : card->name);
1476 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1477 switch (card->snd_card->driver[i]) {
1483 if (!isalnum(card->snd_card->driver[i]))
1484 card->snd_card->driver[i] = '_';
1489 if (card->late_probe) {
1490 ret = card->late_probe(card);
1492 dev_err(card->dev, "%s late_probe() failed: %d\n",
1494 goto probe_aux_dev_err;
1498 snd_soc_dapm_new_widgets(&card->dapm);
1500 if (card->fully_routed)
1501 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1502 snd_soc_dapm_auto_nc_codec_pins(codec);
1504 ret = snd_card_register(card->snd_card);
1506 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1507 goto probe_aux_dev_err;
1510 #ifdef CONFIG_SND_SOC_AC97_BUS
1511 /* register any AC97 codecs */
1512 for (i = 0; i < card->num_rtd; i++) {
1513 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1515 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1517 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1518 goto probe_aux_dev_err;
1523 card->instantiated = 1;
1524 snd_soc_dapm_sync(&card->dapm);
1525 mutex_unlock(&card->mutex);
1529 for (i = 0; i < card->num_aux_devs; i++)
1530 soc_remove_aux_dev(card, i);
1533 soc_remove_dai_links(card);
1539 snd_card_free(card->snd_card);
1541 mutex_unlock(&card->mutex);
1545 * Attempt to initialise any uninitialised cards. Must be called with
1548 static void snd_soc_instantiate_cards(void)
1550 struct snd_soc_card *card;
1551 list_for_each_entry(card, &card_list, list)
1552 snd_soc_instantiate_card(card);
1555 /* probes a new socdev */
1556 static int soc_probe(struct platform_device *pdev)
1558 struct snd_soc_card *card = platform_get_drvdata(pdev);
1562 * no card, so machine driver should be registering card
1563 * we should not be here in that case so ret error
1568 /* Bodge while we unpick instantiation */
1569 card->dev = &pdev->dev;
1571 ret = snd_soc_register_card(card);
1573 dev_err(&pdev->dev, "Failed to register card\n");
1580 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1584 /* make sure any delayed work runs */
1585 for (i = 0; i < card->num_rtd; i++) {
1586 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1587 flush_delayed_work_sync(&rtd->delayed_work);
1590 /* remove auxiliary devices */
1591 for (i = 0; i < card->num_aux_devs; i++)
1592 soc_remove_aux_dev(card, i);
1594 /* remove and free each DAI */
1595 soc_remove_dai_links(card);
1597 soc_cleanup_card_debugfs(card);
1599 /* remove the card */
1603 snd_soc_dapm_free(&card->dapm);
1606 snd_card_free(card->snd_card);
1611 /* removes a socdev */
1612 static int soc_remove(struct platform_device *pdev)
1614 struct snd_soc_card *card = platform_get_drvdata(pdev);
1616 snd_soc_unregister_card(card);
1620 int snd_soc_poweroff(struct device *dev)
1622 struct snd_soc_card *card = dev_get_drvdata(dev);
1625 if (!card->instantiated)
1628 /* Flush out pmdown_time work - we actually do want to run it
1629 * now, we're shutting down so no imminent restart. */
1630 for (i = 0; i < card->num_rtd; i++) {
1631 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1632 flush_delayed_work_sync(&rtd->delayed_work);
1635 snd_soc_dapm_shutdown(card);
1639 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1641 const struct dev_pm_ops snd_soc_pm_ops = {
1642 .suspend = snd_soc_suspend,
1643 .resume = snd_soc_resume,
1644 .poweroff = snd_soc_poweroff,
1646 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1648 /* ASoC platform driver */
1649 static struct platform_driver soc_driver = {
1651 .name = "soc-audio",
1652 .owner = THIS_MODULE,
1653 .pm = &snd_soc_pm_ops,
1656 .remove = soc_remove,
1660 * snd_soc_codec_volatile_register: Report if a register is volatile.
1662 * @codec: CODEC to query.
1663 * @reg: Register to query.
1665 * Boolean function indiciating if a CODEC register is volatile.
1667 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1670 if (codec->volatile_register)
1671 return codec->volatile_register(codec, reg);
1675 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1678 * snd_soc_codec_readable_register: Report if a register is readable.
1680 * @codec: CODEC to query.
1681 * @reg: Register to query.
1683 * Boolean function indicating if a CODEC register is readable.
1685 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1688 if (codec->readable_register)
1689 return codec->readable_register(codec, reg);
1693 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1696 * snd_soc_codec_writable_register: Report if a register is writable.
1698 * @codec: CODEC to query.
1699 * @reg: Register to query.
1701 * Boolean function indicating if a CODEC register is writable.
1703 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1706 if (codec->writable_register)
1707 return codec->writable_register(codec, reg);
1711 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1713 int snd_soc_platform_read(struct snd_soc_platform *platform,
1718 if (!platform->driver->read) {
1719 dev_err(platform->dev, "platform has no read back\n");
1723 ret = platform->driver->read(platform, reg);
1724 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
1725 trace_snd_soc_preg_read(platform, reg, ret);
1729 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1731 int snd_soc_platform_write(struct snd_soc_platform *platform,
1732 unsigned int reg, unsigned int val)
1734 if (!platform->driver->write) {
1735 dev_err(platform->dev, "platform has no write back\n");
1739 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
1740 trace_snd_soc_preg_write(platform, reg, val);
1741 return platform->driver->write(platform, reg, val);
1743 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1746 * snd_soc_new_ac97_codec - initailise AC97 device
1747 * @codec: audio codec
1748 * @ops: AC97 bus operations
1749 * @num: AC97 codec number
1751 * Initialises AC97 codec resources for use by ad-hoc devices only.
1753 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1754 struct snd_ac97_bus_ops *ops, int num)
1756 mutex_lock(&codec->mutex);
1758 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1759 if (codec->ac97 == NULL) {
1760 mutex_unlock(&codec->mutex);
1764 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1765 if (codec->ac97->bus == NULL) {
1768 mutex_unlock(&codec->mutex);
1772 codec->ac97->bus->ops = ops;
1773 codec->ac97->num = num;
1776 * Mark the AC97 device to be created by us. This way we ensure that the
1777 * device will be registered with the device subsystem later on.
1779 codec->ac97_created = 1;
1781 mutex_unlock(&codec->mutex);
1784 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1787 * snd_soc_free_ac97_codec - free AC97 codec device
1788 * @codec: audio codec
1790 * Frees AC97 codec device resources.
1792 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1794 mutex_lock(&codec->mutex);
1795 #ifdef CONFIG_SND_SOC_AC97_BUS
1796 soc_unregister_ac97_dai_link(codec);
1798 kfree(codec->ac97->bus);
1801 codec->ac97_created = 0;
1802 mutex_unlock(&codec->mutex);
1804 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1806 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1810 ret = codec->read(codec, reg);
1811 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
1812 trace_snd_soc_reg_read(codec, reg, ret);
1816 EXPORT_SYMBOL_GPL(snd_soc_read);
1818 unsigned int snd_soc_write(struct snd_soc_codec *codec,
1819 unsigned int reg, unsigned int val)
1821 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
1822 trace_snd_soc_reg_write(codec, reg, val);
1823 return codec->write(codec, reg, val);
1825 EXPORT_SYMBOL_GPL(snd_soc_write);
1827 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1828 unsigned int reg, const void *data, size_t len)
1830 return codec->bulk_write_raw(codec, reg, data, len);
1832 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1835 * snd_soc_update_bits - update codec register bits
1836 * @codec: audio codec
1837 * @reg: codec register
1838 * @mask: register mask
1841 * Writes new register value.
1843 * Returns 1 for change, 0 for no change, or negative error code.
1845 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1846 unsigned int mask, unsigned int value)
1849 unsigned int old, new;
1852 ret = snd_soc_read(codec, reg);
1857 new = (old & ~mask) | (value & mask);
1858 change = old != new;
1860 ret = snd_soc_write(codec, reg, new);
1867 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1870 * snd_soc_update_bits_locked - update codec register bits
1871 * @codec: audio codec
1872 * @reg: codec register
1873 * @mask: register mask
1876 * Writes new register value, and takes the codec mutex.
1878 * Returns 1 for change else 0.
1880 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1881 unsigned short reg, unsigned int mask,
1886 mutex_lock(&codec->mutex);
1887 change = snd_soc_update_bits(codec, reg, mask, value);
1888 mutex_unlock(&codec->mutex);
1892 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1895 * snd_soc_test_bits - test register for change
1896 * @codec: audio codec
1897 * @reg: codec register
1898 * @mask: register mask
1901 * Tests a register with a new value and checks if the new value is
1902 * different from the old value.
1904 * Returns 1 for change else 0.
1906 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1907 unsigned int mask, unsigned int value)
1910 unsigned int old, new;
1912 old = snd_soc_read(codec, reg);
1913 new = (old & ~mask) | value;
1914 change = old != new;
1918 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1921 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1922 * @substream: the pcm substream
1923 * @hw: the hardware parameters
1925 * Sets the substream runtime hardware parameters.
1927 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1928 const struct snd_pcm_hardware *hw)
1930 struct snd_pcm_runtime *runtime = substream->runtime;
1931 runtime->hw.info = hw->info;
1932 runtime->hw.formats = hw->formats;
1933 runtime->hw.period_bytes_min = hw->period_bytes_min;
1934 runtime->hw.period_bytes_max = hw->period_bytes_max;
1935 runtime->hw.periods_min = hw->periods_min;
1936 runtime->hw.periods_max = hw->periods_max;
1937 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1938 runtime->hw.fifo_size = hw->fifo_size;
1941 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1944 * snd_soc_cnew - create new control
1945 * @_template: control template
1946 * @data: control private data
1947 * @long_name: control long name
1948 * @prefix: control name prefix
1950 * Create a new mixer control from a template control.
1952 * Returns 0 for success, else error.
1954 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1955 void *data, char *long_name,
1958 struct snd_kcontrol_new template;
1959 struct snd_kcontrol *kcontrol;
1963 memcpy(&template, _template, sizeof(template));
1967 long_name = template.name;
1970 name_len = strlen(long_name) + strlen(prefix) + 2;
1971 name = kmalloc(name_len, GFP_KERNEL);
1975 snprintf(name, name_len, "%s %s", prefix, long_name);
1977 template.name = name;
1979 template.name = long_name;
1982 kcontrol = snd_ctl_new1(&template, data);
1988 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1991 * snd_soc_add_controls - add an array of controls to a codec.
1992 * Convienience function to add a list of controls. Many codecs were
1993 * duplicating this code.
1995 * @codec: codec to add controls to
1996 * @controls: array of controls to add
1997 * @num_controls: number of elements in the array
1999 * Return 0 for success, else error.
2001 int snd_soc_add_controls(struct snd_soc_codec *codec,
2002 const struct snd_kcontrol_new *controls, int num_controls)
2004 struct snd_card *card = codec->card->snd_card;
2007 for (i = 0; i < num_controls; i++) {
2008 const struct snd_kcontrol_new *control = &controls[i];
2009 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2011 codec->name_prefix));
2013 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2014 codec->name, control->name, err);
2021 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
2024 * snd_soc_add_platform_controls - add an array of controls to a platform.
2025 * Convienience function to add a list of controls.
2027 * @platform: platform to add controls to
2028 * @controls: array of controls to add
2029 * @num_controls: number of elements in the array
2031 * Return 0 for success, else error.
2033 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2034 const struct snd_kcontrol_new *controls, int num_controls)
2036 struct snd_card *card = platform->card->snd_card;
2039 for (i = 0; i < num_controls; i++) {
2040 const struct snd_kcontrol_new *control = &controls[i];
2041 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
2042 control->name, NULL));
2044 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
2051 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2054 * snd_soc_info_enum_double - enumerated double mixer info callback
2055 * @kcontrol: mixer control
2056 * @uinfo: control element information
2058 * Callback to provide information about a double enumerated
2061 * Returns 0 for success.
2063 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2064 struct snd_ctl_elem_info *uinfo)
2066 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2068 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2069 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2070 uinfo->value.enumerated.items = e->max;
2072 if (uinfo->value.enumerated.item > e->max - 1)
2073 uinfo->value.enumerated.item = e->max - 1;
2074 strcpy(uinfo->value.enumerated.name,
2075 e->texts[uinfo->value.enumerated.item]);
2078 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2081 * snd_soc_get_enum_double - enumerated double mixer get callback
2082 * @kcontrol: mixer control
2083 * @ucontrol: control element information
2085 * Callback to get the value of a double enumerated mixer.
2087 * Returns 0 for success.
2089 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2090 struct snd_ctl_elem_value *ucontrol)
2092 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2093 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2094 unsigned int val, bitmask;
2096 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2098 val = snd_soc_read(codec, e->reg);
2099 ucontrol->value.enumerated.item[0]
2100 = (val >> e->shift_l) & (bitmask - 1);
2101 if (e->shift_l != e->shift_r)
2102 ucontrol->value.enumerated.item[1] =
2103 (val >> e->shift_r) & (bitmask - 1);
2107 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2110 * snd_soc_put_enum_double - enumerated double mixer put callback
2111 * @kcontrol: mixer control
2112 * @ucontrol: control element information
2114 * Callback to set the value of a double enumerated mixer.
2116 * Returns 0 for success.
2118 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2119 struct snd_ctl_elem_value *ucontrol)
2121 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2122 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2124 unsigned int mask, bitmask;
2126 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2128 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2130 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2131 mask = (bitmask - 1) << e->shift_l;
2132 if (e->shift_l != e->shift_r) {
2133 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2135 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2136 mask |= (bitmask - 1) << e->shift_r;
2139 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2141 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2144 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2145 * @kcontrol: mixer control
2146 * @ucontrol: control element information
2148 * Callback to get the value of a double semi enumerated mixer.
2150 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2151 * used for handling bitfield coded enumeration for example.
2153 * Returns 0 for success.
2155 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2156 struct snd_ctl_elem_value *ucontrol)
2158 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2159 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2160 unsigned int reg_val, val, mux;
2162 reg_val = snd_soc_read(codec, e->reg);
2163 val = (reg_val >> e->shift_l) & e->mask;
2164 for (mux = 0; mux < e->max; mux++) {
2165 if (val == e->values[mux])
2168 ucontrol->value.enumerated.item[0] = mux;
2169 if (e->shift_l != e->shift_r) {
2170 val = (reg_val >> e->shift_r) & e->mask;
2171 for (mux = 0; mux < e->max; mux++) {
2172 if (val == e->values[mux])
2175 ucontrol->value.enumerated.item[1] = mux;
2180 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2183 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2184 * @kcontrol: mixer control
2185 * @ucontrol: control element information
2187 * Callback to set the value of a double semi enumerated mixer.
2189 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2190 * used for handling bitfield coded enumeration for example.
2192 * Returns 0 for success.
2194 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2195 struct snd_ctl_elem_value *ucontrol)
2197 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2198 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2202 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2204 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2205 mask = e->mask << e->shift_l;
2206 if (e->shift_l != e->shift_r) {
2207 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2209 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2210 mask |= e->mask << e->shift_r;
2213 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2215 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2218 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2219 * @kcontrol: mixer control
2220 * @uinfo: control element information
2222 * Callback to provide information about an external enumerated
2225 * Returns 0 for success.
2227 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2228 struct snd_ctl_elem_info *uinfo)
2230 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2232 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2234 uinfo->value.enumerated.items = e->max;
2236 if (uinfo->value.enumerated.item > e->max - 1)
2237 uinfo->value.enumerated.item = e->max - 1;
2238 strcpy(uinfo->value.enumerated.name,
2239 e->texts[uinfo->value.enumerated.item]);
2242 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2245 * snd_soc_info_volsw_ext - external single mixer info callback
2246 * @kcontrol: mixer control
2247 * @uinfo: control element information
2249 * Callback to provide information about a single external mixer control.
2251 * Returns 0 for success.
2253 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2254 struct snd_ctl_elem_info *uinfo)
2256 int max = kcontrol->private_value;
2258 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2259 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2261 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2264 uinfo->value.integer.min = 0;
2265 uinfo->value.integer.max = max;
2268 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2271 * snd_soc_info_volsw - single mixer info callback
2272 * @kcontrol: mixer control
2273 * @uinfo: control element information
2275 * Callback to provide information about a single mixer control, or a double
2276 * mixer control that spans 2 registers.
2278 * Returns 0 for success.
2280 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2281 struct snd_ctl_elem_info *uinfo)
2283 struct soc_mixer_control *mc =
2284 (struct soc_mixer_control *)kcontrol->private_value;
2287 if (!mc->platform_max)
2288 mc->platform_max = mc->max;
2289 platform_max = mc->platform_max;
2291 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2292 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2294 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2296 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2297 uinfo->value.integer.min = 0;
2298 uinfo->value.integer.max = platform_max;
2301 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2304 * snd_soc_get_volsw - single mixer get callback
2305 * @kcontrol: mixer control
2306 * @ucontrol: control element information
2308 * Callback to get the value of a single mixer control, or a double mixer
2309 * control that spans 2 registers.
2311 * Returns 0 for success.
2313 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2314 struct snd_ctl_elem_value *ucontrol)
2316 struct soc_mixer_control *mc =
2317 (struct soc_mixer_control *)kcontrol->private_value;
2318 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2319 unsigned int reg = mc->reg;
2320 unsigned int reg2 = mc->rreg;
2321 unsigned int shift = mc->shift;
2322 unsigned int rshift = mc->rshift;
2324 unsigned int mask = (1 << fls(max)) - 1;
2325 unsigned int invert = mc->invert;
2327 ucontrol->value.integer.value[0] =
2328 (snd_soc_read(codec, reg) >> shift) & mask;
2330 ucontrol->value.integer.value[0] =
2331 max - ucontrol->value.integer.value[0];
2333 if (snd_soc_volsw_is_stereo(mc)) {
2335 ucontrol->value.integer.value[1] =
2336 (snd_soc_read(codec, reg) >> rshift) & mask;
2338 ucontrol->value.integer.value[1] =
2339 (snd_soc_read(codec, reg2) >> shift) & mask;
2341 ucontrol->value.integer.value[1] =
2342 max - ucontrol->value.integer.value[1];
2347 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2350 * snd_soc_put_volsw - single mixer put callback
2351 * @kcontrol: mixer control
2352 * @ucontrol: control element information
2354 * Callback to set the value of a single mixer control, or a double mixer
2355 * control that spans 2 registers.
2357 * Returns 0 for success.
2359 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2360 struct snd_ctl_elem_value *ucontrol)
2362 struct soc_mixer_control *mc =
2363 (struct soc_mixer_control *)kcontrol->private_value;
2364 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2365 unsigned int reg = mc->reg;
2366 unsigned int reg2 = mc->rreg;
2367 unsigned int shift = mc->shift;
2368 unsigned int rshift = mc->rshift;
2370 unsigned int mask = (1 << fls(max)) - 1;
2371 unsigned int invert = mc->invert;
2374 unsigned int val2 = 0;
2375 unsigned int val, val_mask;
2377 val = (ucontrol->value.integer.value[0] & mask);
2380 val_mask = mask << shift;
2382 if (snd_soc_volsw_is_stereo(mc)) {
2383 val2 = (ucontrol->value.integer.value[1] & mask);
2387 val_mask |= mask << rshift;
2388 val |= val2 << rshift;
2390 val2 = val2 << shift;
2394 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2399 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2403 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2406 * snd_soc_info_volsw_s8 - signed mixer info callback
2407 * @kcontrol: mixer control
2408 * @uinfo: control element information
2410 * Callback to provide information about a signed mixer control.
2412 * Returns 0 for success.
2414 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2415 struct snd_ctl_elem_info *uinfo)
2417 struct soc_mixer_control *mc =
2418 (struct soc_mixer_control *)kcontrol->private_value;
2422 if (!mc->platform_max)
2423 mc->platform_max = mc->max;
2424 platform_max = mc->platform_max;
2426 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2428 uinfo->value.integer.min = 0;
2429 uinfo->value.integer.max = platform_max - min;
2432 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2435 * snd_soc_get_volsw_s8 - signed mixer get callback
2436 * @kcontrol: mixer control
2437 * @ucontrol: control element information
2439 * Callback to get the value of a signed mixer control.
2441 * Returns 0 for success.
2443 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2444 struct snd_ctl_elem_value *ucontrol)
2446 struct soc_mixer_control *mc =
2447 (struct soc_mixer_control *)kcontrol->private_value;
2448 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2449 unsigned int reg = mc->reg;
2451 int val = snd_soc_read(codec, reg);
2453 ucontrol->value.integer.value[0] =
2454 ((signed char)(val & 0xff))-min;
2455 ucontrol->value.integer.value[1] =
2456 ((signed char)((val >> 8) & 0xff))-min;
2459 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2462 * snd_soc_put_volsw_sgn - signed mixer put callback
2463 * @kcontrol: mixer control
2464 * @ucontrol: control element information
2466 * Callback to set the value of a signed mixer control.
2468 * Returns 0 for success.
2470 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2471 struct snd_ctl_elem_value *ucontrol)
2473 struct soc_mixer_control *mc =
2474 (struct soc_mixer_control *)kcontrol->private_value;
2475 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2476 unsigned int reg = mc->reg;
2480 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2481 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2483 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2485 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2488 * snd_soc_limit_volume - Set new limit to an existing volume control.
2490 * @codec: where to look for the control
2491 * @name: Name of the control
2492 * @max: new maximum limit
2494 * Return 0 for success, else error.
2496 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2497 const char *name, int max)
2499 struct snd_card *card = codec->card->snd_card;
2500 struct snd_kcontrol *kctl;
2501 struct soc_mixer_control *mc;
2505 /* Sanity check for name and max */
2506 if (unlikely(!name || max <= 0))
2509 list_for_each_entry(kctl, &card->controls, list) {
2510 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2516 mc = (struct soc_mixer_control *)kctl->private_value;
2517 if (max <= mc->max) {
2518 mc->platform_max = max;
2524 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2527 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2528 * mixer info callback
2529 * @kcontrol: mixer control
2530 * @uinfo: control element information
2532 * Returns 0 for success.
2534 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2535 struct snd_ctl_elem_info *uinfo)
2537 struct soc_mixer_control *mc =
2538 (struct soc_mixer_control *)kcontrol->private_value;
2542 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2544 uinfo->value.integer.min = 0;
2545 uinfo->value.integer.max = max-min;
2549 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2552 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2553 * mixer get callback
2554 * @kcontrol: mixer control
2555 * @uinfo: control element information
2557 * Returns 0 for success.
2559 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2560 struct snd_ctl_elem_value *ucontrol)
2562 struct soc_mixer_control *mc =
2563 (struct soc_mixer_control *)kcontrol->private_value;
2564 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2565 unsigned int mask = (1<<mc->shift)-1;
2567 int val = snd_soc_read(codec, mc->reg) & mask;
2568 int valr = snd_soc_read(codec, mc->rreg) & mask;
2570 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2571 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2574 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2577 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2578 * mixer put callback
2579 * @kcontrol: mixer control
2580 * @uinfo: control element information
2582 * Returns 0 for success.
2584 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2585 struct snd_ctl_elem_value *ucontrol)
2587 struct soc_mixer_control *mc =
2588 (struct soc_mixer_control *)kcontrol->private_value;
2589 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2590 unsigned int mask = (1<<mc->shift)-1;
2593 unsigned int val, valr, oval, ovalr;
2595 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2597 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2600 oval = snd_soc_read(codec, mc->reg) & mask;
2601 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2605 ret = snd_soc_write(codec, mc->reg, val);
2609 if (ovalr != valr) {
2610 ret = snd_soc_write(codec, mc->rreg, valr);
2617 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2620 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2622 * @clk_id: DAI specific clock ID
2623 * @freq: new clock frequency in Hz
2624 * @dir: new clock direction - input/output.
2626 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2628 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2629 unsigned int freq, int dir)
2631 if (dai->driver && dai->driver->ops->set_sysclk)
2632 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2633 else if (dai->codec && dai->codec->driver->set_sysclk)
2634 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2639 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2642 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2644 * @clk_id: DAI specific clock ID
2645 * @source: Source for the clock
2646 * @freq: new clock frequency in Hz
2647 * @dir: new clock direction - input/output.
2649 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2651 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2652 int source, unsigned int freq, int dir)
2654 if (codec->driver->set_sysclk)
2655 return codec->driver->set_sysclk(codec, clk_id, source,
2660 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2663 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2665 * @div_id: DAI specific clock divider ID
2666 * @div: new clock divisor.
2668 * Configures the clock dividers. This is used to derive the best DAI bit and
2669 * frame clocks from the system or master clock. It's best to set the DAI bit
2670 * and frame clocks as low as possible to save system power.
2672 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2673 int div_id, int div)
2675 if (dai->driver && dai->driver->ops->set_clkdiv)
2676 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2680 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2683 * snd_soc_dai_set_pll - configure DAI PLL.
2685 * @pll_id: DAI specific PLL ID
2686 * @source: DAI specific source for the PLL
2687 * @freq_in: PLL input clock frequency in Hz
2688 * @freq_out: requested PLL output clock frequency in Hz
2690 * Configures and enables PLL to generate output clock based on input clock.
2692 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2693 unsigned int freq_in, unsigned int freq_out)
2695 if (dai->driver && dai->driver->ops->set_pll)
2696 return dai->driver->ops->set_pll(dai, pll_id, source,
2698 else if (dai->codec && dai->codec->driver->set_pll)
2699 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2704 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2707 * snd_soc_codec_set_pll - configure codec PLL.
2709 * @pll_id: DAI specific PLL ID
2710 * @source: DAI specific source for the PLL
2711 * @freq_in: PLL input clock frequency in Hz
2712 * @freq_out: requested PLL output clock frequency in Hz
2714 * Configures and enables PLL to generate output clock based on input clock.
2716 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2717 unsigned int freq_in, unsigned int freq_out)
2719 if (codec->driver->set_pll)
2720 return codec->driver->set_pll(codec, pll_id, source,
2725 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2728 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2730 * @fmt: SND_SOC_DAIFMT_ format value.
2732 * Configures the DAI hardware format and clocking.
2734 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2736 if (dai->driver && dai->driver->ops->set_fmt)
2737 return dai->driver->ops->set_fmt(dai, fmt);
2741 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2744 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2746 * @tx_mask: bitmask representing active TX slots.
2747 * @rx_mask: bitmask representing active RX slots.
2748 * @slots: Number of slots in use.
2749 * @slot_width: Width in bits for each slot.
2751 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2754 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2755 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2757 if (dai->driver && dai->driver->ops->set_tdm_slot)
2758 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2763 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2766 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2768 * @tx_num: how many TX channels
2769 * @tx_slot: pointer to an array which imply the TX slot number channel
2771 * @rx_num: how many RX channels
2772 * @rx_slot: pointer to an array which imply the RX slot number channel
2775 * configure the relationship between channel number and TDM slot number.
2777 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2778 unsigned int tx_num, unsigned int *tx_slot,
2779 unsigned int rx_num, unsigned int *rx_slot)
2781 if (dai->driver && dai->driver->ops->set_channel_map)
2782 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2787 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2790 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2792 * @tristate: tristate enable
2794 * Tristates the DAI so that others can use it.
2796 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2798 if (dai->driver && dai->driver->ops->set_tristate)
2799 return dai->driver->ops->set_tristate(dai, tristate);
2803 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2806 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2808 * @mute: mute enable
2810 * Mutes the DAI DAC.
2812 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2814 if (dai->driver && dai->driver->ops->digital_mute)
2815 return dai->driver->ops->digital_mute(dai, mute);
2819 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2822 * snd_soc_register_card - Register a card with the ASoC core
2824 * @card: Card to register
2827 int snd_soc_register_card(struct snd_soc_card *card)
2831 if (!card->name || !card->dev)
2834 dev_set_drvdata(card->dev, card);
2836 snd_soc_initialize_card_lists(card);
2838 soc_init_card_debugfs(card);
2840 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2841 (card->num_links + card->num_aux_devs),
2843 if (card->rtd == NULL)
2845 card->rtd_aux = &card->rtd[card->num_links];
2847 for (i = 0; i < card->num_links; i++)
2848 card->rtd[i].dai_link = &card->dai_link[i];
2850 INIT_LIST_HEAD(&card->list);
2851 INIT_LIST_HEAD(&card->dapm_dirty);
2852 card->instantiated = 0;
2853 mutex_init(&card->mutex);
2855 mutex_lock(&client_mutex);
2856 list_add(&card->list, &card_list);
2857 snd_soc_instantiate_cards();
2858 mutex_unlock(&client_mutex);
2860 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2864 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2867 * snd_soc_unregister_card - Unregister a card with the ASoC core
2869 * @card: Card to unregister
2872 int snd_soc_unregister_card(struct snd_soc_card *card)
2874 if (card->instantiated)
2875 soc_cleanup_card_resources(card);
2876 mutex_lock(&client_mutex);
2877 list_del(&card->list);
2878 mutex_unlock(&client_mutex);
2879 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2883 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2886 * Simplify DAI link configuration by removing ".-1" from device names
2887 * and sanitizing names.
2889 static char *fmt_single_name(struct device *dev, int *id)
2891 char *found, name[NAME_SIZE];
2894 if (dev_name(dev) == NULL)
2897 strlcpy(name, dev_name(dev), NAME_SIZE);
2899 /* are we a "%s.%d" name (platform and SPI components) */
2900 found = strstr(name, dev->driver->name);
2903 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2905 /* discard ID from name if ID == -1 */
2907 found[strlen(dev->driver->name)] = '\0';
2911 /* I2C component devices are named "bus-addr" */
2912 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2913 char tmp[NAME_SIZE];
2915 /* create unique ID number from I2C addr and bus */
2916 *id = ((id1 & 0xffff) << 16) + id2;
2918 /* sanitize component name for DAI link creation */
2919 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2920 strlcpy(name, tmp, NAME_SIZE);
2925 return kstrdup(name, GFP_KERNEL);
2929 * Simplify DAI link naming for single devices with multiple DAIs by removing
2930 * any ".-1" and using the DAI name (instead of device name).
2932 static inline char *fmt_multiple_name(struct device *dev,
2933 struct snd_soc_dai_driver *dai_drv)
2935 if (dai_drv->name == NULL) {
2936 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2941 return kstrdup(dai_drv->name, GFP_KERNEL);
2945 * snd_soc_register_dai - Register a DAI with the ASoC core
2947 * @dai: DAI to register
2949 int snd_soc_register_dai(struct device *dev,
2950 struct snd_soc_dai_driver *dai_drv)
2952 struct snd_soc_dai *dai;
2954 dev_dbg(dev, "dai register %s\n", dev_name(dev));
2956 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2960 /* create DAI component name */
2961 dai->name = fmt_single_name(dev, &dai->id);
2962 if (dai->name == NULL) {
2968 dai->driver = dai_drv;
2969 if (!dai->driver->ops)
2970 dai->driver->ops = &null_dai_ops;
2972 mutex_lock(&client_mutex);
2973 list_add(&dai->list, &dai_list);
2974 snd_soc_instantiate_cards();
2975 mutex_unlock(&client_mutex);
2977 pr_debug("Registered DAI '%s'\n", dai->name);
2981 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2984 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2986 * @dai: DAI to unregister
2988 void snd_soc_unregister_dai(struct device *dev)
2990 struct snd_soc_dai *dai;
2992 list_for_each_entry(dai, &dai_list, list) {
2993 if (dev == dai->dev)
2999 mutex_lock(&client_mutex);
3000 list_del(&dai->list);
3001 mutex_unlock(&client_mutex);
3003 pr_debug("Unregistered DAI '%s'\n", dai->name);
3007 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3010 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3012 * @dai: Array of DAIs to register
3013 * @count: Number of DAIs
3015 int snd_soc_register_dais(struct device *dev,
3016 struct snd_soc_dai_driver *dai_drv, size_t count)
3018 struct snd_soc_dai *dai;
3021 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3023 for (i = 0; i < count; i++) {
3025 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3031 /* create DAI component name */
3032 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3033 if (dai->name == NULL) {
3040 dai->driver = &dai_drv[i];
3041 if (dai->driver->id)
3042 dai->id = dai->driver->id;
3045 if (!dai->driver->ops)
3046 dai->driver->ops = &null_dai_ops;
3048 mutex_lock(&client_mutex);
3049 list_add(&dai->list, &dai_list);
3050 mutex_unlock(&client_mutex);
3052 pr_debug("Registered DAI '%s'\n", dai->name);
3055 mutex_lock(&client_mutex);
3056 snd_soc_instantiate_cards();
3057 mutex_unlock(&client_mutex);
3061 for (i--; i >= 0; i--)
3062 snd_soc_unregister_dai(dev);
3066 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3069 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3071 * @dai: Array of DAIs to unregister
3072 * @count: Number of DAIs
3074 void snd_soc_unregister_dais(struct device *dev, size_t count)
3078 for (i = 0; i < count; i++)
3079 snd_soc_unregister_dai(dev);
3081 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3084 * snd_soc_register_platform - Register a platform with the ASoC core
3086 * @platform: platform to register
3088 int snd_soc_register_platform(struct device *dev,
3089 struct snd_soc_platform_driver *platform_drv)
3091 struct snd_soc_platform *platform;
3093 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3095 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3096 if (platform == NULL)
3099 /* create platform component name */
3100 platform->name = fmt_single_name(dev, &platform->id);
3101 if (platform->name == NULL) {
3106 platform->dev = dev;
3107 platform->driver = platform_drv;
3108 platform->dapm.dev = dev;
3109 platform->dapm.platform = platform;
3110 platform->dapm.stream_event = platform_drv->stream_event;
3112 mutex_lock(&client_mutex);
3113 list_add(&platform->list, &platform_list);
3114 snd_soc_instantiate_cards();
3115 mutex_unlock(&client_mutex);
3117 pr_debug("Registered platform '%s'\n", platform->name);
3121 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3124 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3126 * @platform: platform to unregister
3128 void snd_soc_unregister_platform(struct device *dev)
3130 struct snd_soc_platform *platform;
3132 list_for_each_entry(platform, &platform_list, list) {
3133 if (dev == platform->dev)
3139 mutex_lock(&client_mutex);
3140 list_del(&platform->list);
3141 mutex_unlock(&client_mutex);
3143 pr_debug("Unregistered platform '%s'\n", platform->name);
3144 kfree(platform->name);
3147 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3149 static u64 codec_format_map[] = {
3150 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3151 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3152 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3153 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3154 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3155 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3156 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3157 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3158 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3159 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3160 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3161 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3162 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3163 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3164 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3165 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3168 /* Fix up the DAI formats for endianness: codecs don't actually see
3169 * the endianness of the data but we're using the CPU format
3170 * definitions which do need to include endianness so we ensure that
3171 * codec DAIs always have both big and little endian variants set.
3173 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3177 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3178 if (stream->formats & codec_format_map[i])
3179 stream->formats |= codec_format_map[i];
3183 * snd_soc_register_codec - Register a codec with the ASoC core
3185 * @codec: codec to register
3187 int snd_soc_register_codec(struct device *dev,
3188 const struct snd_soc_codec_driver *codec_drv,
3189 struct snd_soc_dai_driver *dai_drv,
3193 struct snd_soc_codec *codec;
3196 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3198 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3202 /* create CODEC component name */
3203 codec->name = fmt_single_name(dev, &codec->id);
3204 if (codec->name == NULL) {
3209 if (codec_drv->compress_type)
3210 codec->compress_type = codec_drv->compress_type;
3212 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3214 codec->write = codec_drv->write;
3215 codec->read = codec_drv->read;
3216 codec->volatile_register = codec_drv->volatile_register;
3217 codec->readable_register = codec_drv->readable_register;
3218 codec->writable_register = codec_drv->writable_register;
3219 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3220 codec->dapm.dev = dev;
3221 codec->dapm.codec = codec;
3222 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3223 codec->dapm.stream_event = codec_drv->stream_event;
3225 codec->driver = codec_drv;
3226 codec->num_dai = num_dai;
3227 mutex_init(&codec->mutex);
3229 /* allocate CODEC register cache */
3230 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3231 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3232 codec->reg_size = reg_size;
3233 /* it is necessary to make a copy of the default register cache
3234 * because in the case of using a compression type that requires
3235 * the default register cache to be marked as __devinitconst the
3236 * kernel might have freed the array by the time we initialize
3239 if (codec_drv->reg_cache_default) {
3240 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3241 reg_size, GFP_KERNEL);
3242 if (!codec->reg_def_copy) {
3249 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3250 if (!codec->volatile_register)
3251 codec->volatile_register = snd_soc_default_volatile_register;
3252 if (!codec->readable_register)
3253 codec->readable_register = snd_soc_default_readable_register;
3254 if (!codec->writable_register)
3255 codec->writable_register = snd_soc_default_writable_register;
3258 for (i = 0; i < num_dai; i++) {
3259 fixup_codec_formats(&dai_drv[i].playback);
3260 fixup_codec_formats(&dai_drv[i].capture);
3263 /* register any DAIs */
3265 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3270 mutex_lock(&client_mutex);
3271 list_add(&codec->list, &codec_list);
3272 snd_soc_instantiate_cards();
3273 mutex_unlock(&client_mutex);
3275 pr_debug("Registered codec '%s'\n", codec->name);
3279 kfree(codec->reg_def_copy);
3280 codec->reg_def_copy = NULL;
3285 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3288 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3290 * @codec: codec to unregister
3292 void snd_soc_unregister_codec(struct device *dev)
3294 struct snd_soc_codec *codec;
3297 list_for_each_entry(codec, &codec_list, list) {
3298 if (dev == codec->dev)
3305 for (i = 0; i < codec->num_dai; i++)
3306 snd_soc_unregister_dai(dev);
3308 mutex_lock(&client_mutex);
3309 list_del(&codec->list);
3310 mutex_unlock(&client_mutex);
3312 pr_debug("Unregistered codec '%s'\n", codec->name);
3314 snd_soc_cache_exit(codec);
3315 kfree(codec->reg_def_copy);
3319 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3321 /* Retrieve a card's name from device tree */
3322 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3323 const char *propname)
3325 struct device_node *np = card->dev->of_node;
3328 ret = of_property_read_string_index(np, propname, 0, &card->name);
3330 * EINVAL means the property does not exist. This is fine providing
3331 * card->name was previously set, which is checked later in
3332 * snd_soc_register_card.
3334 if (ret < 0 && ret != -EINVAL) {
3336 "Property '%s' could not be read: %d\n",
3343 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3345 static int __init snd_soc_init(void)
3347 #ifdef CONFIG_DEBUG_FS
3348 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3349 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
3351 "ASoC: Failed to create debugfs directory\n");
3352 snd_soc_debugfs_root = NULL;
3355 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
3357 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3359 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
3361 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3363 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
3364 &platform_list_fops))
3365 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3368 snd_soc_util_init();
3370 return platform_driver_register(&soc_driver);
3372 module_init(snd_soc_init);
3374 static void __exit snd_soc_exit(void)
3376 snd_soc_util_exit();
3378 #ifdef CONFIG_DEBUG_FS
3379 debugfs_remove_recursive(snd_soc_debugfs_root);
3381 platform_driver_unregister(&soc_driver);
3383 module_exit(snd_soc_exit);
3385 /* Module information */
3386 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3387 MODULE_DESCRIPTION("ALSA SoC Core");
3388 MODULE_LICENSE("GPL");
3389 MODULE_ALIAS("platform:soc-audio");