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/slab.h>
34 #include <sound/ac97_codec.h>
35 #include <sound/core.h>
36 #include <sound/jack.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/soc.h>
40 #include <sound/initval.h>
42 #define CREATE_TRACE_POINTS
43 #include <trace/events/asoc.h>
47 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
49 #ifdef CONFIG_DEBUG_FS
50 struct dentry *snd_soc_debugfs_root;
51 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
54 static DEFINE_MUTEX(client_mutex);
55 static LIST_HEAD(card_list);
56 static LIST_HEAD(dai_list);
57 static LIST_HEAD(platform_list);
58 static LIST_HEAD(codec_list);
60 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
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 =
173 container_of(dev, struct snd_soc_pcm_runtime, dev);
175 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
178 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
180 static ssize_t pmdown_time_show(struct device *dev,
181 struct device_attribute *attr, char *buf)
183 struct snd_soc_pcm_runtime *rtd =
184 container_of(dev, struct snd_soc_pcm_runtime, dev);
186 return sprintf(buf, "%ld\n", rtd->pmdown_time);
189 static ssize_t pmdown_time_set(struct device *dev,
190 struct device_attribute *attr,
191 const char *buf, size_t count)
193 struct snd_soc_pcm_runtime *rtd =
194 container_of(dev, struct snd_soc_pcm_runtime, dev);
197 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
204 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
206 #ifdef CONFIG_DEBUG_FS
207 static int codec_reg_open_file(struct inode *inode, struct file *file)
209 file->private_data = inode->i_private;
213 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
214 size_t count, loff_t *ppos)
217 struct snd_soc_codec *codec = file->private_data;
220 if (*ppos < 0 || !count)
223 buf = kmalloc(count, GFP_KERNEL);
227 ret = soc_codec_reg_show(codec, buf, count, *ppos);
229 if (copy_to_user(user_buf, buf, ret)) {
240 static ssize_t codec_reg_write_file(struct file *file,
241 const char __user *user_buf, size_t count, loff_t *ppos)
246 unsigned long reg, value;
247 struct snd_soc_codec *codec = file->private_data;
249 buf_size = min(count, (sizeof(buf)-1));
250 if (copy_from_user(buf, user_buf, buf_size))
254 while (*start == ' ')
256 reg = simple_strtoul(start, &start, 16);
257 while (*start == ' ')
259 if (strict_strtoul(start, 16, &value))
262 /* Userspace has been fiddling around behind the kernel's back */
263 add_taint(TAINT_USER);
265 snd_soc_write(codec, reg, value);
269 static const struct file_operations codec_reg_fops = {
270 .open = codec_reg_open_file,
271 .read = codec_reg_read_file,
272 .write = codec_reg_write_file,
273 .llseek = default_llseek,
276 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
278 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
280 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
282 if (!codec->debugfs_codec_root) {
284 "ASoC: Failed to create codec debugfs directory\n");
288 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
290 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
293 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
294 codec->debugfs_codec_root,
295 codec, &codec_reg_fops);
296 if (!codec->debugfs_reg)
298 "ASoC: Failed to create codec register debugfs file\n");
300 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
303 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
305 debugfs_remove_recursive(codec->debugfs_codec_root);
308 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
309 size_t count, loff_t *ppos)
311 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
312 ssize_t len, ret = 0;
313 struct snd_soc_codec *codec;
318 list_for_each_entry(codec, &codec_list, list) {
319 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
323 if (ret > PAGE_SIZE) {
330 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
337 static const struct file_operations codec_list_fops = {
338 .read = codec_list_read_file,
339 .llseek = default_llseek,/* read accesses f_pos */
342 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
343 size_t count, loff_t *ppos)
345 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
346 ssize_t len, ret = 0;
347 struct snd_soc_dai *dai;
352 list_for_each_entry(dai, &dai_list, list) {
353 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
356 if (ret > PAGE_SIZE) {
362 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
369 static const struct file_operations dai_list_fops = {
370 .read = dai_list_read_file,
371 .llseek = default_llseek,/* read accesses f_pos */
374 static ssize_t platform_list_read_file(struct file *file,
375 char __user *user_buf,
376 size_t count, loff_t *ppos)
378 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
379 ssize_t len, ret = 0;
380 struct snd_soc_platform *platform;
385 list_for_each_entry(platform, &platform_list, list) {
386 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
390 if (ret > PAGE_SIZE) {
396 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
403 static const struct file_operations platform_list_fops = {
404 .read = platform_list_read_file,
405 .llseek = default_llseek,/* read accesses f_pos */
408 static void soc_init_card_debugfs(struct snd_soc_card *card)
410 card->debugfs_card_root = debugfs_create_dir(card->name,
411 snd_soc_debugfs_root);
412 if (!card->debugfs_card_root) {
414 "ASoC: Failed to create codec debugfs directory\n");
418 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
419 card->debugfs_card_root,
421 if (!card->debugfs_pop_time)
423 "Failed to create pop time debugfs file\n");
426 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
428 debugfs_remove_recursive(card->debugfs_card_root);
433 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
437 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
441 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
445 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
450 #ifdef CONFIG_SND_SOC_AC97_BUS
451 /* unregister ac97 codec */
452 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
454 if (codec->ac97->dev.bus)
455 device_unregister(&codec->ac97->dev);
459 /* stop no dev release warning */
460 static void soc_ac97_device_release(struct device *dev){}
462 /* register ac97 codec to bus */
463 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
467 codec->ac97->dev.bus = &ac97_bus_type;
468 codec->ac97->dev.parent = codec->card->dev;
469 codec->ac97->dev.release = soc_ac97_device_release;
471 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
472 codec->card->snd_card->number, 0, codec->name);
473 err = device_register(&codec->ac97->dev);
475 snd_printk(KERN_ERR "Can't register ac97 bus\n");
476 codec->ac97->dev.bus = NULL;
483 #ifdef CONFIG_PM_SLEEP
484 /* powers down audio subsystem for suspend */
485 int snd_soc_suspend(struct device *dev)
487 struct snd_soc_card *card = dev_get_drvdata(dev);
488 struct snd_soc_codec *codec;
491 /* If the initialization of this soc device failed, there is no codec
492 * associated with it. Just bail out in this case.
494 if (list_empty(&card->codec_dev_list))
497 /* Due to the resume being scheduled into a workqueue we could
498 * suspend before that's finished - wait for it to complete.
500 snd_power_lock(card->snd_card);
501 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
502 snd_power_unlock(card->snd_card);
504 /* we're going to block userspace touching us until resume completes */
505 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
507 /* mute any active DACs */
508 for (i = 0; i < card->num_rtd; i++) {
509 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
510 struct snd_soc_dai_driver *drv = dai->driver;
512 if (card->rtd[i].dai_link->ignore_suspend)
515 if (drv->ops->digital_mute && dai->playback_active)
516 drv->ops->digital_mute(dai, 1);
519 /* suspend all pcms */
520 for (i = 0; i < card->num_rtd; i++) {
521 if (card->rtd[i].dai_link->ignore_suspend)
524 snd_pcm_suspend_all(card->rtd[i].pcm);
527 if (card->suspend_pre)
528 card->suspend_pre(card);
530 for (i = 0; i < card->num_rtd; i++) {
531 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
532 struct snd_soc_platform *platform = card->rtd[i].platform;
534 if (card->rtd[i].dai_link->ignore_suspend)
537 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
538 cpu_dai->driver->suspend(cpu_dai);
539 if (platform->driver->suspend && !platform->suspended) {
540 platform->driver->suspend(cpu_dai);
541 platform->suspended = 1;
545 /* close any waiting streams and save state */
546 for (i = 0; i < card->num_rtd; i++) {
547 flush_delayed_work_sync(&card->rtd[i].delayed_work);
548 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
551 for (i = 0; i < card->num_rtd; i++) {
552 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
554 if (card->rtd[i].dai_link->ignore_suspend)
557 if (driver->playback.stream_name != NULL)
558 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
559 SND_SOC_DAPM_STREAM_SUSPEND);
561 if (driver->capture.stream_name != NULL)
562 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
563 SND_SOC_DAPM_STREAM_SUSPEND);
566 /* suspend all CODECs */
567 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
568 /* If there are paths active then the CODEC will be held with
569 * bias _ON and should not be suspended. */
570 if (!codec->suspended && codec->driver->suspend) {
571 switch (codec->dapm.bias_level) {
572 case SND_SOC_BIAS_STANDBY:
573 case SND_SOC_BIAS_OFF:
574 codec->driver->suspend(codec, PMSG_SUSPEND);
575 codec->suspended = 1;
576 codec->cache_sync = 1;
579 dev_dbg(codec->dev, "CODEC is on over suspend\n");
585 for (i = 0; i < card->num_rtd; i++) {
586 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
588 if (card->rtd[i].dai_link->ignore_suspend)
591 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
592 cpu_dai->driver->suspend(cpu_dai);
595 if (card->suspend_post)
596 card->suspend_post(card);
600 EXPORT_SYMBOL_GPL(snd_soc_suspend);
602 /* deferred resume work, so resume can complete before we finished
603 * setting our codec back up, which can be very slow on I2C
605 static void soc_resume_deferred(struct work_struct *work)
607 struct snd_soc_card *card =
608 container_of(work, struct snd_soc_card, deferred_resume_work);
609 struct snd_soc_codec *codec;
612 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
613 * so userspace apps are blocked from touching us
616 dev_dbg(card->dev, "starting resume work\n");
618 /* Bring us up into D2 so that DAPM starts enabling things */
619 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
621 if (card->resume_pre)
622 card->resume_pre(card);
624 /* resume AC97 DAIs */
625 for (i = 0; i < card->num_rtd; i++) {
626 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
628 if (card->rtd[i].dai_link->ignore_suspend)
631 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
632 cpu_dai->driver->resume(cpu_dai);
635 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
636 /* If the CODEC was idle over suspend then it will have been
637 * left with bias OFF or STANDBY and suspended so we must now
638 * resume. Otherwise the suspend was suppressed.
640 if (codec->driver->resume && codec->suspended) {
641 switch (codec->dapm.bias_level) {
642 case SND_SOC_BIAS_STANDBY:
643 case SND_SOC_BIAS_OFF:
644 codec->driver->resume(codec);
645 codec->suspended = 0;
648 dev_dbg(codec->dev, "CODEC was on over suspend\n");
654 for (i = 0; i < card->num_rtd; i++) {
655 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
657 if (card->rtd[i].dai_link->ignore_suspend)
660 if (driver->playback.stream_name != NULL)
661 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
662 SND_SOC_DAPM_STREAM_RESUME);
664 if (driver->capture.stream_name != NULL)
665 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
666 SND_SOC_DAPM_STREAM_RESUME);
669 /* unmute any active DACs */
670 for (i = 0; i < card->num_rtd; i++) {
671 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
672 struct snd_soc_dai_driver *drv = dai->driver;
674 if (card->rtd[i].dai_link->ignore_suspend)
677 if (drv->ops->digital_mute && dai->playback_active)
678 drv->ops->digital_mute(dai, 0);
681 for (i = 0; i < card->num_rtd; i++) {
682 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
683 struct snd_soc_platform *platform = card->rtd[i].platform;
685 if (card->rtd[i].dai_link->ignore_suspend)
688 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
689 cpu_dai->driver->resume(cpu_dai);
690 if (platform->driver->resume && platform->suspended) {
691 platform->driver->resume(cpu_dai);
692 platform->suspended = 0;
696 if (card->resume_post)
697 card->resume_post(card);
699 dev_dbg(card->dev, "resume work completed\n");
701 /* userspace can access us now we are back as we were before */
702 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
705 /* powers up audio subsystem after a suspend */
706 int snd_soc_resume(struct device *dev)
708 struct snd_soc_card *card = dev_get_drvdata(dev);
709 int i, ac97_control = 0;
711 /* AC97 devices might have other drivers hanging off them so
712 * need to resume immediately. Other drivers don't have that
713 * problem and may take a substantial amount of time to resume
714 * due to I/O costs and anti-pop so handle them out of line.
716 for (i = 0; i < card->num_rtd; i++) {
717 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
718 ac97_control |= cpu_dai->driver->ac97_control;
721 dev_dbg(dev, "Resuming AC97 immediately\n");
722 soc_resume_deferred(&card->deferred_resume_work);
724 dev_dbg(dev, "Scheduling resume work\n");
725 if (!schedule_work(&card->deferred_resume_work))
726 dev_err(dev, "resume work item may be lost\n");
731 EXPORT_SYMBOL_GPL(snd_soc_resume);
733 #define snd_soc_suspend NULL
734 #define snd_soc_resume NULL
737 static struct snd_soc_dai_ops null_dai_ops = {
740 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
742 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
743 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
744 struct snd_soc_codec *codec;
745 struct snd_soc_platform *platform;
746 struct snd_soc_dai *codec_dai, *cpu_dai;
747 const char *platform_name;
751 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
753 /* do we already have the CPU DAI for this link ? */
757 /* no, then find CPU DAI from registered DAIs*/
758 list_for_each_entry(cpu_dai, &dai_list, list) {
759 if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
760 rtd->cpu_dai = cpu_dai;
764 dev_dbg(card->dev, "CPU DAI %s not registered\n",
765 dai_link->cpu_dai_name);
768 /* do we already have the CODEC for this link ? */
773 /* no, then find CODEC from registered CODECs*/
774 list_for_each_entry(codec, &codec_list, list) {
775 if (!strcmp(codec->name, dai_link->codec_name)) {
778 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
779 list_for_each_entry(codec_dai, &dai_list, list) {
780 if (codec->dev == codec_dai->dev &&
781 !strcmp(codec_dai->name, dai_link->codec_dai_name)) {
782 rtd->codec_dai = codec_dai;
786 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
787 dai_link->codec_dai_name);
792 dev_dbg(card->dev, "CODEC %s not registered\n",
793 dai_link->codec_name);
796 /* do we need a platform? */
800 /* if there's no platform we match on the empty platform */
801 platform_name = dai_link->platform_name;
803 platform_name = "snd-soc-dummy";
805 /* no, then find one from the set of registered platforms */
806 list_for_each_entry(platform, &platform_list, list) {
807 if (!strcmp(platform->name, platform_name)) {
808 rtd->platform = platform;
813 dev_dbg(card->dev, "platform %s not registered\n",
814 dai_link->platform_name);
818 /* mark rtd as complete if we found all 4 of our client devices */
819 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
826 static void soc_remove_codec(struct snd_soc_codec *codec)
830 if (codec->driver->remove) {
831 err = codec->driver->remove(codec);
834 "asoc: failed to remove %s: %d\n",
838 /* Make sure all DAPM widgets are freed */
839 snd_soc_dapm_free(&codec->dapm);
841 soc_cleanup_codec_debugfs(codec);
843 list_del(&codec->card_list);
844 module_put(codec->dev->driver->owner);
847 static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
849 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
850 struct snd_soc_codec *codec = rtd->codec;
851 struct snd_soc_platform *platform = rtd->platform;
852 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
855 /* unregister the rtd device */
856 if (rtd->dev_registered) {
857 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
858 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
859 device_unregister(&rtd->dev);
860 rtd->dev_registered = 0;
863 /* remove the CODEC DAI */
864 if (codec_dai && codec_dai->probed &&
865 codec_dai->driver->remove_order == order) {
866 if (codec_dai->driver->remove) {
867 err = codec_dai->driver->remove(codec_dai);
869 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
871 codec_dai->probed = 0;
872 list_del(&codec_dai->card_list);
875 /* remove the platform */
876 if (platform && platform->probed &&
877 platform->driver->remove_order == order) {
878 if (platform->driver->remove) {
879 err = platform->driver->remove(platform);
881 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
883 platform->probed = 0;
884 list_del(&platform->card_list);
885 module_put(platform->dev->driver->owner);
888 /* remove the CODEC */
889 if (codec && codec->probed &&
890 codec->driver->remove_order == order)
891 soc_remove_codec(codec);
893 /* remove the cpu_dai */
894 if (cpu_dai && cpu_dai->probed &&
895 cpu_dai->driver->remove_order == order) {
896 if (cpu_dai->driver->remove) {
897 err = cpu_dai->driver->remove(cpu_dai);
899 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
902 list_del(&cpu_dai->card_list);
903 module_put(cpu_dai->dev->driver->owner);
907 static void soc_remove_dai_links(struct snd_soc_card *card)
911 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
913 for (dai = 0; dai < card->num_rtd; dai++)
914 soc_remove_dai_link(card, dai, order);
919 static void soc_set_name_prefix(struct snd_soc_card *card,
920 struct snd_soc_codec *codec)
924 if (card->codec_conf == NULL)
927 for (i = 0; i < card->num_configs; i++) {
928 struct snd_soc_codec_conf *map = &card->codec_conf[i];
929 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
930 codec->name_prefix = map->name_prefix;
936 static int soc_probe_codec(struct snd_soc_card *card,
937 struct snd_soc_codec *codec)
940 const struct snd_soc_codec_driver *driver = codec->driver;
943 codec->dapm.card = card;
944 soc_set_name_prefix(card, codec);
946 if (!try_module_get(codec->dev->driver->owner))
949 soc_init_codec_debugfs(codec);
951 if (driver->dapm_widgets)
952 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
953 driver->num_dapm_widgets);
955 codec->dapm.idle_bias_off = driver->idle_bias_off;
958 ret = driver->probe(codec);
961 "asoc: failed to probe CODEC %s: %d\n",
967 if (driver->controls)
968 snd_soc_add_controls(codec, driver->controls,
969 driver->num_controls);
970 if (driver->dapm_routes)
971 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
972 driver->num_dapm_routes);
974 /* mark codec as probed and add to card codec list */
976 list_add(&codec->card_list, &card->codec_dev_list);
977 list_add(&codec->dapm.list, &card->dapm_list);
982 soc_cleanup_codec_debugfs(codec);
983 module_put(codec->dev->driver->owner);
988 static int soc_probe_platform(struct snd_soc_card *card,
989 struct snd_soc_platform *platform)
992 const struct snd_soc_platform_driver *driver = platform->driver;
994 platform->card = card;
995 platform->dapm.card = card;
997 if (!try_module_get(platform->dev->driver->owner))
1000 if (driver->dapm_widgets)
1001 snd_soc_dapm_new_controls(&platform->dapm,
1002 driver->dapm_widgets, driver->num_dapm_widgets);
1004 if (driver->probe) {
1005 ret = driver->probe(platform);
1007 dev_err(platform->dev,
1008 "asoc: failed to probe platform %s: %d\n",
1009 platform->name, ret);
1014 if (driver->controls)
1015 snd_soc_add_platform_controls(platform, driver->controls,
1016 driver->num_controls);
1017 if (driver->dapm_routes)
1018 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1019 driver->num_dapm_routes);
1021 /* mark platform as probed and add to card platform list */
1022 platform->probed = 1;
1023 list_add(&platform->card_list, &card->platform_dev_list);
1024 list_add(&platform->dapm.list, &card->dapm_list);
1029 module_put(platform->dev->driver->owner);
1034 static void rtd_release(struct device *dev) {}
1036 static int soc_post_component_init(struct snd_soc_card *card,
1037 struct snd_soc_codec *codec,
1038 int num, int dailess)
1040 struct snd_soc_dai_link *dai_link = NULL;
1041 struct snd_soc_aux_dev *aux_dev = NULL;
1042 struct snd_soc_pcm_runtime *rtd;
1043 const char *temp, *name;
1047 dai_link = &card->dai_link[num];
1048 rtd = &card->rtd[num];
1049 name = dai_link->name;
1051 aux_dev = &card->aux_dev[num];
1052 rtd = &card->rtd_aux[num];
1053 name = aux_dev->name;
1057 /* machine controls, routes and widgets are not prefixed */
1058 temp = codec->name_prefix;
1059 codec->name_prefix = NULL;
1061 /* do machine specific initialization */
1062 if (!dailess && dai_link->init)
1063 ret = dai_link->init(rtd);
1064 else if (dailess && aux_dev->init)
1065 ret = aux_dev->init(&codec->dapm);
1067 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1070 codec->name_prefix = temp;
1072 /* Make sure all DAPM widgets are instantiated */
1073 snd_soc_dapm_new_widgets(&codec->dapm);
1075 /* register the rtd device */
1077 rtd->dev.parent = card->dev;
1078 rtd->dev.release = rtd_release;
1079 rtd->dev.init_name = name;
1080 mutex_init(&rtd->pcm_mutex);
1081 ret = device_register(&rtd->dev);
1084 "asoc: failed to register runtime device: %d\n", ret);
1087 rtd->dev_registered = 1;
1089 /* add DAPM sysfs entries for this codec */
1090 ret = snd_soc_dapm_sys_add(&rtd->dev);
1093 "asoc: failed to add codec dapm sysfs entries: %d\n",
1096 /* add codec sysfs entries */
1097 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1100 "asoc: failed to add codec sysfs files: %d\n", ret);
1105 static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1107 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1108 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1109 struct snd_soc_codec *codec = rtd->codec;
1110 struct snd_soc_platform *platform = rtd->platform;
1111 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1114 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1115 card->name, num, order);
1117 /* config components */
1118 codec_dai->codec = codec;
1119 cpu_dai->platform = platform;
1120 codec_dai->card = card;
1121 cpu_dai->card = card;
1123 /* set default power off timeout */
1124 rtd->pmdown_time = pmdown_time;
1126 /* probe the cpu_dai */
1127 if (!cpu_dai->probed &&
1128 cpu_dai->driver->probe_order == order) {
1129 if (!try_module_get(cpu_dai->dev->driver->owner))
1132 if (cpu_dai->driver->probe) {
1133 ret = cpu_dai->driver->probe(cpu_dai);
1135 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1137 module_put(cpu_dai->dev->driver->owner);
1141 cpu_dai->probed = 1;
1142 /* mark cpu_dai as probed and add to card dai list */
1143 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1146 /* probe the CODEC */
1147 if (!codec->probed &&
1148 codec->driver->probe_order == order) {
1149 ret = soc_probe_codec(card, codec);
1154 /* probe the platform */
1155 if (!platform->probed &&
1156 platform->driver->probe_order == order) {
1157 ret = soc_probe_platform(card, platform);
1162 /* probe the CODEC DAI */
1163 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1164 if (codec_dai->driver->probe) {
1165 ret = codec_dai->driver->probe(codec_dai);
1167 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1173 /* mark codec_dai as probed and add to card dai list */
1174 codec_dai->probed = 1;
1175 list_add(&codec_dai->card_list, &card->dai_dev_list);
1178 /* complete DAI probe during last probe */
1179 if (order != SND_SOC_COMP_ORDER_LAST)
1182 ret = soc_post_component_init(card, codec, num, 0);
1186 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1188 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1190 /* create the pcm */
1191 ret = soc_new_pcm(rtd, num);
1193 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1197 /* add platform data for AC97 devices */
1198 if (rtd->codec_dai->driver->ac97_control)
1199 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1204 #ifdef CONFIG_SND_SOC_AC97_BUS
1205 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1209 /* Only instantiate AC97 if not already done by the adaptor
1210 * for the generic AC97 subsystem.
1212 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1214 * It is possible that the AC97 device is already registered to
1215 * the device subsystem. This happens when the device is created
1216 * via snd_ac97_mixer(). Currently only SoC codec that does so
1217 * is the generic AC97 glue but others migh emerge.
1219 * In those cases we don't try to register the device again.
1221 if (!rtd->codec->ac97_created)
1224 ret = soc_ac97_dev_register(rtd->codec);
1226 printk(KERN_ERR "asoc: AC97 device register failed\n");
1230 rtd->codec->ac97_registered = 1;
1235 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1237 if (codec->ac97_registered) {
1238 soc_ac97_dev_unregister(codec);
1239 codec->ac97_registered = 0;
1244 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1246 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1247 struct snd_soc_codec *codec;
1250 /* find CODEC from registered CODECs*/
1251 list_for_each_entry(codec, &codec_list, list) {
1252 if (!strcmp(codec->name, aux_dev->codec_name)) {
1253 if (codec->probed) {
1255 "asoc: codec already probed");
1262 /* codec not found */
1263 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1267 ret = soc_probe_codec(card, codec);
1271 ret = soc_post_component_init(card, codec, num, 1);
1277 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1279 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1280 struct snd_soc_codec *codec = rtd->codec;
1282 /* unregister the rtd device */
1283 if (rtd->dev_registered) {
1284 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1285 device_unregister(&rtd->dev);
1286 rtd->dev_registered = 0;
1289 if (codec && codec->probed)
1290 soc_remove_codec(codec);
1293 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1294 enum snd_soc_compress_type compress_type)
1298 if (codec->cache_init)
1301 /* override the compress_type if necessary */
1302 if (compress_type && codec->compress_type != compress_type)
1303 codec->compress_type = compress_type;
1304 ret = snd_soc_cache_init(codec);
1306 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1310 codec->cache_init = 1;
1314 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1316 struct snd_soc_codec *codec;
1317 struct snd_soc_codec_conf *codec_conf;
1318 enum snd_soc_compress_type compress_type;
1321 mutex_lock(&card->mutex);
1323 if (card->instantiated) {
1324 mutex_unlock(&card->mutex);
1329 for (i = 0; i < card->num_links; i++)
1330 soc_bind_dai_link(card, i);
1332 /* bind completed ? */
1333 if (card->num_rtd != card->num_links) {
1334 mutex_unlock(&card->mutex);
1338 /* initialize the register cache for each available codec */
1339 list_for_each_entry(codec, &codec_list, list) {
1340 if (codec->cache_init)
1342 /* by default we don't override the compress_type */
1344 /* check to see if we need to override the compress_type */
1345 for (i = 0; i < card->num_configs; ++i) {
1346 codec_conf = &card->codec_conf[i];
1347 if (!strcmp(codec->name, codec_conf->dev_name)) {
1348 compress_type = codec_conf->compress_type;
1349 if (compress_type && compress_type
1350 != codec->compress_type)
1354 ret = snd_soc_init_codec_cache(codec, compress_type);
1356 mutex_unlock(&card->mutex);
1361 /* card bind complete so register a sound card */
1362 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1363 card->owner, 0, &card->snd_card);
1365 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1367 mutex_unlock(&card->mutex);
1370 card->snd_card->dev = card->dev;
1372 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1373 card->dapm.dev = card->dev;
1374 card->dapm.card = card;
1375 list_add(&card->dapm.list, &card->dapm_list);
1377 #ifdef CONFIG_DEBUG_FS
1378 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1381 #ifdef CONFIG_PM_SLEEP
1382 /* deferred resume work */
1383 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1386 if (card->dapm_widgets)
1387 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1388 card->num_dapm_widgets);
1390 /* initialise the sound card only once */
1392 ret = card->probe(card);
1394 goto card_probe_error;
1397 /* early DAI link probe */
1398 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1400 for (i = 0; i < card->num_links; i++) {
1401 ret = soc_probe_dai_link(card, i, order);
1403 pr_err("asoc: failed to instantiate card %s: %d\n",
1410 for (i = 0; i < card->num_aux_devs; i++) {
1411 ret = soc_probe_aux_dev(card, i);
1413 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1415 goto probe_aux_dev_err;
1419 /* We should have a non-codec control add function but we don't */
1421 snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
1422 struct snd_soc_codec,
1425 card->num_controls);
1427 if (card->dapm_routes)
1428 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1429 card->num_dapm_routes);
1431 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1433 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1434 "%s", card->long_name ? card->long_name : card->name);
1435 if (card->driver_name)
1436 strlcpy(card->snd_card->driver, card->driver_name,
1437 sizeof(card->snd_card->driver));
1439 if (card->late_probe) {
1440 ret = card->late_probe(card);
1442 dev_err(card->dev, "%s late_probe() failed: %d\n",
1444 goto probe_aux_dev_err;
1448 ret = snd_card_register(card->snd_card);
1450 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1451 goto probe_aux_dev_err;
1454 #ifdef CONFIG_SND_SOC_AC97_BUS
1455 /* register any AC97 codecs */
1456 for (i = 0; i < card->num_rtd; i++) {
1457 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1459 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1461 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1462 goto probe_aux_dev_err;
1467 card->instantiated = 1;
1468 mutex_unlock(&card->mutex);
1472 for (i = 0; i < card->num_aux_devs; i++)
1473 soc_remove_aux_dev(card, i);
1476 soc_remove_dai_links(card);
1482 snd_card_free(card->snd_card);
1484 mutex_unlock(&card->mutex);
1488 * Attempt to initialise any uninitialised cards. Must be called with
1491 static void snd_soc_instantiate_cards(void)
1493 struct snd_soc_card *card;
1494 list_for_each_entry(card, &card_list, list)
1495 snd_soc_instantiate_card(card);
1498 /* probes a new socdev */
1499 static int soc_probe(struct platform_device *pdev)
1501 struct snd_soc_card *card = platform_get_drvdata(pdev);
1505 * no card, so machine driver should be registering card
1506 * we should not be here in that case so ret error
1511 /* Bodge while we unpick instantiation */
1512 card->dev = &pdev->dev;
1514 ret = snd_soc_register_card(card);
1516 dev_err(&pdev->dev, "Failed to register card\n");
1523 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1527 /* make sure any delayed work runs */
1528 for (i = 0; i < card->num_rtd; i++) {
1529 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1530 flush_delayed_work_sync(&rtd->delayed_work);
1533 /* remove auxiliary devices */
1534 for (i = 0; i < card->num_aux_devs; i++)
1535 soc_remove_aux_dev(card, i);
1537 /* remove and free each DAI */
1538 soc_remove_dai_links(card);
1540 soc_cleanup_card_debugfs(card);
1542 /* remove the card */
1546 snd_soc_dapm_free(&card->dapm);
1549 snd_card_free(card->snd_card);
1554 /* removes a socdev */
1555 static int soc_remove(struct platform_device *pdev)
1557 struct snd_soc_card *card = platform_get_drvdata(pdev);
1559 snd_soc_unregister_card(card);
1563 int snd_soc_poweroff(struct device *dev)
1565 struct snd_soc_card *card = dev_get_drvdata(dev);
1568 if (!card->instantiated)
1571 /* Flush out pmdown_time work - we actually do want to run it
1572 * now, we're shutting down so no imminent restart. */
1573 for (i = 0; i < card->num_rtd; i++) {
1574 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1575 flush_delayed_work_sync(&rtd->delayed_work);
1578 snd_soc_dapm_shutdown(card);
1582 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1584 const struct dev_pm_ops snd_soc_pm_ops = {
1585 .suspend = snd_soc_suspend,
1586 .resume = snd_soc_resume,
1587 .poweroff = snd_soc_poweroff,
1589 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1591 /* ASoC platform driver */
1592 static struct platform_driver soc_driver = {
1594 .name = "soc-audio",
1595 .owner = THIS_MODULE,
1596 .pm = &snd_soc_pm_ops,
1599 .remove = soc_remove,
1603 * snd_soc_codec_volatile_register: Report if a register is volatile.
1605 * @codec: CODEC to query.
1606 * @reg: Register to query.
1608 * Boolean function indiciating if a CODEC register is volatile.
1610 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1613 if (codec->volatile_register)
1614 return codec->volatile_register(codec, reg);
1618 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1621 * snd_soc_codec_readable_register: Report if a register is readable.
1623 * @codec: CODEC to query.
1624 * @reg: Register to query.
1626 * Boolean function indicating if a CODEC register is readable.
1628 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1631 if (codec->readable_register)
1632 return codec->readable_register(codec, reg);
1636 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1639 * snd_soc_codec_writable_register: Report if a register is writable.
1641 * @codec: CODEC to query.
1642 * @reg: Register to query.
1644 * Boolean function indicating if a CODEC register is writable.
1646 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1649 if (codec->writable_register)
1650 return codec->writable_register(codec, reg);
1654 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1656 int snd_soc_platform_read(struct snd_soc_platform *platform,
1661 if (!platform->driver->read) {
1662 dev_err(platform->dev, "platform has no read back\n");
1666 ret = platform->driver->read(platform, reg);
1667 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
1668 trace_snd_soc_preg_read(platform, reg, ret);
1672 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1674 int snd_soc_platform_write(struct snd_soc_platform *platform,
1675 unsigned int reg, unsigned int val)
1677 if (!platform->driver->write) {
1678 dev_err(platform->dev, "platform has no write back\n");
1682 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
1683 trace_snd_soc_preg_write(platform, reg, val);
1684 return platform->driver->write(platform, reg, val);
1686 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1689 * snd_soc_new_ac97_codec - initailise AC97 device
1690 * @codec: audio codec
1691 * @ops: AC97 bus operations
1692 * @num: AC97 codec number
1694 * Initialises AC97 codec resources for use by ad-hoc devices only.
1696 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1697 struct snd_ac97_bus_ops *ops, int num)
1699 mutex_lock(&codec->mutex);
1701 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1702 if (codec->ac97 == NULL) {
1703 mutex_unlock(&codec->mutex);
1707 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1708 if (codec->ac97->bus == NULL) {
1711 mutex_unlock(&codec->mutex);
1715 codec->ac97->bus->ops = ops;
1716 codec->ac97->num = num;
1719 * Mark the AC97 device to be created by us. This way we ensure that the
1720 * device will be registered with the device subsystem later on.
1722 codec->ac97_created = 1;
1724 mutex_unlock(&codec->mutex);
1727 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1730 * snd_soc_free_ac97_codec - free AC97 codec device
1731 * @codec: audio codec
1733 * Frees AC97 codec device resources.
1735 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1737 mutex_lock(&codec->mutex);
1738 #ifdef CONFIG_SND_SOC_AC97_BUS
1739 soc_unregister_ac97_dai_link(codec);
1741 kfree(codec->ac97->bus);
1744 codec->ac97_created = 0;
1745 mutex_unlock(&codec->mutex);
1747 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1749 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1753 ret = codec->read(codec, reg);
1754 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
1755 trace_snd_soc_reg_read(codec, reg, ret);
1759 EXPORT_SYMBOL_GPL(snd_soc_read);
1761 unsigned int snd_soc_write(struct snd_soc_codec *codec,
1762 unsigned int reg, unsigned int val)
1764 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
1765 trace_snd_soc_reg_write(codec, reg, val);
1766 return codec->write(codec, reg, val);
1768 EXPORT_SYMBOL_GPL(snd_soc_write);
1770 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1771 unsigned int reg, const void *data, size_t len)
1773 return codec->bulk_write_raw(codec, reg, data, len);
1775 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1778 * snd_soc_update_bits - update codec register bits
1779 * @codec: audio codec
1780 * @reg: codec register
1781 * @mask: register mask
1784 * Writes new register value.
1786 * Returns 1 for change, 0 for no change, or negative error code.
1788 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1789 unsigned int mask, unsigned int value)
1792 unsigned int old, new;
1795 ret = snd_soc_read(codec, reg);
1800 new = (old & ~mask) | (value & mask);
1801 change = old != new;
1803 ret = snd_soc_write(codec, reg, new);
1810 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1813 * snd_soc_update_bits_locked - update codec register bits
1814 * @codec: audio codec
1815 * @reg: codec register
1816 * @mask: register mask
1819 * Writes new register value, and takes the codec mutex.
1821 * Returns 1 for change else 0.
1823 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1824 unsigned short reg, unsigned int mask,
1829 mutex_lock(&codec->mutex);
1830 change = snd_soc_update_bits(codec, reg, mask, value);
1831 mutex_unlock(&codec->mutex);
1835 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1838 * snd_soc_test_bits - test register for change
1839 * @codec: audio codec
1840 * @reg: codec register
1841 * @mask: register mask
1844 * Tests a register with a new value and checks if the new value is
1845 * different from the old value.
1847 * Returns 1 for change else 0.
1849 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1850 unsigned int mask, unsigned int value)
1853 unsigned int old, new;
1855 old = snd_soc_read(codec, reg);
1856 new = (old & ~mask) | value;
1857 change = old != new;
1861 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1864 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1865 * @substream: the pcm substream
1866 * @hw: the hardware parameters
1868 * Sets the substream runtime hardware parameters.
1870 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1871 const struct snd_pcm_hardware *hw)
1873 struct snd_pcm_runtime *runtime = substream->runtime;
1874 runtime->hw.info = hw->info;
1875 runtime->hw.formats = hw->formats;
1876 runtime->hw.period_bytes_min = hw->period_bytes_min;
1877 runtime->hw.period_bytes_max = hw->period_bytes_max;
1878 runtime->hw.periods_min = hw->periods_min;
1879 runtime->hw.periods_max = hw->periods_max;
1880 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1881 runtime->hw.fifo_size = hw->fifo_size;
1884 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1887 * snd_soc_cnew - create new control
1888 * @_template: control template
1889 * @data: control private data
1890 * @long_name: control long name
1891 * @prefix: control name prefix
1893 * Create a new mixer control from a template control.
1895 * Returns 0 for success, else error.
1897 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1898 void *data, char *long_name,
1901 struct snd_kcontrol_new template;
1902 struct snd_kcontrol *kcontrol;
1906 memcpy(&template, _template, sizeof(template));
1910 long_name = template.name;
1913 name_len = strlen(long_name) + strlen(prefix) + 2;
1914 name = kmalloc(name_len, GFP_KERNEL);
1918 snprintf(name, name_len, "%s %s", prefix, long_name);
1920 template.name = name;
1922 template.name = long_name;
1925 kcontrol = snd_ctl_new1(&template, data);
1931 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1934 * snd_soc_add_controls - add an array of controls to a codec.
1935 * Convienience function to add a list of controls. Many codecs were
1936 * duplicating this code.
1938 * @codec: codec to add controls to
1939 * @controls: array of controls to add
1940 * @num_controls: number of elements in the array
1942 * Return 0 for success, else error.
1944 int snd_soc_add_controls(struct snd_soc_codec *codec,
1945 const struct snd_kcontrol_new *controls, int num_controls)
1947 struct snd_card *card = codec->card->snd_card;
1950 for (i = 0; i < num_controls; i++) {
1951 const struct snd_kcontrol_new *control = &controls[i];
1952 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
1954 codec->name_prefix));
1956 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
1957 codec->name, control->name, err);
1964 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
1967 * snd_soc_add_platform_controls - add an array of controls to a platform.
1968 * Convienience function to add a list of controls.
1970 * @platform: platform to add controls to
1971 * @controls: array of controls to add
1972 * @num_controls: number of elements in the array
1974 * Return 0 for success, else error.
1976 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
1977 const struct snd_kcontrol_new *controls, int num_controls)
1979 struct snd_card *card = platform->card->snd_card;
1982 for (i = 0; i < num_controls; i++) {
1983 const struct snd_kcontrol_new *control = &controls[i];
1984 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
1985 control->name, NULL));
1987 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
1994 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
1997 * snd_soc_info_enum_double - enumerated double mixer info callback
1998 * @kcontrol: mixer control
1999 * @uinfo: control element information
2001 * Callback to provide information about a double enumerated
2004 * Returns 0 for success.
2006 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2007 struct snd_ctl_elem_info *uinfo)
2009 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2011 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2012 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2013 uinfo->value.enumerated.items = e->max;
2015 if (uinfo->value.enumerated.item > e->max - 1)
2016 uinfo->value.enumerated.item = e->max - 1;
2017 strcpy(uinfo->value.enumerated.name,
2018 e->texts[uinfo->value.enumerated.item]);
2021 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2024 * snd_soc_get_enum_double - enumerated double mixer get callback
2025 * @kcontrol: mixer control
2026 * @ucontrol: control element information
2028 * Callback to get the value of a double enumerated mixer.
2030 * Returns 0 for success.
2032 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2033 struct snd_ctl_elem_value *ucontrol)
2035 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2036 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2037 unsigned int val, bitmask;
2039 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2041 val = snd_soc_read(codec, e->reg);
2042 ucontrol->value.enumerated.item[0]
2043 = (val >> e->shift_l) & (bitmask - 1);
2044 if (e->shift_l != e->shift_r)
2045 ucontrol->value.enumerated.item[1] =
2046 (val >> e->shift_r) & (bitmask - 1);
2050 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2053 * snd_soc_put_enum_double - enumerated double mixer put callback
2054 * @kcontrol: mixer control
2055 * @ucontrol: control element information
2057 * Callback to set the value of a double enumerated mixer.
2059 * Returns 0 for success.
2061 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2062 struct snd_ctl_elem_value *ucontrol)
2064 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2065 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2067 unsigned int mask, bitmask;
2069 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2071 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2073 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2074 mask = (bitmask - 1) << e->shift_l;
2075 if (e->shift_l != e->shift_r) {
2076 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2078 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2079 mask |= (bitmask - 1) << e->shift_r;
2082 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2084 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2087 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2088 * @kcontrol: mixer control
2089 * @ucontrol: control element information
2091 * Callback to get the value of a double semi enumerated mixer.
2093 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2094 * used for handling bitfield coded enumeration for example.
2096 * Returns 0 for success.
2098 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2101 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2102 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2103 unsigned int reg_val, val, mux;
2105 reg_val = snd_soc_read(codec, e->reg);
2106 val = (reg_val >> e->shift_l) & e->mask;
2107 for (mux = 0; mux < e->max; mux++) {
2108 if (val == e->values[mux])
2111 ucontrol->value.enumerated.item[0] = mux;
2112 if (e->shift_l != e->shift_r) {
2113 val = (reg_val >> e->shift_r) & e->mask;
2114 for (mux = 0; mux < e->max; mux++) {
2115 if (val == e->values[mux])
2118 ucontrol->value.enumerated.item[1] = mux;
2123 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2126 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2127 * @kcontrol: mixer control
2128 * @ucontrol: control element information
2130 * Callback to set the value of a double semi enumerated mixer.
2132 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2133 * used for handling bitfield coded enumeration for example.
2135 * Returns 0 for success.
2137 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2138 struct snd_ctl_elem_value *ucontrol)
2140 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2141 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2145 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2147 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2148 mask = e->mask << e->shift_l;
2149 if (e->shift_l != e->shift_r) {
2150 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2152 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2153 mask |= e->mask << e->shift_r;
2156 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2158 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2161 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2162 * @kcontrol: mixer control
2163 * @uinfo: control element information
2165 * Callback to provide information about an external enumerated
2168 * Returns 0 for success.
2170 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2171 struct snd_ctl_elem_info *uinfo)
2173 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2175 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2177 uinfo->value.enumerated.items = e->max;
2179 if (uinfo->value.enumerated.item > e->max - 1)
2180 uinfo->value.enumerated.item = e->max - 1;
2181 strcpy(uinfo->value.enumerated.name,
2182 e->texts[uinfo->value.enumerated.item]);
2185 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2188 * snd_soc_info_volsw_ext - external single mixer info callback
2189 * @kcontrol: mixer control
2190 * @uinfo: control element information
2192 * Callback to provide information about a single external mixer control.
2194 * Returns 0 for success.
2196 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2197 struct snd_ctl_elem_info *uinfo)
2199 int max = kcontrol->private_value;
2201 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2202 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2204 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2207 uinfo->value.integer.min = 0;
2208 uinfo->value.integer.max = max;
2211 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2214 * snd_soc_info_volsw - single mixer info callback
2215 * @kcontrol: mixer control
2216 * @uinfo: control element information
2218 * Callback to provide information about a single mixer control.
2220 * Returns 0 for success.
2222 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2223 struct snd_ctl_elem_info *uinfo)
2225 struct soc_mixer_control *mc =
2226 (struct soc_mixer_control *)kcontrol->private_value;
2228 unsigned int shift = mc->shift;
2229 unsigned int rshift = mc->rshift;
2231 if (!mc->platform_max)
2232 mc->platform_max = mc->max;
2233 platform_max = mc->platform_max;
2235 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2236 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2238 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2240 uinfo->count = shift == rshift ? 1 : 2;
2241 uinfo->value.integer.min = 0;
2242 uinfo->value.integer.max = platform_max;
2245 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2248 * snd_soc_get_volsw - single mixer get callback
2249 * @kcontrol: mixer control
2250 * @ucontrol: control element information
2252 * Callback to get the value of a single mixer control.
2254 * Returns 0 for success.
2256 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2257 struct snd_ctl_elem_value *ucontrol)
2259 struct soc_mixer_control *mc =
2260 (struct soc_mixer_control *)kcontrol->private_value;
2261 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2262 unsigned int reg = mc->reg;
2263 unsigned int shift = mc->shift;
2264 unsigned int rshift = mc->rshift;
2266 unsigned int mask = (1 << fls(max)) - 1;
2267 unsigned int invert = mc->invert;
2269 ucontrol->value.integer.value[0] =
2270 (snd_soc_read(codec, reg) >> shift) & mask;
2271 if (shift != rshift)
2272 ucontrol->value.integer.value[1] =
2273 (snd_soc_read(codec, reg) >> rshift) & mask;
2275 ucontrol->value.integer.value[0] =
2276 max - ucontrol->value.integer.value[0];
2277 if (shift != rshift)
2278 ucontrol->value.integer.value[1] =
2279 max - ucontrol->value.integer.value[1];
2284 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2287 * snd_soc_put_volsw - single mixer put callback
2288 * @kcontrol: mixer control
2289 * @ucontrol: control element information
2291 * Callback to set the value of a single mixer control.
2293 * Returns 0 for success.
2295 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2296 struct snd_ctl_elem_value *ucontrol)
2298 struct soc_mixer_control *mc =
2299 (struct soc_mixer_control *)kcontrol->private_value;
2300 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2301 unsigned int reg = mc->reg;
2302 unsigned int shift = mc->shift;
2303 unsigned int rshift = mc->rshift;
2305 unsigned int mask = (1 << fls(max)) - 1;
2306 unsigned int invert = mc->invert;
2307 unsigned int val, val2, val_mask;
2309 val = (ucontrol->value.integer.value[0] & mask);
2312 val_mask = mask << shift;
2314 if (shift != rshift) {
2315 val2 = (ucontrol->value.integer.value[1] & mask);
2318 val_mask |= mask << rshift;
2319 val |= val2 << rshift;
2321 return snd_soc_update_bits_locked(codec, reg, val_mask, val);
2323 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2326 * snd_soc_info_volsw_2r - double mixer info callback
2327 * @kcontrol: mixer control
2328 * @uinfo: control element information
2330 * Callback to provide information about a double mixer control that
2331 * spans 2 codec registers.
2333 * Returns 0 for success.
2335 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
2336 struct snd_ctl_elem_info *uinfo)
2338 struct soc_mixer_control *mc =
2339 (struct soc_mixer_control *)kcontrol->private_value;
2342 if (!mc->platform_max)
2343 mc->platform_max = mc->max;
2344 platform_max = mc->platform_max;
2346 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2347 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2349 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2352 uinfo->value.integer.min = 0;
2353 uinfo->value.integer.max = platform_max;
2356 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
2359 * snd_soc_get_volsw_2r - double mixer get callback
2360 * @kcontrol: mixer control
2361 * @ucontrol: control element information
2363 * Callback to get the value of a double mixer control that spans 2 registers.
2365 * Returns 0 for success.
2367 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
2368 struct snd_ctl_elem_value *ucontrol)
2370 struct soc_mixer_control *mc =
2371 (struct soc_mixer_control *)kcontrol->private_value;
2372 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2373 unsigned int reg = mc->reg;
2374 unsigned int reg2 = mc->rreg;
2375 unsigned int shift = mc->shift;
2377 unsigned int mask = (1 << fls(max)) - 1;
2378 unsigned int invert = mc->invert;
2380 ucontrol->value.integer.value[0] =
2381 (snd_soc_read(codec, reg) >> shift) & mask;
2382 ucontrol->value.integer.value[1] =
2383 (snd_soc_read(codec, reg2) >> shift) & mask;
2385 ucontrol->value.integer.value[0] =
2386 max - ucontrol->value.integer.value[0];
2387 ucontrol->value.integer.value[1] =
2388 max - ucontrol->value.integer.value[1];
2393 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
2396 * snd_soc_put_volsw_2r - double mixer set callback
2397 * @kcontrol: mixer control
2398 * @ucontrol: control element information
2400 * Callback to set the value of a double mixer control that spans 2 registers.
2402 * Returns 0 for success.
2404 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2407 struct soc_mixer_control *mc =
2408 (struct soc_mixer_control *)kcontrol->private_value;
2409 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2410 unsigned int reg = mc->reg;
2411 unsigned int reg2 = mc->rreg;
2412 unsigned int shift = mc->shift;
2414 unsigned int mask = (1 << fls(max)) - 1;
2415 unsigned int invert = mc->invert;
2417 unsigned int val, val2, val_mask;
2419 val_mask = mask << shift;
2420 val = (ucontrol->value.integer.value[0] & mask);
2421 val2 = (ucontrol->value.integer.value[1] & mask);
2429 val2 = val2 << shift;
2431 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2435 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2438 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
2441 * snd_soc_info_volsw_s8 - signed mixer info callback
2442 * @kcontrol: mixer control
2443 * @uinfo: control element information
2445 * Callback to provide information about a signed mixer control.
2447 * Returns 0 for success.
2449 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2450 struct snd_ctl_elem_info *uinfo)
2452 struct soc_mixer_control *mc =
2453 (struct soc_mixer_control *)kcontrol->private_value;
2457 if (!mc->platform_max)
2458 mc->platform_max = mc->max;
2459 platform_max = mc->platform_max;
2461 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2463 uinfo->value.integer.min = 0;
2464 uinfo->value.integer.max = platform_max - min;
2467 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2470 * snd_soc_get_volsw_s8 - signed mixer get callback
2471 * @kcontrol: mixer control
2472 * @ucontrol: control element information
2474 * Callback to get the value of a signed mixer control.
2476 * Returns 0 for success.
2478 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2479 struct snd_ctl_elem_value *ucontrol)
2481 struct soc_mixer_control *mc =
2482 (struct soc_mixer_control *)kcontrol->private_value;
2483 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2484 unsigned int reg = mc->reg;
2486 int val = snd_soc_read(codec, reg);
2488 ucontrol->value.integer.value[0] =
2489 ((signed char)(val & 0xff))-min;
2490 ucontrol->value.integer.value[1] =
2491 ((signed char)((val >> 8) & 0xff))-min;
2494 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2497 * snd_soc_put_volsw_sgn - signed mixer put callback
2498 * @kcontrol: mixer control
2499 * @ucontrol: control element information
2501 * Callback to set the value of a signed mixer control.
2503 * Returns 0 for success.
2505 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2506 struct snd_ctl_elem_value *ucontrol)
2508 struct soc_mixer_control *mc =
2509 (struct soc_mixer_control *)kcontrol->private_value;
2510 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2511 unsigned int reg = mc->reg;
2515 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2516 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2518 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2520 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2523 * snd_soc_limit_volume - Set new limit to an existing volume control.
2525 * @codec: where to look for the control
2526 * @name: Name of the control
2527 * @max: new maximum limit
2529 * Return 0 for success, else error.
2531 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2532 const char *name, int max)
2534 struct snd_card *card = codec->card->snd_card;
2535 struct snd_kcontrol *kctl;
2536 struct soc_mixer_control *mc;
2540 /* Sanity check for name and max */
2541 if (unlikely(!name || max <= 0))
2544 list_for_each_entry(kctl, &card->controls, list) {
2545 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2551 mc = (struct soc_mixer_control *)kctl->private_value;
2552 if (max <= mc->max) {
2553 mc->platform_max = max;
2559 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2562 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2563 * mixer info callback
2564 * @kcontrol: mixer control
2565 * @uinfo: control element information
2567 * Returns 0 for success.
2569 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_info *uinfo)
2572 struct soc_mixer_control *mc =
2573 (struct soc_mixer_control *)kcontrol->private_value;
2577 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2579 uinfo->value.integer.min = 0;
2580 uinfo->value.integer.max = max-min;
2584 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2587 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2588 * mixer get callback
2589 * @kcontrol: mixer control
2590 * @uinfo: control element information
2592 * Returns 0 for success.
2594 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2595 struct snd_ctl_elem_value *ucontrol)
2597 struct soc_mixer_control *mc =
2598 (struct soc_mixer_control *)kcontrol->private_value;
2599 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2600 unsigned int mask = (1<<mc->shift)-1;
2602 int val = snd_soc_read(codec, mc->reg) & mask;
2603 int valr = snd_soc_read(codec, mc->rreg) & mask;
2605 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2606 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2609 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2612 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2613 * mixer put callback
2614 * @kcontrol: mixer control
2615 * @uinfo: control element information
2617 * Returns 0 for success.
2619 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2620 struct snd_ctl_elem_value *ucontrol)
2622 struct soc_mixer_control *mc =
2623 (struct soc_mixer_control *)kcontrol->private_value;
2624 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2625 unsigned int mask = (1<<mc->shift)-1;
2628 unsigned int val, valr, oval, ovalr;
2630 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2632 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2635 oval = snd_soc_read(codec, mc->reg) & mask;
2636 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2640 ret = snd_soc_write(codec, mc->reg, val);
2644 if (ovalr != valr) {
2645 ret = snd_soc_write(codec, mc->rreg, valr);
2652 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2655 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2657 * @clk_id: DAI specific clock ID
2658 * @freq: new clock frequency in Hz
2659 * @dir: new clock direction - input/output.
2661 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2663 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2664 unsigned int freq, int dir)
2666 if (dai->driver && dai->driver->ops->set_sysclk)
2667 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2668 else if (dai->codec && dai->codec->driver->set_sysclk)
2669 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2674 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2677 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2679 * @clk_id: DAI specific clock ID
2680 * @source: Source for the clock
2681 * @freq: new clock frequency in Hz
2682 * @dir: new clock direction - input/output.
2684 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2686 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2687 int source, unsigned int freq, int dir)
2689 if (codec->driver->set_sysclk)
2690 return codec->driver->set_sysclk(codec, clk_id, source,
2695 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2698 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2700 * @div_id: DAI specific clock divider ID
2701 * @div: new clock divisor.
2703 * Configures the clock dividers. This is used to derive the best DAI bit and
2704 * frame clocks from the system or master clock. It's best to set the DAI bit
2705 * and frame clocks as low as possible to save system power.
2707 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2708 int div_id, int div)
2710 if (dai->driver && dai->driver->ops->set_clkdiv)
2711 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2715 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2718 * snd_soc_dai_set_pll - configure DAI PLL.
2720 * @pll_id: DAI specific PLL ID
2721 * @source: DAI specific source for the PLL
2722 * @freq_in: PLL input clock frequency in Hz
2723 * @freq_out: requested PLL output clock frequency in Hz
2725 * Configures and enables PLL to generate output clock based on input clock.
2727 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2728 unsigned int freq_in, unsigned int freq_out)
2730 if (dai->driver && dai->driver->ops->set_pll)
2731 return dai->driver->ops->set_pll(dai, pll_id, source,
2733 else if (dai->codec && dai->codec->driver->set_pll)
2734 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2739 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2742 * snd_soc_codec_set_pll - configure codec PLL.
2744 * @pll_id: DAI specific PLL ID
2745 * @source: DAI specific source for the PLL
2746 * @freq_in: PLL input clock frequency in Hz
2747 * @freq_out: requested PLL output clock frequency in Hz
2749 * Configures and enables PLL to generate output clock based on input clock.
2751 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2752 unsigned int freq_in, unsigned int freq_out)
2754 if (codec->driver->set_pll)
2755 return codec->driver->set_pll(codec, pll_id, source,
2760 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2763 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2765 * @fmt: SND_SOC_DAIFMT_ format value.
2767 * Configures the DAI hardware format and clocking.
2769 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2771 if (dai->driver && dai->driver->ops->set_fmt)
2772 return dai->driver->ops->set_fmt(dai, fmt);
2776 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2779 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2781 * @tx_mask: bitmask representing active TX slots.
2782 * @rx_mask: bitmask representing active RX slots.
2783 * @slots: Number of slots in use.
2784 * @slot_width: Width in bits for each slot.
2786 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2789 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2790 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2792 if (dai->driver && dai->driver->ops->set_tdm_slot)
2793 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2798 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2801 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2803 * @tx_num: how many TX channels
2804 * @tx_slot: pointer to an array which imply the TX slot number channel
2806 * @rx_num: how many RX channels
2807 * @rx_slot: pointer to an array which imply the RX slot number channel
2810 * configure the relationship between channel number and TDM slot number.
2812 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2813 unsigned int tx_num, unsigned int *tx_slot,
2814 unsigned int rx_num, unsigned int *rx_slot)
2816 if (dai->driver && dai->driver->ops->set_channel_map)
2817 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2822 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2825 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2827 * @tristate: tristate enable
2829 * Tristates the DAI so that others can use it.
2831 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2833 if (dai->driver && dai->driver->ops->set_tristate)
2834 return dai->driver->ops->set_tristate(dai, tristate);
2838 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2841 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2843 * @mute: mute enable
2845 * Mutes the DAI DAC.
2847 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2849 if (dai->driver && dai->driver->ops->digital_mute)
2850 return dai->driver->ops->digital_mute(dai, mute);
2854 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2857 * snd_soc_register_card - Register a card with the ASoC core
2859 * @card: Card to register
2862 int snd_soc_register_card(struct snd_soc_card *card)
2866 if (!card->name || !card->dev)
2869 dev_set_drvdata(card->dev, card);
2871 snd_soc_initialize_card_lists(card);
2873 soc_init_card_debugfs(card);
2875 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2876 (card->num_links + card->num_aux_devs),
2878 if (card->rtd == NULL)
2880 card->rtd_aux = &card->rtd[card->num_links];
2882 for (i = 0; i < card->num_links; i++)
2883 card->rtd[i].dai_link = &card->dai_link[i];
2885 INIT_LIST_HEAD(&card->list);
2886 card->instantiated = 0;
2887 mutex_init(&card->mutex);
2889 mutex_lock(&client_mutex);
2890 list_add(&card->list, &card_list);
2891 snd_soc_instantiate_cards();
2892 mutex_unlock(&client_mutex);
2894 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2898 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2901 * snd_soc_unregister_card - Unregister a card with the ASoC core
2903 * @card: Card to unregister
2906 int snd_soc_unregister_card(struct snd_soc_card *card)
2908 if (card->instantiated)
2909 soc_cleanup_card_resources(card);
2910 mutex_lock(&client_mutex);
2911 list_del(&card->list);
2912 mutex_unlock(&client_mutex);
2913 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2917 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2920 * Simplify DAI link configuration by removing ".-1" from device names
2921 * and sanitizing names.
2923 static char *fmt_single_name(struct device *dev, int *id)
2925 char *found, name[NAME_SIZE];
2928 if (dev_name(dev) == NULL)
2931 strlcpy(name, dev_name(dev), NAME_SIZE);
2933 /* are we a "%s.%d" name (platform and SPI components) */
2934 found = strstr(name, dev->driver->name);
2937 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2939 /* discard ID from name if ID == -1 */
2941 found[strlen(dev->driver->name)] = '\0';
2945 /* I2C component devices are named "bus-addr" */
2946 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2947 char tmp[NAME_SIZE];
2949 /* create unique ID number from I2C addr and bus */
2950 *id = ((id1 & 0xffff) << 16) + id2;
2952 /* sanitize component name for DAI link creation */
2953 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2954 strlcpy(name, tmp, NAME_SIZE);
2959 return kstrdup(name, GFP_KERNEL);
2963 * Simplify DAI link naming for single devices with multiple DAIs by removing
2964 * any ".-1" and using the DAI name (instead of device name).
2966 static inline char *fmt_multiple_name(struct device *dev,
2967 struct snd_soc_dai_driver *dai_drv)
2969 if (dai_drv->name == NULL) {
2970 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2975 return kstrdup(dai_drv->name, GFP_KERNEL);
2979 * snd_soc_register_dai - Register a DAI with the ASoC core
2981 * @dai: DAI to register
2983 int snd_soc_register_dai(struct device *dev,
2984 struct snd_soc_dai_driver *dai_drv)
2986 struct snd_soc_dai *dai;
2988 dev_dbg(dev, "dai register %s\n", dev_name(dev));
2990 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2994 /* create DAI component name */
2995 dai->name = fmt_single_name(dev, &dai->id);
2996 if (dai->name == NULL) {
3002 dai->driver = dai_drv;
3003 if (!dai->driver->ops)
3004 dai->driver->ops = &null_dai_ops;
3006 mutex_lock(&client_mutex);
3007 list_add(&dai->list, &dai_list);
3008 snd_soc_instantiate_cards();
3009 mutex_unlock(&client_mutex);
3011 pr_debug("Registered DAI '%s'\n", dai->name);
3015 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3018 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3020 * @dai: DAI to unregister
3022 void snd_soc_unregister_dai(struct device *dev)
3024 struct snd_soc_dai *dai;
3026 list_for_each_entry(dai, &dai_list, list) {
3027 if (dev == dai->dev)
3033 mutex_lock(&client_mutex);
3034 list_del(&dai->list);
3035 mutex_unlock(&client_mutex);
3037 pr_debug("Unregistered DAI '%s'\n", dai->name);
3041 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3044 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3046 * @dai: Array of DAIs to register
3047 * @count: Number of DAIs
3049 int snd_soc_register_dais(struct device *dev,
3050 struct snd_soc_dai_driver *dai_drv, size_t count)
3052 struct snd_soc_dai *dai;
3055 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3057 for (i = 0; i < count; i++) {
3059 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3065 /* create DAI component name */
3066 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3067 if (dai->name == NULL) {
3074 dai->driver = &dai_drv[i];
3075 if (dai->driver->id)
3076 dai->id = dai->driver->id;
3079 if (!dai->driver->ops)
3080 dai->driver->ops = &null_dai_ops;
3082 mutex_lock(&client_mutex);
3083 list_add(&dai->list, &dai_list);
3084 mutex_unlock(&client_mutex);
3086 pr_debug("Registered DAI '%s'\n", dai->name);
3089 mutex_lock(&client_mutex);
3090 snd_soc_instantiate_cards();
3091 mutex_unlock(&client_mutex);
3095 for (i--; i >= 0; i--)
3096 snd_soc_unregister_dai(dev);
3100 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3103 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3105 * @dai: Array of DAIs to unregister
3106 * @count: Number of DAIs
3108 void snd_soc_unregister_dais(struct device *dev, size_t count)
3112 for (i = 0; i < count; i++)
3113 snd_soc_unregister_dai(dev);
3115 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3118 * snd_soc_register_platform - Register a platform with the ASoC core
3120 * @platform: platform to register
3122 int snd_soc_register_platform(struct device *dev,
3123 struct snd_soc_platform_driver *platform_drv)
3125 struct snd_soc_platform *platform;
3127 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3129 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3130 if (platform == NULL)
3133 /* create platform component name */
3134 platform->name = fmt_single_name(dev, &platform->id);
3135 if (platform->name == NULL) {
3140 platform->dev = dev;
3141 platform->driver = platform_drv;
3142 platform->dapm.dev = dev;
3143 platform->dapm.platform = platform;
3144 platform->dapm.stream_event = platform_drv->stream_event;
3146 mutex_lock(&client_mutex);
3147 list_add(&platform->list, &platform_list);
3148 snd_soc_instantiate_cards();
3149 mutex_unlock(&client_mutex);
3151 pr_debug("Registered platform '%s'\n", platform->name);
3155 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3158 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3160 * @platform: platform to unregister
3162 void snd_soc_unregister_platform(struct device *dev)
3164 struct snd_soc_platform *platform;
3166 list_for_each_entry(platform, &platform_list, list) {
3167 if (dev == platform->dev)
3173 mutex_lock(&client_mutex);
3174 list_del(&platform->list);
3175 mutex_unlock(&client_mutex);
3177 pr_debug("Unregistered platform '%s'\n", platform->name);
3178 kfree(platform->name);
3181 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3183 static u64 codec_format_map[] = {
3184 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3185 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3186 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3187 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3188 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3189 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3190 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3191 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3192 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3193 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3194 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3195 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3196 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3197 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3198 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3199 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3202 /* Fix up the DAI formats for endianness: codecs don't actually see
3203 * the endianness of the data but we're using the CPU format
3204 * definitions which do need to include endianness so we ensure that
3205 * codec DAIs always have both big and little endian variants set.
3207 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3211 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3212 if (stream->formats & codec_format_map[i])
3213 stream->formats |= codec_format_map[i];
3217 * snd_soc_register_codec - Register a codec with the ASoC core
3219 * @codec: codec to register
3221 int snd_soc_register_codec(struct device *dev,
3222 const struct snd_soc_codec_driver *codec_drv,
3223 struct snd_soc_dai_driver *dai_drv,
3227 struct snd_soc_codec *codec;
3230 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3232 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3236 /* create CODEC component name */
3237 codec->name = fmt_single_name(dev, &codec->id);
3238 if (codec->name == NULL) {
3243 if (codec_drv->compress_type)
3244 codec->compress_type = codec_drv->compress_type;
3246 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3248 codec->write = codec_drv->write;
3249 codec->read = codec_drv->read;
3250 codec->volatile_register = codec_drv->volatile_register;
3251 codec->readable_register = codec_drv->readable_register;
3252 codec->writable_register = codec_drv->writable_register;
3253 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3254 codec->dapm.dev = dev;
3255 codec->dapm.codec = codec;
3256 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3257 codec->dapm.stream_event = codec_drv->stream_event;
3259 codec->driver = codec_drv;
3260 codec->num_dai = num_dai;
3261 mutex_init(&codec->mutex);
3263 /* allocate CODEC register cache */
3264 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3265 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3266 codec->reg_size = reg_size;
3267 /* it is necessary to make a copy of the default register cache
3268 * because in the case of using a compression type that requires
3269 * the default register cache to be marked as __devinitconst the
3270 * kernel might have freed the array by the time we initialize
3273 if (codec_drv->reg_cache_default) {
3274 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3275 reg_size, GFP_KERNEL);
3276 if (!codec->reg_def_copy) {
3283 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3284 if (!codec->volatile_register)
3285 codec->volatile_register = snd_soc_default_volatile_register;
3286 if (!codec->readable_register)
3287 codec->readable_register = snd_soc_default_readable_register;
3288 if (!codec->writable_register)
3289 codec->writable_register = snd_soc_default_writable_register;
3292 for (i = 0; i < num_dai; i++) {
3293 fixup_codec_formats(&dai_drv[i].playback);
3294 fixup_codec_formats(&dai_drv[i].capture);
3297 /* register any DAIs */
3299 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3304 mutex_lock(&client_mutex);
3305 list_add(&codec->list, &codec_list);
3306 snd_soc_instantiate_cards();
3307 mutex_unlock(&client_mutex);
3309 pr_debug("Registered codec '%s'\n", codec->name);
3313 kfree(codec->reg_def_copy);
3314 codec->reg_def_copy = NULL;
3319 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3322 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3324 * @codec: codec to unregister
3326 void snd_soc_unregister_codec(struct device *dev)
3328 struct snd_soc_codec *codec;
3331 list_for_each_entry(codec, &codec_list, list) {
3332 if (dev == codec->dev)
3339 for (i = 0; i < codec->num_dai; i++)
3340 snd_soc_unregister_dai(dev);
3342 mutex_lock(&client_mutex);
3343 list_del(&codec->list);
3344 mutex_unlock(&client_mutex);
3346 pr_debug("Unregistered codec '%s'\n", codec->name);
3348 snd_soc_cache_exit(codec);
3349 kfree(codec->reg_def_copy);
3353 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3355 static int __init snd_soc_init(void)
3357 #ifdef CONFIG_DEBUG_FS
3358 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3359 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
3361 "ASoC: Failed to create debugfs directory\n");
3362 snd_soc_debugfs_root = NULL;
3365 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
3367 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3369 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
3371 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3373 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
3374 &platform_list_fops))
3375 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3378 snd_soc_util_init();
3380 return platform_driver_register(&soc_driver);
3382 module_init(snd_soc_init);
3384 static void __exit snd_soc_exit(void)
3386 snd_soc_util_exit();
3388 #ifdef CONFIG_DEBUG_FS
3389 debugfs_remove_recursive(snd_soc_debugfs_root);
3391 platform_driver_unregister(&soc_driver);
3393 module_exit(snd_soc_exit);
3395 /* Module information */
3396 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3397 MODULE_DESCRIPTION("ALSA SoC Core");
3398 MODULE_LICENSE("GPL");
3399 MODULE_ALIAS("platform:soc-audio");