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 (dai_link->cpu_dai_of_node) {
768 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
771 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
775 rtd->cpu_dai = cpu_dai;
778 dev_dbg(card->dev, "CPU DAI %s not registered\n",
779 dai_link->cpu_dai_name);
782 /* do we already have the CODEC for this link ? */
787 /* no, then find CODEC from registered CODECs*/
788 list_for_each_entry(codec, &codec_list, list) {
789 if (dai_link->codec_of_node) {
790 if (codec->dev->of_node != dai_link->codec_of_node)
793 if (strcmp(codec->name, dai_link->codec_name))
800 * CODEC found, so find CODEC DAI from registered DAIs from
803 list_for_each_entry(codec_dai, &dai_list, list) {
804 if (codec->dev == codec_dai->dev &&
805 !strcmp(codec_dai->name,
806 dai_link->codec_dai_name)) {
808 rtd->codec_dai = codec_dai;
812 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
813 dai_link->codec_dai_name);
817 dev_dbg(card->dev, "CODEC %s not registered\n",
818 dai_link->codec_name);
821 /* do we need a platform? */
825 /* if there's no platform we match on the empty platform */
826 platform_name = dai_link->platform_name;
827 if (!platform_name && !dai_link->platform_of_node)
828 platform_name = "snd-soc-dummy";
830 /* no, then find one from the set of registered platforms */
831 list_for_each_entry(platform, &platform_list, list) {
832 if (dai_link->platform_of_node) {
833 if (platform->dev->of_node !=
834 dai_link->platform_of_node)
837 if (strcmp(platform->name, platform_name))
841 rtd->platform = platform;
845 dev_dbg(card->dev, "platform %s not registered\n",
846 dai_link->platform_name);
850 /* mark rtd as complete if we found all 4 of our client devices */
851 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
858 static void soc_remove_codec(struct snd_soc_codec *codec)
862 if (codec->driver->remove) {
863 err = codec->driver->remove(codec);
866 "asoc: failed to remove %s: %d\n",
870 /* Make sure all DAPM widgets are freed */
871 snd_soc_dapm_free(&codec->dapm);
873 soc_cleanup_codec_debugfs(codec);
875 list_del(&codec->card_list);
876 module_put(codec->dev->driver->owner);
879 static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
881 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
882 struct snd_soc_codec *codec = rtd->codec;
883 struct snd_soc_platform *platform = rtd->platform;
884 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
887 /* unregister the rtd device */
888 if (rtd->dev_registered) {
889 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
890 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
891 device_unregister(&rtd->dev);
892 rtd->dev_registered = 0;
895 /* remove the CODEC DAI */
896 if (codec_dai && codec_dai->probed &&
897 codec_dai->driver->remove_order == order) {
898 if (codec_dai->driver->remove) {
899 err = codec_dai->driver->remove(codec_dai);
901 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
903 codec_dai->probed = 0;
904 list_del(&codec_dai->card_list);
907 /* remove the platform */
908 if (platform && platform->probed &&
909 platform->driver->remove_order == order) {
910 if (platform->driver->remove) {
911 err = platform->driver->remove(platform);
913 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
915 platform->probed = 0;
916 list_del(&platform->card_list);
917 module_put(platform->dev->driver->owner);
920 /* remove the CODEC */
921 if (codec && codec->probed &&
922 codec->driver->remove_order == order)
923 soc_remove_codec(codec);
925 /* remove the cpu_dai */
926 if (cpu_dai && cpu_dai->probed &&
927 cpu_dai->driver->remove_order == order) {
928 if (cpu_dai->driver->remove) {
929 err = cpu_dai->driver->remove(cpu_dai);
931 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
934 list_del(&cpu_dai->card_list);
935 module_put(cpu_dai->dev->driver->owner);
939 static void soc_remove_dai_links(struct snd_soc_card *card)
943 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
945 for (dai = 0; dai < card->num_rtd; dai++)
946 soc_remove_dai_link(card, dai, order);
951 static void soc_set_name_prefix(struct snd_soc_card *card,
952 struct snd_soc_codec *codec)
956 if (card->codec_conf == NULL)
959 for (i = 0; i < card->num_configs; i++) {
960 struct snd_soc_codec_conf *map = &card->codec_conf[i];
961 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
962 codec->name_prefix = map->name_prefix;
968 static int soc_probe_codec(struct snd_soc_card *card,
969 struct snd_soc_codec *codec)
972 const struct snd_soc_codec_driver *driver = codec->driver;
975 codec->dapm.card = card;
976 soc_set_name_prefix(card, codec);
978 if (!try_module_get(codec->dev->driver->owner))
981 soc_init_codec_debugfs(codec);
983 if (driver->dapm_widgets)
984 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
985 driver->num_dapm_widgets);
987 codec->dapm.idle_bias_off = driver->idle_bias_off;
990 ret = driver->probe(codec);
993 "asoc: failed to probe CODEC %s: %d\n",
999 if (driver->controls)
1000 snd_soc_add_controls(codec, driver->controls,
1001 driver->num_controls);
1002 if (driver->dapm_routes)
1003 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1004 driver->num_dapm_routes);
1006 /* mark codec as probed and add to card codec list */
1008 list_add(&codec->card_list, &card->codec_dev_list);
1009 list_add(&codec->dapm.list, &card->dapm_list);
1014 soc_cleanup_codec_debugfs(codec);
1015 module_put(codec->dev->driver->owner);
1020 static int soc_probe_platform(struct snd_soc_card *card,
1021 struct snd_soc_platform *platform)
1024 const struct snd_soc_platform_driver *driver = platform->driver;
1026 platform->card = card;
1027 platform->dapm.card = card;
1029 if (!try_module_get(platform->dev->driver->owner))
1032 if (driver->dapm_widgets)
1033 snd_soc_dapm_new_controls(&platform->dapm,
1034 driver->dapm_widgets, driver->num_dapm_widgets);
1036 if (driver->probe) {
1037 ret = driver->probe(platform);
1039 dev_err(platform->dev,
1040 "asoc: failed to probe platform %s: %d\n",
1041 platform->name, ret);
1046 if (driver->controls)
1047 snd_soc_add_platform_controls(platform, driver->controls,
1048 driver->num_controls);
1049 if (driver->dapm_routes)
1050 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1051 driver->num_dapm_routes);
1053 /* mark platform as probed and add to card platform list */
1054 platform->probed = 1;
1055 list_add(&platform->card_list, &card->platform_dev_list);
1056 list_add(&platform->dapm.list, &card->dapm_list);
1061 module_put(platform->dev->driver->owner);
1066 static void rtd_release(struct device *dev) {}
1068 static int soc_post_component_init(struct snd_soc_card *card,
1069 struct snd_soc_codec *codec,
1070 int num, int dailess)
1072 struct snd_soc_dai_link *dai_link = NULL;
1073 struct snd_soc_aux_dev *aux_dev = NULL;
1074 struct snd_soc_pcm_runtime *rtd;
1075 const char *temp, *name;
1079 dai_link = &card->dai_link[num];
1080 rtd = &card->rtd[num];
1081 name = dai_link->name;
1083 aux_dev = &card->aux_dev[num];
1084 rtd = &card->rtd_aux[num];
1085 name = aux_dev->name;
1089 /* Make sure all DAPM widgets are instantiated */
1090 snd_soc_dapm_new_widgets(&codec->dapm);
1092 /* machine controls, routes and widgets are not prefixed */
1093 temp = codec->name_prefix;
1094 codec->name_prefix = NULL;
1096 /* do machine specific initialization */
1097 if (!dailess && dai_link->init)
1098 ret = dai_link->init(rtd);
1099 else if (dailess && aux_dev->init)
1100 ret = aux_dev->init(&codec->dapm);
1102 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1105 codec->name_prefix = temp;
1107 /* register the rtd device */
1109 rtd->dev.parent = card->dev;
1110 rtd->dev.release = rtd_release;
1111 rtd->dev.init_name = name;
1112 mutex_init(&rtd->pcm_mutex);
1113 ret = device_register(&rtd->dev);
1116 "asoc: failed to register runtime device: %d\n", ret);
1119 rtd->dev_registered = 1;
1121 /* add DAPM sysfs entries for this codec */
1122 ret = snd_soc_dapm_sys_add(&rtd->dev);
1125 "asoc: failed to add codec dapm sysfs entries: %d\n",
1128 /* add codec sysfs entries */
1129 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1132 "asoc: failed to add codec sysfs files: %d\n", ret);
1137 static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1139 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1140 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1141 struct snd_soc_codec *codec = rtd->codec;
1142 struct snd_soc_platform *platform = rtd->platform;
1143 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1146 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1147 card->name, num, order);
1149 /* config components */
1150 codec_dai->codec = codec;
1151 cpu_dai->platform = platform;
1152 codec_dai->card = card;
1153 cpu_dai->card = card;
1155 /* set default power off timeout */
1156 rtd->pmdown_time = pmdown_time;
1158 /* probe the cpu_dai */
1159 if (!cpu_dai->probed &&
1160 cpu_dai->driver->probe_order == order) {
1161 if (!try_module_get(cpu_dai->dev->driver->owner))
1164 if (cpu_dai->driver->probe) {
1165 ret = cpu_dai->driver->probe(cpu_dai);
1167 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1169 module_put(cpu_dai->dev->driver->owner);
1173 cpu_dai->probed = 1;
1174 /* mark cpu_dai as probed and add to card dai list */
1175 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1178 /* probe the CODEC */
1179 if (!codec->probed &&
1180 codec->driver->probe_order == order) {
1181 ret = soc_probe_codec(card, codec);
1186 /* probe the platform */
1187 if (!platform->probed &&
1188 platform->driver->probe_order == order) {
1189 ret = soc_probe_platform(card, platform);
1194 /* probe the CODEC DAI */
1195 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1196 if (codec_dai->driver->probe) {
1197 ret = codec_dai->driver->probe(codec_dai);
1199 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1205 /* mark codec_dai as probed and add to card dai list */
1206 codec_dai->probed = 1;
1207 list_add(&codec_dai->card_list, &card->dai_dev_list);
1210 /* complete DAI probe during last probe */
1211 if (order != SND_SOC_COMP_ORDER_LAST)
1214 ret = soc_post_component_init(card, codec, num, 0);
1218 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1220 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1222 /* create the pcm */
1223 ret = soc_new_pcm(rtd, num);
1225 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1229 /* add platform data for AC97 devices */
1230 if (rtd->codec_dai->driver->ac97_control)
1231 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1236 #ifdef CONFIG_SND_SOC_AC97_BUS
1237 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1241 /* Only instantiate AC97 if not already done by the adaptor
1242 * for the generic AC97 subsystem.
1244 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1246 * It is possible that the AC97 device is already registered to
1247 * the device subsystem. This happens when the device is created
1248 * via snd_ac97_mixer(). Currently only SoC codec that does so
1249 * is the generic AC97 glue but others migh emerge.
1251 * In those cases we don't try to register the device again.
1253 if (!rtd->codec->ac97_created)
1256 ret = soc_ac97_dev_register(rtd->codec);
1258 printk(KERN_ERR "asoc: AC97 device register failed\n");
1262 rtd->codec->ac97_registered = 1;
1267 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1269 if (codec->ac97_registered) {
1270 soc_ac97_dev_unregister(codec);
1271 codec->ac97_registered = 0;
1276 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1278 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1279 struct snd_soc_codec *codec;
1282 /* find CODEC from registered CODECs*/
1283 list_for_each_entry(codec, &codec_list, list) {
1284 if (!strcmp(codec->name, aux_dev->codec_name)) {
1285 if (codec->probed) {
1287 "asoc: codec already probed");
1294 /* codec not found */
1295 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1299 ret = soc_probe_codec(card, codec);
1303 ret = soc_post_component_init(card, codec, num, 1);
1309 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1311 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1312 struct snd_soc_codec *codec = rtd->codec;
1314 /* unregister the rtd device */
1315 if (rtd->dev_registered) {
1316 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1317 device_unregister(&rtd->dev);
1318 rtd->dev_registered = 0;
1321 if (codec && codec->probed)
1322 soc_remove_codec(codec);
1325 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1326 enum snd_soc_compress_type compress_type)
1330 if (codec->cache_init)
1333 /* override the compress_type if necessary */
1334 if (compress_type && codec->compress_type != compress_type)
1335 codec->compress_type = compress_type;
1336 ret = snd_soc_cache_init(codec);
1338 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1342 codec->cache_init = 1;
1346 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1348 struct snd_soc_codec *codec;
1349 struct snd_soc_codec_conf *codec_conf;
1350 enum snd_soc_compress_type compress_type;
1351 struct snd_soc_dai_link *dai_link;
1354 mutex_lock(&card->mutex);
1356 if (card->instantiated) {
1357 mutex_unlock(&card->mutex);
1362 for (i = 0; i < card->num_links; i++)
1363 soc_bind_dai_link(card, i);
1365 /* bind completed ? */
1366 if (card->num_rtd != card->num_links) {
1367 mutex_unlock(&card->mutex);
1371 /* initialize the register cache for each available codec */
1372 list_for_each_entry(codec, &codec_list, list) {
1373 if (codec->cache_init)
1375 /* by default we don't override the compress_type */
1377 /* check to see if we need to override the compress_type */
1378 for (i = 0; i < card->num_configs; ++i) {
1379 codec_conf = &card->codec_conf[i];
1380 if (!strcmp(codec->name, codec_conf->dev_name)) {
1381 compress_type = codec_conf->compress_type;
1382 if (compress_type && compress_type
1383 != codec->compress_type)
1387 ret = snd_soc_init_codec_cache(codec, compress_type);
1389 mutex_unlock(&card->mutex);
1394 /* card bind complete so register a sound card */
1395 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1396 card->owner, 0, &card->snd_card);
1398 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1400 mutex_unlock(&card->mutex);
1403 card->snd_card->dev = card->dev;
1405 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1406 card->dapm.dev = card->dev;
1407 card->dapm.card = card;
1408 list_add(&card->dapm.list, &card->dapm_list);
1410 #ifdef CONFIG_DEBUG_FS
1411 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1414 #ifdef CONFIG_PM_SLEEP
1415 /* deferred resume work */
1416 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1419 if (card->dapm_widgets)
1420 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1421 card->num_dapm_widgets);
1423 /* initialise the sound card only once */
1425 ret = card->probe(card);
1427 goto card_probe_error;
1430 /* early DAI link probe */
1431 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1433 for (i = 0; i < card->num_links; i++) {
1434 ret = soc_probe_dai_link(card, i, order);
1436 pr_err("asoc: failed to instantiate card %s: %d\n",
1443 for (i = 0; i < card->num_aux_devs; i++) {
1444 ret = soc_probe_aux_dev(card, i);
1446 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1448 goto probe_aux_dev_err;
1452 /* We should have a non-codec control add function but we don't */
1454 snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
1455 struct snd_soc_codec,
1458 card->num_controls);
1460 if (card->dapm_routes)
1461 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1462 card->num_dapm_routes);
1464 snd_soc_dapm_new_widgets(&card->dapm);
1466 for (i = 0; i < card->num_links; i++) {
1467 dai_link = &card->dai_link[i];
1469 if (dai_link->dai_fmt) {
1470 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1473 dev_warn(card->rtd[i].codec_dai->dev,
1474 "Failed to set DAI format: %d\n",
1477 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1480 dev_warn(card->rtd[i].cpu_dai->dev,
1481 "Failed to set DAI format: %d\n",
1486 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1488 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1489 "%s", card->long_name ? card->long_name : card->name);
1490 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1491 "%s", card->driver_name ? card->driver_name : card->name);
1492 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1493 switch (card->snd_card->driver[i]) {
1499 if (!isalnum(card->snd_card->driver[i]))
1500 card->snd_card->driver[i] = '_';
1505 if (card->late_probe) {
1506 ret = card->late_probe(card);
1508 dev_err(card->dev, "%s late_probe() failed: %d\n",
1510 goto probe_aux_dev_err;
1514 snd_soc_dapm_new_widgets(&card->dapm);
1516 if (card->fully_routed)
1517 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1518 snd_soc_dapm_auto_nc_codec_pins(codec);
1520 ret = snd_card_register(card->snd_card);
1522 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1523 goto probe_aux_dev_err;
1526 #ifdef CONFIG_SND_SOC_AC97_BUS
1527 /* register any AC97 codecs */
1528 for (i = 0; i < card->num_rtd; i++) {
1529 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1531 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1533 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1534 goto probe_aux_dev_err;
1539 card->instantiated = 1;
1540 snd_soc_dapm_sync(&card->dapm);
1541 mutex_unlock(&card->mutex);
1545 for (i = 0; i < card->num_aux_devs; i++)
1546 soc_remove_aux_dev(card, i);
1549 soc_remove_dai_links(card);
1555 snd_card_free(card->snd_card);
1557 mutex_unlock(&card->mutex);
1561 * Attempt to initialise any uninitialised cards. Must be called with
1564 static void snd_soc_instantiate_cards(void)
1566 struct snd_soc_card *card;
1567 list_for_each_entry(card, &card_list, list)
1568 snd_soc_instantiate_card(card);
1571 /* probes a new socdev */
1572 static int soc_probe(struct platform_device *pdev)
1574 struct snd_soc_card *card = platform_get_drvdata(pdev);
1578 * no card, so machine driver should be registering card
1579 * we should not be here in that case so ret error
1584 /* Bodge while we unpick instantiation */
1585 card->dev = &pdev->dev;
1587 ret = snd_soc_register_card(card);
1589 dev_err(&pdev->dev, "Failed to register card\n");
1596 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1600 /* make sure any delayed work runs */
1601 for (i = 0; i < card->num_rtd; i++) {
1602 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1603 flush_delayed_work_sync(&rtd->delayed_work);
1606 /* remove auxiliary devices */
1607 for (i = 0; i < card->num_aux_devs; i++)
1608 soc_remove_aux_dev(card, i);
1610 /* remove and free each DAI */
1611 soc_remove_dai_links(card);
1613 soc_cleanup_card_debugfs(card);
1615 /* remove the card */
1619 snd_soc_dapm_free(&card->dapm);
1622 snd_card_free(card->snd_card);
1627 /* removes a socdev */
1628 static int soc_remove(struct platform_device *pdev)
1630 struct snd_soc_card *card = platform_get_drvdata(pdev);
1632 snd_soc_unregister_card(card);
1636 int snd_soc_poweroff(struct device *dev)
1638 struct snd_soc_card *card = dev_get_drvdata(dev);
1641 if (!card->instantiated)
1644 /* Flush out pmdown_time work - we actually do want to run it
1645 * now, we're shutting down so no imminent restart. */
1646 for (i = 0; i < card->num_rtd; i++) {
1647 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1648 flush_delayed_work_sync(&rtd->delayed_work);
1651 snd_soc_dapm_shutdown(card);
1655 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1657 const struct dev_pm_ops snd_soc_pm_ops = {
1658 .suspend = snd_soc_suspend,
1659 .resume = snd_soc_resume,
1660 .poweroff = snd_soc_poweroff,
1662 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1664 /* ASoC platform driver */
1665 static struct platform_driver soc_driver = {
1667 .name = "soc-audio",
1668 .owner = THIS_MODULE,
1669 .pm = &snd_soc_pm_ops,
1672 .remove = soc_remove,
1676 * snd_soc_codec_volatile_register: Report if a register is volatile.
1678 * @codec: CODEC to query.
1679 * @reg: Register to query.
1681 * Boolean function indiciating if a CODEC register is volatile.
1683 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1686 if (codec->volatile_register)
1687 return codec->volatile_register(codec, reg);
1691 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1694 * snd_soc_codec_readable_register: Report if a register is readable.
1696 * @codec: CODEC to query.
1697 * @reg: Register to query.
1699 * Boolean function indicating if a CODEC register is readable.
1701 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1704 if (codec->readable_register)
1705 return codec->readable_register(codec, reg);
1709 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1712 * snd_soc_codec_writable_register: Report if a register is writable.
1714 * @codec: CODEC to query.
1715 * @reg: Register to query.
1717 * Boolean function indicating if a CODEC register is writable.
1719 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1722 if (codec->writable_register)
1723 return codec->writable_register(codec, reg);
1727 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1729 int snd_soc_platform_read(struct snd_soc_platform *platform,
1734 if (!platform->driver->read) {
1735 dev_err(platform->dev, "platform has no read back\n");
1739 ret = platform->driver->read(platform, reg);
1740 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
1741 trace_snd_soc_preg_read(platform, reg, ret);
1745 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1747 int snd_soc_platform_write(struct snd_soc_platform *platform,
1748 unsigned int reg, unsigned int val)
1750 if (!platform->driver->write) {
1751 dev_err(platform->dev, "platform has no write back\n");
1755 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
1756 trace_snd_soc_preg_write(platform, reg, val);
1757 return platform->driver->write(platform, reg, val);
1759 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1762 * snd_soc_new_ac97_codec - initailise AC97 device
1763 * @codec: audio codec
1764 * @ops: AC97 bus operations
1765 * @num: AC97 codec number
1767 * Initialises AC97 codec resources for use by ad-hoc devices only.
1769 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1770 struct snd_ac97_bus_ops *ops, int num)
1772 mutex_lock(&codec->mutex);
1774 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1775 if (codec->ac97 == NULL) {
1776 mutex_unlock(&codec->mutex);
1780 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1781 if (codec->ac97->bus == NULL) {
1784 mutex_unlock(&codec->mutex);
1788 codec->ac97->bus->ops = ops;
1789 codec->ac97->num = num;
1792 * Mark the AC97 device to be created by us. This way we ensure that the
1793 * device will be registered with the device subsystem later on.
1795 codec->ac97_created = 1;
1797 mutex_unlock(&codec->mutex);
1800 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1803 * snd_soc_free_ac97_codec - free AC97 codec device
1804 * @codec: audio codec
1806 * Frees AC97 codec device resources.
1808 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1810 mutex_lock(&codec->mutex);
1811 #ifdef CONFIG_SND_SOC_AC97_BUS
1812 soc_unregister_ac97_dai_link(codec);
1814 kfree(codec->ac97->bus);
1817 codec->ac97_created = 0;
1818 mutex_unlock(&codec->mutex);
1820 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1822 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1826 ret = codec->read(codec, reg);
1827 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
1828 trace_snd_soc_reg_read(codec, reg, ret);
1832 EXPORT_SYMBOL_GPL(snd_soc_read);
1834 unsigned int snd_soc_write(struct snd_soc_codec *codec,
1835 unsigned int reg, unsigned int val)
1837 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
1838 trace_snd_soc_reg_write(codec, reg, val);
1839 return codec->write(codec, reg, val);
1841 EXPORT_SYMBOL_GPL(snd_soc_write);
1843 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1844 unsigned int reg, const void *data, size_t len)
1846 return codec->bulk_write_raw(codec, reg, data, len);
1848 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1851 * snd_soc_update_bits - update codec register bits
1852 * @codec: audio codec
1853 * @reg: codec register
1854 * @mask: register mask
1857 * Writes new register value.
1859 * Returns 1 for change, 0 for no change, or negative error code.
1861 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1862 unsigned int mask, unsigned int value)
1865 unsigned int old, new;
1868 ret = snd_soc_read(codec, reg);
1873 new = (old & ~mask) | (value & mask);
1874 change = old != new;
1876 ret = snd_soc_write(codec, reg, new);
1883 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1886 * snd_soc_update_bits_locked - update codec register bits
1887 * @codec: audio codec
1888 * @reg: codec register
1889 * @mask: register mask
1892 * Writes new register value, and takes the codec mutex.
1894 * Returns 1 for change else 0.
1896 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1897 unsigned short reg, unsigned int mask,
1902 mutex_lock(&codec->mutex);
1903 change = snd_soc_update_bits(codec, reg, mask, value);
1904 mutex_unlock(&codec->mutex);
1908 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1911 * snd_soc_test_bits - test register for change
1912 * @codec: audio codec
1913 * @reg: codec register
1914 * @mask: register mask
1917 * Tests a register with a new value and checks if the new value is
1918 * different from the old value.
1920 * Returns 1 for change else 0.
1922 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1923 unsigned int mask, unsigned int value)
1926 unsigned int old, new;
1928 old = snd_soc_read(codec, reg);
1929 new = (old & ~mask) | value;
1930 change = old != new;
1934 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1937 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1938 * @substream: the pcm substream
1939 * @hw: the hardware parameters
1941 * Sets the substream runtime hardware parameters.
1943 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1944 const struct snd_pcm_hardware *hw)
1946 struct snd_pcm_runtime *runtime = substream->runtime;
1947 runtime->hw.info = hw->info;
1948 runtime->hw.formats = hw->formats;
1949 runtime->hw.period_bytes_min = hw->period_bytes_min;
1950 runtime->hw.period_bytes_max = hw->period_bytes_max;
1951 runtime->hw.periods_min = hw->periods_min;
1952 runtime->hw.periods_max = hw->periods_max;
1953 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1954 runtime->hw.fifo_size = hw->fifo_size;
1957 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1960 * snd_soc_cnew - create new control
1961 * @_template: control template
1962 * @data: control private data
1963 * @long_name: control long name
1964 * @prefix: control name prefix
1966 * Create a new mixer control from a template control.
1968 * Returns 0 for success, else error.
1970 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1971 void *data, char *long_name,
1974 struct snd_kcontrol_new template;
1975 struct snd_kcontrol *kcontrol;
1979 memcpy(&template, _template, sizeof(template));
1983 long_name = template.name;
1986 name_len = strlen(long_name) + strlen(prefix) + 2;
1987 name = kmalloc(name_len, GFP_KERNEL);
1991 snprintf(name, name_len, "%s %s", prefix, long_name);
1993 template.name = name;
1995 template.name = long_name;
1998 kcontrol = snd_ctl_new1(&template, data);
2004 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2007 * snd_soc_add_controls - add an array of controls to a codec.
2008 * Convienience function to add a list of controls. Many codecs were
2009 * duplicating this code.
2011 * @codec: codec to add controls to
2012 * @controls: array of controls to add
2013 * @num_controls: number of elements in the array
2015 * Return 0 for success, else error.
2017 int snd_soc_add_controls(struct snd_soc_codec *codec,
2018 const struct snd_kcontrol_new *controls, int num_controls)
2020 struct snd_card *card = codec->card->snd_card;
2023 for (i = 0; i < num_controls; i++) {
2024 const struct snd_kcontrol_new *control = &controls[i];
2025 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2027 codec->name_prefix));
2029 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2030 codec->name, control->name, err);
2037 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
2040 * snd_soc_add_platform_controls - add an array of controls to a platform.
2041 * Convienience function to add a list of controls.
2043 * @platform: platform to add controls to
2044 * @controls: array of controls to add
2045 * @num_controls: number of elements in the array
2047 * Return 0 for success, else error.
2049 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2050 const struct snd_kcontrol_new *controls, int num_controls)
2052 struct snd_card *card = platform->card->snd_card;
2055 for (i = 0; i < num_controls; i++) {
2056 const struct snd_kcontrol_new *control = &controls[i];
2057 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
2058 control->name, NULL));
2060 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
2067 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2070 * snd_soc_info_enum_double - enumerated double mixer info callback
2071 * @kcontrol: mixer control
2072 * @uinfo: control element information
2074 * Callback to provide information about a double enumerated
2077 * Returns 0 for success.
2079 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2080 struct snd_ctl_elem_info *uinfo)
2082 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2084 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2085 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2086 uinfo->value.enumerated.items = e->max;
2088 if (uinfo->value.enumerated.item > e->max - 1)
2089 uinfo->value.enumerated.item = e->max - 1;
2090 strcpy(uinfo->value.enumerated.name,
2091 e->texts[uinfo->value.enumerated.item]);
2094 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2097 * snd_soc_get_enum_double - enumerated double mixer get callback
2098 * @kcontrol: mixer control
2099 * @ucontrol: control element information
2101 * Callback to get the value of a double enumerated mixer.
2103 * Returns 0 for success.
2105 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2106 struct snd_ctl_elem_value *ucontrol)
2108 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2109 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2110 unsigned int val, bitmask;
2112 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2114 val = snd_soc_read(codec, e->reg);
2115 ucontrol->value.enumerated.item[0]
2116 = (val >> e->shift_l) & (bitmask - 1);
2117 if (e->shift_l != e->shift_r)
2118 ucontrol->value.enumerated.item[1] =
2119 (val >> e->shift_r) & (bitmask - 1);
2123 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2126 * snd_soc_put_enum_double - enumerated double mixer put callback
2127 * @kcontrol: mixer control
2128 * @ucontrol: control element information
2130 * Callback to set the value of a double enumerated mixer.
2132 * Returns 0 for success.
2134 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2135 struct snd_ctl_elem_value *ucontrol)
2137 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2138 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2140 unsigned int mask, bitmask;
2142 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2144 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2146 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2147 mask = (bitmask - 1) << e->shift_l;
2148 if (e->shift_l != e->shift_r) {
2149 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2151 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2152 mask |= (bitmask - 1) << e->shift_r;
2155 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2157 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2160 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2161 * @kcontrol: mixer control
2162 * @ucontrol: control element information
2164 * Callback to get the value of a double semi enumerated mixer.
2166 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2167 * used for handling bitfield coded enumeration for example.
2169 * Returns 0 for success.
2171 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2172 struct snd_ctl_elem_value *ucontrol)
2174 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2175 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2176 unsigned int reg_val, val, mux;
2178 reg_val = snd_soc_read(codec, e->reg);
2179 val = (reg_val >> e->shift_l) & e->mask;
2180 for (mux = 0; mux < e->max; mux++) {
2181 if (val == e->values[mux])
2184 ucontrol->value.enumerated.item[0] = mux;
2185 if (e->shift_l != e->shift_r) {
2186 val = (reg_val >> e->shift_r) & e->mask;
2187 for (mux = 0; mux < e->max; mux++) {
2188 if (val == e->values[mux])
2191 ucontrol->value.enumerated.item[1] = mux;
2196 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2199 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2200 * @kcontrol: mixer control
2201 * @ucontrol: control element information
2203 * Callback to set the value of a double semi enumerated mixer.
2205 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2206 * used for handling bitfield coded enumeration for example.
2208 * Returns 0 for success.
2210 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_value *ucontrol)
2213 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2214 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2218 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2220 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2221 mask = e->mask << e->shift_l;
2222 if (e->shift_l != e->shift_r) {
2223 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2225 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2226 mask |= e->mask << e->shift_r;
2229 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2231 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2234 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2235 * @kcontrol: mixer control
2236 * @uinfo: control element information
2238 * Callback to provide information about an external enumerated
2241 * Returns 0 for success.
2243 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2244 struct snd_ctl_elem_info *uinfo)
2246 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2248 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2250 uinfo->value.enumerated.items = e->max;
2252 if (uinfo->value.enumerated.item > e->max - 1)
2253 uinfo->value.enumerated.item = e->max - 1;
2254 strcpy(uinfo->value.enumerated.name,
2255 e->texts[uinfo->value.enumerated.item]);
2258 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2261 * snd_soc_info_volsw_ext - external single mixer info callback
2262 * @kcontrol: mixer control
2263 * @uinfo: control element information
2265 * Callback to provide information about a single external mixer control.
2267 * Returns 0 for success.
2269 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2270 struct snd_ctl_elem_info *uinfo)
2272 int max = kcontrol->private_value;
2274 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2275 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2277 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2280 uinfo->value.integer.min = 0;
2281 uinfo->value.integer.max = max;
2284 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2287 * snd_soc_info_volsw - single mixer info callback
2288 * @kcontrol: mixer control
2289 * @uinfo: control element information
2291 * Callback to provide information about a single mixer control, or a double
2292 * mixer control that spans 2 registers.
2294 * Returns 0 for success.
2296 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_info *uinfo)
2299 struct soc_mixer_control *mc =
2300 (struct soc_mixer_control *)kcontrol->private_value;
2303 if (!mc->platform_max)
2304 mc->platform_max = mc->max;
2305 platform_max = mc->platform_max;
2307 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2308 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2310 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2312 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2313 uinfo->value.integer.min = 0;
2314 uinfo->value.integer.max = platform_max;
2317 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2320 * snd_soc_get_volsw - single mixer get callback
2321 * @kcontrol: mixer control
2322 * @ucontrol: control element information
2324 * Callback to get the value of a single mixer control, or a double mixer
2325 * control that spans 2 registers.
2327 * Returns 0 for success.
2329 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2330 struct snd_ctl_elem_value *ucontrol)
2332 struct soc_mixer_control *mc =
2333 (struct soc_mixer_control *)kcontrol->private_value;
2334 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2335 unsigned int reg = mc->reg;
2336 unsigned int reg2 = mc->rreg;
2337 unsigned int shift = mc->shift;
2338 unsigned int rshift = mc->rshift;
2340 unsigned int mask = (1 << fls(max)) - 1;
2341 unsigned int invert = mc->invert;
2343 ucontrol->value.integer.value[0] =
2344 (snd_soc_read(codec, reg) >> shift) & mask;
2346 ucontrol->value.integer.value[0] =
2347 max - ucontrol->value.integer.value[0];
2349 if (snd_soc_volsw_is_stereo(mc)) {
2351 ucontrol->value.integer.value[1] =
2352 (snd_soc_read(codec, reg) >> rshift) & mask;
2354 ucontrol->value.integer.value[1] =
2355 (snd_soc_read(codec, reg2) >> shift) & mask;
2357 ucontrol->value.integer.value[1] =
2358 max - ucontrol->value.integer.value[1];
2363 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2366 * snd_soc_put_volsw - single mixer put callback
2367 * @kcontrol: mixer control
2368 * @ucontrol: control element information
2370 * Callback to set the value of a single mixer control, or a double mixer
2371 * control that spans 2 registers.
2373 * Returns 0 for success.
2375 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2376 struct snd_ctl_elem_value *ucontrol)
2378 struct soc_mixer_control *mc =
2379 (struct soc_mixer_control *)kcontrol->private_value;
2380 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2381 unsigned int reg = mc->reg;
2382 unsigned int reg2 = mc->rreg;
2383 unsigned int shift = mc->shift;
2384 unsigned int rshift = mc->rshift;
2386 unsigned int mask = (1 << fls(max)) - 1;
2387 unsigned int invert = mc->invert;
2390 unsigned int val2 = 0;
2391 unsigned int val, val_mask;
2393 val = (ucontrol->value.integer.value[0] & mask);
2396 val_mask = mask << shift;
2398 if (snd_soc_volsw_is_stereo(mc)) {
2399 val2 = (ucontrol->value.integer.value[1] & mask);
2403 val_mask |= mask << rshift;
2404 val |= val2 << rshift;
2406 val2 = val2 << shift;
2410 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2415 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2419 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2422 * snd_soc_info_volsw_s8 - signed mixer info callback
2423 * @kcontrol: mixer control
2424 * @uinfo: control element information
2426 * Callback to provide information about a signed mixer control.
2428 * Returns 0 for success.
2430 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2431 struct snd_ctl_elem_info *uinfo)
2433 struct soc_mixer_control *mc =
2434 (struct soc_mixer_control *)kcontrol->private_value;
2438 if (!mc->platform_max)
2439 mc->platform_max = mc->max;
2440 platform_max = mc->platform_max;
2442 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2444 uinfo->value.integer.min = 0;
2445 uinfo->value.integer.max = platform_max - min;
2448 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2451 * snd_soc_get_volsw_s8 - signed mixer get callback
2452 * @kcontrol: mixer control
2453 * @ucontrol: control element information
2455 * Callback to get the value of a signed mixer control.
2457 * Returns 0 for success.
2459 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2460 struct snd_ctl_elem_value *ucontrol)
2462 struct soc_mixer_control *mc =
2463 (struct soc_mixer_control *)kcontrol->private_value;
2464 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2465 unsigned int reg = mc->reg;
2467 int val = snd_soc_read(codec, reg);
2469 ucontrol->value.integer.value[0] =
2470 ((signed char)(val & 0xff))-min;
2471 ucontrol->value.integer.value[1] =
2472 ((signed char)((val >> 8) & 0xff))-min;
2475 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2478 * snd_soc_put_volsw_sgn - signed mixer put callback
2479 * @kcontrol: mixer control
2480 * @ucontrol: control element information
2482 * Callback to set the value of a signed mixer control.
2484 * Returns 0 for success.
2486 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2487 struct snd_ctl_elem_value *ucontrol)
2489 struct soc_mixer_control *mc =
2490 (struct soc_mixer_control *)kcontrol->private_value;
2491 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2492 unsigned int reg = mc->reg;
2496 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2497 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2499 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2501 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2504 * snd_soc_limit_volume - Set new limit to an existing volume control.
2506 * @codec: where to look for the control
2507 * @name: Name of the control
2508 * @max: new maximum limit
2510 * Return 0 for success, else error.
2512 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2513 const char *name, int max)
2515 struct snd_card *card = codec->card->snd_card;
2516 struct snd_kcontrol *kctl;
2517 struct soc_mixer_control *mc;
2521 /* Sanity check for name and max */
2522 if (unlikely(!name || max <= 0))
2525 list_for_each_entry(kctl, &card->controls, list) {
2526 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2532 mc = (struct soc_mixer_control *)kctl->private_value;
2533 if (max <= mc->max) {
2534 mc->platform_max = max;
2540 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2543 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2544 * mixer info callback
2545 * @kcontrol: mixer control
2546 * @uinfo: control element information
2548 * Returns 0 for success.
2550 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2551 struct snd_ctl_elem_info *uinfo)
2553 struct soc_mixer_control *mc =
2554 (struct soc_mixer_control *)kcontrol->private_value;
2558 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2560 uinfo->value.integer.min = 0;
2561 uinfo->value.integer.max = max-min;
2565 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2568 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2569 * mixer get callback
2570 * @kcontrol: mixer control
2571 * @uinfo: control element information
2573 * Returns 0 for success.
2575 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2576 struct snd_ctl_elem_value *ucontrol)
2578 struct soc_mixer_control *mc =
2579 (struct soc_mixer_control *)kcontrol->private_value;
2580 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2581 unsigned int mask = (1<<mc->shift)-1;
2583 int val = snd_soc_read(codec, mc->reg) & mask;
2584 int valr = snd_soc_read(codec, mc->rreg) & mask;
2586 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2587 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2590 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2593 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2594 * mixer put callback
2595 * @kcontrol: mixer control
2596 * @uinfo: control element information
2598 * Returns 0 for success.
2600 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2601 struct snd_ctl_elem_value *ucontrol)
2603 struct soc_mixer_control *mc =
2604 (struct soc_mixer_control *)kcontrol->private_value;
2605 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2606 unsigned int mask = (1<<mc->shift)-1;
2609 unsigned int val, valr, oval, ovalr;
2611 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2613 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2616 oval = snd_soc_read(codec, mc->reg) & mask;
2617 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2621 ret = snd_soc_write(codec, mc->reg, val);
2625 if (ovalr != valr) {
2626 ret = snd_soc_write(codec, mc->rreg, valr);
2633 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2636 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2638 * @clk_id: DAI specific clock ID
2639 * @freq: new clock frequency in Hz
2640 * @dir: new clock direction - input/output.
2642 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2644 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2645 unsigned int freq, int dir)
2647 if (dai->driver && dai->driver->ops->set_sysclk)
2648 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2649 else if (dai->codec && dai->codec->driver->set_sysclk)
2650 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2655 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2658 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2660 * @clk_id: DAI specific clock ID
2661 * @source: Source for the clock
2662 * @freq: new clock frequency in Hz
2663 * @dir: new clock direction - input/output.
2665 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2667 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2668 int source, unsigned int freq, int dir)
2670 if (codec->driver->set_sysclk)
2671 return codec->driver->set_sysclk(codec, clk_id, source,
2676 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2679 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2681 * @div_id: DAI specific clock divider ID
2682 * @div: new clock divisor.
2684 * Configures the clock dividers. This is used to derive the best DAI bit and
2685 * frame clocks from the system or master clock. It's best to set the DAI bit
2686 * and frame clocks as low as possible to save system power.
2688 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2689 int div_id, int div)
2691 if (dai->driver && dai->driver->ops->set_clkdiv)
2692 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2696 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2699 * snd_soc_dai_set_pll - configure DAI PLL.
2701 * @pll_id: DAI specific PLL ID
2702 * @source: DAI specific source for the PLL
2703 * @freq_in: PLL input clock frequency in Hz
2704 * @freq_out: requested PLL output clock frequency in Hz
2706 * Configures and enables PLL to generate output clock based on input clock.
2708 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2709 unsigned int freq_in, unsigned int freq_out)
2711 if (dai->driver && dai->driver->ops->set_pll)
2712 return dai->driver->ops->set_pll(dai, pll_id, source,
2714 else if (dai->codec && dai->codec->driver->set_pll)
2715 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2720 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2723 * snd_soc_codec_set_pll - configure codec PLL.
2725 * @pll_id: DAI specific PLL ID
2726 * @source: DAI specific source for the PLL
2727 * @freq_in: PLL input clock frequency in Hz
2728 * @freq_out: requested PLL output clock frequency in Hz
2730 * Configures and enables PLL to generate output clock based on input clock.
2732 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2733 unsigned int freq_in, unsigned int freq_out)
2735 if (codec->driver->set_pll)
2736 return codec->driver->set_pll(codec, pll_id, source,
2741 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2744 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2746 * @fmt: SND_SOC_DAIFMT_ format value.
2748 * Configures the DAI hardware format and clocking.
2750 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2752 if (dai->driver && dai->driver->ops->set_fmt)
2753 return dai->driver->ops->set_fmt(dai, fmt);
2757 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2760 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2762 * @tx_mask: bitmask representing active TX slots.
2763 * @rx_mask: bitmask representing active RX slots.
2764 * @slots: Number of slots in use.
2765 * @slot_width: Width in bits for each slot.
2767 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2770 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2771 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2773 if (dai->driver && dai->driver->ops->set_tdm_slot)
2774 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2779 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2782 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2784 * @tx_num: how many TX channels
2785 * @tx_slot: pointer to an array which imply the TX slot number channel
2787 * @rx_num: how many RX channels
2788 * @rx_slot: pointer to an array which imply the RX slot number channel
2791 * configure the relationship between channel number and TDM slot number.
2793 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2794 unsigned int tx_num, unsigned int *tx_slot,
2795 unsigned int rx_num, unsigned int *rx_slot)
2797 if (dai->driver && dai->driver->ops->set_channel_map)
2798 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2803 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2806 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2808 * @tristate: tristate enable
2810 * Tristates the DAI so that others can use it.
2812 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2814 if (dai->driver && dai->driver->ops->set_tristate)
2815 return dai->driver->ops->set_tristate(dai, tristate);
2819 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2822 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2824 * @mute: mute enable
2826 * Mutes the DAI DAC.
2828 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2830 if (dai->driver && dai->driver->ops->digital_mute)
2831 return dai->driver->ops->digital_mute(dai, mute);
2835 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2838 * snd_soc_register_card - Register a card with the ASoC core
2840 * @card: Card to register
2843 int snd_soc_register_card(struct snd_soc_card *card)
2847 if (!card->name || !card->dev)
2850 for (i = 0; i < card->num_links; i++) {
2851 struct snd_soc_dai_link *link = &card->dai_link[i];
2854 * Codec must be specified by 1 of name or OF node,
2855 * not both or neither.
2857 if (!!link->codec_name == !!link->codec_of_node) {
2859 "Neither/both codec name/of_node are set\n");
2864 * Platform may be specified by either name or OF node, but
2865 * can be left unspecified, and a dummy platform will be used.
2867 if (link->platform_name && link->platform_of_node) {
2869 "Both platform name/of_node are set\n");
2874 * CPU DAI must be specified by 1 of name or OF node,
2875 * not both or neither.
2877 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2879 "Neither/both cpu_dai name/of_node are set\n");
2884 dev_set_drvdata(card->dev, card);
2886 snd_soc_initialize_card_lists(card);
2888 soc_init_card_debugfs(card);
2890 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2891 (card->num_links + card->num_aux_devs),
2893 if (card->rtd == NULL)
2895 card->rtd_aux = &card->rtd[card->num_links];
2897 for (i = 0; i < card->num_links; i++)
2898 card->rtd[i].dai_link = &card->dai_link[i];
2900 INIT_LIST_HEAD(&card->list);
2901 INIT_LIST_HEAD(&card->dapm_dirty);
2902 card->instantiated = 0;
2903 mutex_init(&card->mutex);
2905 mutex_lock(&client_mutex);
2906 list_add(&card->list, &card_list);
2907 snd_soc_instantiate_cards();
2908 mutex_unlock(&client_mutex);
2910 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2914 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2917 * snd_soc_unregister_card - Unregister a card with the ASoC core
2919 * @card: Card to unregister
2922 int snd_soc_unregister_card(struct snd_soc_card *card)
2924 if (card->instantiated)
2925 soc_cleanup_card_resources(card);
2926 mutex_lock(&client_mutex);
2927 list_del(&card->list);
2928 mutex_unlock(&client_mutex);
2929 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2933 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2936 * Simplify DAI link configuration by removing ".-1" from device names
2937 * and sanitizing names.
2939 static char *fmt_single_name(struct device *dev, int *id)
2941 char *found, name[NAME_SIZE];
2944 if (dev_name(dev) == NULL)
2947 strlcpy(name, dev_name(dev), NAME_SIZE);
2949 /* are we a "%s.%d" name (platform and SPI components) */
2950 found = strstr(name, dev->driver->name);
2953 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2955 /* discard ID from name if ID == -1 */
2957 found[strlen(dev->driver->name)] = '\0';
2961 /* I2C component devices are named "bus-addr" */
2962 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2963 char tmp[NAME_SIZE];
2965 /* create unique ID number from I2C addr and bus */
2966 *id = ((id1 & 0xffff) << 16) + id2;
2968 /* sanitize component name for DAI link creation */
2969 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2970 strlcpy(name, tmp, NAME_SIZE);
2975 return kstrdup(name, GFP_KERNEL);
2979 * Simplify DAI link naming for single devices with multiple DAIs by removing
2980 * any ".-1" and using the DAI name (instead of device name).
2982 static inline char *fmt_multiple_name(struct device *dev,
2983 struct snd_soc_dai_driver *dai_drv)
2985 if (dai_drv->name == NULL) {
2986 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2991 return kstrdup(dai_drv->name, GFP_KERNEL);
2995 * snd_soc_register_dai - Register a DAI with the ASoC core
2997 * @dai: DAI to register
2999 int snd_soc_register_dai(struct device *dev,
3000 struct snd_soc_dai_driver *dai_drv)
3002 struct snd_soc_dai *dai;
3004 dev_dbg(dev, "dai register %s\n", dev_name(dev));
3006 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3010 /* create DAI component name */
3011 dai->name = fmt_single_name(dev, &dai->id);
3012 if (dai->name == NULL) {
3018 dai->driver = dai_drv;
3019 if (!dai->driver->ops)
3020 dai->driver->ops = &null_dai_ops;
3022 mutex_lock(&client_mutex);
3023 list_add(&dai->list, &dai_list);
3024 snd_soc_instantiate_cards();
3025 mutex_unlock(&client_mutex);
3027 pr_debug("Registered DAI '%s'\n", dai->name);
3031 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3034 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3036 * @dai: DAI to unregister
3038 void snd_soc_unregister_dai(struct device *dev)
3040 struct snd_soc_dai *dai;
3042 list_for_each_entry(dai, &dai_list, list) {
3043 if (dev == dai->dev)
3049 mutex_lock(&client_mutex);
3050 list_del(&dai->list);
3051 mutex_unlock(&client_mutex);
3053 pr_debug("Unregistered DAI '%s'\n", dai->name);
3057 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3060 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3062 * @dai: Array of DAIs to register
3063 * @count: Number of DAIs
3065 int snd_soc_register_dais(struct device *dev,
3066 struct snd_soc_dai_driver *dai_drv, size_t count)
3068 struct snd_soc_dai *dai;
3071 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3073 for (i = 0; i < count; i++) {
3075 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3081 /* create DAI component name */
3082 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3083 if (dai->name == NULL) {
3090 dai->driver = &dai_drv[i];
3091 if (dai->driver->id)
3092 dai->id = dai->driver->id;
3095 if (!dai->driver->ops)
3096 dai->driver->ops = &null_dai_ops;
3098 mutex_lock(&client_mutex);
3099 list_add(&dai->list, &dai_list);
3100 mutex_unlock(&client_mutex);
3102 pr_debug("Registered DAI '%s'\n", dai->name);
3105 mutex_lock(&client_mutex);
3106 snd_soc_instantiate_cards();
3107 mutex_unlock(&client_mutex);
3111 for (i--; i >= 0; i--)
3112 snd_soc_unregister_dai(dev);
3116 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3119 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3121 * @dai: Array of DAIs to unregister
3122 * @count: Number of DAIs
3124 void snd_soc_unregister_dais(struct device *dev, size_t count)
3128 for (i = 0; i < count; i++)
3129 snd_soc_unregister_dai(dev);
3131 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3134 * snd_soc_register_platform - Register a platform with the ASoC core
3136 * @platform: platform to register
3138 int snd_soc_register_platform(struct device *dev,
3139 struct snd_soc_platform_driver *platform_drv)
3141 struct snd_soc_platform *platform;
3143 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3145 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3146 if (platform == NULL)
3149 /* create platform component name */
3150 platform->name = fmt_single_name(dev, &platform->id);
3151 if (platform->name == NULL) {
3156 platform->dev = dev;
3157 platform->driver = platform_drv;
3158 platform->dapm.dev = dev;
3159 platform->dapm.platform = platform;
3160 platform->dapm.stream_event = platform_drv->stream_event;
3162 mutex_lock(&client_mutex);
3163 list_add(&platform->list, &platform_list);
3164 snd_soc_instantiate_cards();
3165 mutex_unlock(&client_mutex);
3167 pr_debug("Registered platform '%s'\n", platform->name);
3171 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3174 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3176 * @platform: platform to unregister
3178 void snd_soc_unregister_platform(struct device *dev)
3180 struct snd_soc_platform *platform;
3182 list_for_each_entry(platform, &platform_list, list) {
3183 if (dev == platform->dev)
3189 mutex_lock(&client_mutex);
3190 list_del(&platform->list);
3191 mutex_unlock(&client_mutex);
3193 pr_debug("Unregistered platform '%s'\n", platform->name);
3194 kfree(platform->name);
3197 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3199 static u64 codec_format_map[] = {
3200 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3201 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3202 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3203 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3204 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3205 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3206 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3207 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3208 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3209 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3210 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3211 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3212 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3213 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3214 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3215 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3218 /* Fix up the DAI formats for endianness: codecs don't actually see
3219 * the endianness of the data but we're using the CPU format
3220 * definitions which do need to include endianness so we ensure that
3221 * codec DAIs always have both big and little endian variants set.
3223 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3227 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3228 if (stream->formats & codec_format_map[i])
3229 stream->formats |= codec_format_map[i];
3233 * snd_soc_register_codec - Register a codec with the ASoC core
3235 * @codec: codec to register
3237 int snd_soc_register_codec(struct device *dev,
3238 const struct snd_soc_codec_driver *codec_drv,
3239 struct snd_soc_dai_driver *dai_drv,
3243 struct snd_soc_codec *codec;
3246 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3248 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3252 /* create CODEC component name */
3253 codec->name = fmt_single_name(dev, &codec->id);
3254 if (codec->name == NULL) {
3259 if (codec_drv->compress_type)
3260 codec->compress_type = codec_drv->compress_type;
3262 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3264 codec->write = codec_drv->write;
3265 codec->read = codec_drv->read;
3266 codec->volatile_register = codec_drv->volatile_register;
3267 codec->readable_register = codec_drv->readable_register;
3268 codec->writable_register = codec_drv->writable_register;
3269 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3270 codec->dapm.dev = dev;
3271 codec->dapm.codec = codec;
3272 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3273 codec->dapm.stream_event = codec_drv->stream_event;
3275 codec->driver = codec_drv;
3276 codec->num_dai = num_dai;
3277 mutex_init(&codec->mutex);
3279 /* allocate CODEC register cache */
3280 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3281 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3282 codec->reg_size = reg_size;
3283 /* it is necessary to make a copy of the default register cache
3284 * because in the case of using a compression type that requires
3285 * the default register cache to be marked as __devinitconst the
3286 * kernel might have freed the array by the time we initialize
3289 if (codec_drv->reg_cache_default) {
3290 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3291 reg_size, GFP_KERNEL);
3292 if (!codec->reg_def_copy) {
3299 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3300 if (!codec->volatile_register)
3301 codec->volatile_register = snd_soc_default_volatile_register;
3302 if (!codec->readable_register)
3303 codec->readable_register = snd_soc_default_readable_register;
3304 if (!codec->writable_register)
3305 codec->writable_register = snd_soc_default_writable_register;
3308 for (i = 0; i < num_dai; i++) {
3309 fixup_codec_formats(&dai_drv[i].playback);
3310 fixup_codec_formats(&dai_drv[i].capture);
3313 /* register any DAIs */
3315 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3320 mutex_lock(&client_mutex);
3321 list_add(&codec->list, &codec_list);
3322 snd_soc_instantiate_cards();
3323 mutex_unlock(&client_mutex);
3325 pr_debug("Registered codec '%s'\n", codec->name);
3329 kfree(codec->reg_def_copy);
3330 codec->reg_def_copy = NULL;
3335 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3338 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3340 * @codec: codec to unregister
3342 void snd_soc_unregister_codec(struct device *dev)
3344 struct snd_soc_codec *codec;
3347 list_for_each_entry(codec, &codec_list, list) {
3348 if (dev == codec->dev)
3355 for (i = 0; i < codec->num_dai; i++)
3356 snd_soc_unregister_dai(dev);
3358 mutex_lock(&client_mutex);
3359 list_del(&codec->list);
3360 mutex_unlock(&client_mutex);
3362 pr_debug("Unregistered codec '%s'\n", codec->name);
3364 snd_soc_cache_exit(codec);
3365 kfree(codec->reg_def_copy);
3369 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3371 /* Retrieve a card's name from device tree */
3372 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3373 const char *propname)
3375 struct device_node *np = card->dev->of_node;
3378 ret = of_property_read_string_index(np, propname, 0, &card->name);
3380 * EINVAL means the property does not exist. This is fine providing
3381 * card->name was previously set, which is checked later in
3382 * snd_soc_register_card.
3384 if (ret < 0 && ret != -EINVAL) {
3386 "Property '%s' could not be read: %d\n",
3393 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3395 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3396 const char *propname)
3398 struct device_node *np = card->dev->of_node;
3400 struct snd_soc_dapm_route *routes;
3403 num_routes = of_property_count_strings(np, propname);
3404 if (num_routes & 1) {
3406 "Property '%s's length is not even\n",
3413 "Property '%s's length is zero\n",
3418 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3422 "Could not allocate DAPM route table\n");
3426 for (i = 0; i < num_routes; i++) {
3427 ret = of_property_read_string_index(np, propname,
3428 2 * i, &routes[i].sink);
3431 "Property '%s' index %d could not be read: %d\n",
3432 propname, 2 * i, ret);
3435 ret = of_property_read_string_index(np, propname,
3436 (2 * i) + 1, &routes[i].source);
3439 "Property '%s' index %d could not be read: %d\n",
3440 propname, (2 * i) + 1, ret);
3445 card->num_dapm_routes = num_routes;
3446 card->dapm_routes = routes;
3450 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3452 static int __init snd_soc_init(void)
3454 #ifdef CONFIG_DEBUG_FS
3455 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3456 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
3458 "ASoC: Failed to create debugfs directory\n");
3459 snd_soc_debugfs_root = NULL;
3462 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
3464 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3466 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
3468 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3470 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
3471 &platform_list_fops))
3472 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3475 snd_soc_util_init();
3477 return platform_driver_register(&soc_driver);
3479 module_init(snd_soc_init);
3481 static void __exit snd_soc_exit(void)
3483 snd_soc_util_exit();
3485 #ifdef CONFIG_DEBUG_FS
3486 debugfs_remove_recursive(snd_soc_debugfs_root);
3488 platform_driver_unregister(&soc_driver);
3490 module_exit(snd_soc_exit);
3492 /* Module information */
3493 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3494 MODULE_DESCRIPTION("ALSA SoC Core");
3495 MODULE_LICENSE("GPL");
3496 MODULE_ALIAS("platform:soc-audio");