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);
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
67 static int pmdown_time = 5000;
68 module_param(pmdown_time, int, 0);
69 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71 /* returns the minimum number of bytes needed to represent
72 * a particular given value */
73 static int min_bytes_needed(unsigned long val)
78 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
81 c = (sizeof val * 8) - c;
89 /* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91 static int format_register_str(struct snd_soc_codec *codec,
92 unsigned int reg, char *buf, size_t len)
94 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
95 int regsize = codec->driver->reg_word_size * 2;
98 char regbuf[regsize + 1];
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize + regsize + 2 + 1 != len)
108 ret = snd_soc_read(codec, reg);
110 memset(regbuf, 'X', regsize);
111 regbuf[regsize] = '\0';
113 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
116 /* prepare the buffer */
117 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf, tmpbuf, len);
124 /* codec register dump */
125 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
126 size_t count, loff_t pos)
129 int wordsize, regsize;
134 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
135 regsize = codec->driver->reg_word_size * 2;
137 len = wordsize + regsize + 2 + 1;
139 if (!codec->driver->reg_cache_size)
142 if (codec->driver->reg_cache_step)
143 step = codec->driver->reg_cache_step;
145 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
146 if (!snd_soc_codec_readable_register(codec, i))
148 if (codec->driver->display_register) {
149 count += codec->driver->display_register(codec, buf + count,
150 PAGE_SIZE - count, i);
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
155 if (total + len >= count - 1)
157 format_register_str(codec, i, buf + total, len);
164 total = min(total, count - 1);
169 static ssize_t codec_reg_show(struct device *dev,
170 struct device_attribute *attr, char *buf)
172 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
174 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
177 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
179 static ssize_t pmdown_time_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
182 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
184 return sprintf(buf, "%ld\n", rtd->pmdown_time);
187 static ssize_t pmdown_time_set(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
191 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
194 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
201 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
203 #ifdef CONFIG_DEBUG_FS
204 static int codec_reg_open_file(struct inode *inode, struct file *file)
206 file->private_data = inode->i_private;
210 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
211 size_t count, loff_t *ppos)
214 struct snd_soc_codec *codec = file->private_data;
217 if (*ppos < 0 || !count)
220 buf = kmalloc(count, GFP_KERNEL);
224 ret = soc_codec_reg_show(codec, buf, count, *ppos);
226 if (copy_to_user(user_buf, buf, ret)) {
237 static ssize_t codec_reg_write_file(struct file *file,
238 const char __user *user_buf, size_t count, loff_t *ppos)
243 unsigned long reg, value;
244 struct snd_soc_codec *codec = file->private_data;
246 buf_size = min(count, (sizeof(buf)-1));
247 if (copy_from_user(buf, user_buf, buf_size))
251 while (*start == ' ')
253 reg = simple_strtoul(start, &start, 16);
254 while (*start == ' ')
256 if (strict_strtoul(start, 16, &value))
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER);
262 snd_soc_write(codec, reg, value);
266 static const struct file_operations codec_reg_fops = {
267 .open = codec_reg_open_file,
268 .read = codec_reg_read_file,
269 .write = codec_reg_write_file,
270 .llseek = default_llseek,
273 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
275 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
277 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
279 if (!codec->debugfs_codec_root) {
281 "ASoC: Failed to create codec debugfs directory\n");
285 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
287 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
290 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
291 codec->debugfs_codec_root,
292 codec, &codec_reg_fops);
293 if (!codec->debugfs_reg)
295 "ASoC: Failed to create codec register debugfs file\n");
297 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
300 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
302 debugfs_remove_recursive(codec->debugfs_codec_root);
305 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
306 size_t count, loff_t *ppos)
308 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
309 ssize_t len, ret = 0;
310 struct snd_soc_codec *codec;
315 list_for_each_entry(codec, &codec_list, list) {
316 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
320 if (ret > PAGE_SIZE) {
327 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
334 static const struct file_operations codec_list_fops = {
335 .read = codec_list_read_file,
336 .llseek = default_llseek,/* read accesses f_pos */
339 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
340 size_t count, loff_t *ppos)
342 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
343 ssize_t len, ret = 0;
344 struct snd_soc_dai *dai;
349 list_for_each_entry(dai, &dai_list, list) {
350 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
353 if (ret > PAGE_SIZE) {
359 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
366 static const struct file_operations dai_list_fops = {
367 .read = dai_list_read_file,
368 .llseek = default_llseek,/* read accesses f_pos */
371 static ssize_t platform_list_read_file(struct file *file,
372 char __user *user_buf,
373 size_t count, loff_t *ppos)
375 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
376 ssize_t len, ret = 0;
377 struct snd_soc_platform *platform;
382 list_for_each_entry(platform, &platform_list, list) {
383 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
387 if (ret > PAGE_SIZE) {
393 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
400 static const struct file_operations platform_list_fops = {
401 .read = platform_list_read_file,
402 .llseek = default_llseek,/* read accesses f_pos */
405 static void soc_init_card_debugfs(struct snd_soc_card *card)
407 card->debugfs_card_root = debugfs_create_dir(card->name,
408 snd_soc_debugfs_root);
409 if (!card->debugfs_card_root) {
411 "ASoC: Failed to create card debugfs directory\n");
415 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
416 card->debugfs_card_root,
418 if (!card->debugfs_pop_time)
420 "Failed to create pop time debugfs file\n");
423 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
425 debugfs_remove_recursive(card->debugfs_card_root);
430 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
434 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
438 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
442 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
447 #ifdef CONFIG_SND_SOC_AC97_BUS
448 /* unregister ac97 codec */
449 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
451 if (codec->ac97->dev.bus)
452 device_unregister(&codec->ac97->dev);
456 /* stop no dev release warning */
457 static void soc_ac97_device_release(struct device *dev){}
459 /* register ac97 codec to bus */
460 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
464 codec->ac97->dev.bus = &ac97_bus_type;
465 codec->ac97->dev.parent = codec->card->dev;
466 codec->ac97->dev.release = soc_ac97_device_release;
468 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
469 codec->card->snd_card->number, 0, codec->name);
470 err = device_register(&codec->ac97->dev);
472 snd_printk(KERN_ERR "Can't register ac97 bus\n");
473 codec->ac97->dev.bus = NULL;
480 #ifdef CONFIG_PM_SLEEP
481 /* powers down audio subsystem for suspend */
482 int snd_soc_suspend(struct device *dev)
484 struct snd_soc_card *card = dev_get_drvdata(dev);
485 struct snd_soc_codec *codec;
488 /* If the initialization of this soc device failed, there is no codec
489 * associated with it. Just bail out in this case.
491 if (list_empty(&card->codec_dev_list))
494 /* Due to the resume being scheduled into a workqueue we could
495 * suspend before that's finished - wait for it to complete.
497 snd_power_lock(card->snd_card);
498 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
499 snd_power_unlock(card->snd_card);
501 /* we're going to block userspace touching us until resume completes */
502 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
504 /* mute any active DACs */
505 for (i = 0; i < card->num_rtd; i++) {
506 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
507 struct snd_soc_dai_driver *drv = dai->driver;
509 if (card->rtd[i].dai_link->ignore_suspend)
512 if (drv->ops->digital_mute && dai->playback_active)
513 drv->ops->digital_mute(dai, 1);
516 /* suspend all pcms */
517 for (i = 0; i < card->num_rtd; i++) {
518 if (card->rtd[i].dai_link->ignore_suspend)
521 snd_pcm_suspend_all(card->rtd[i].pcm);
524 if (card->suspend_pre)
525 card->suspend_pre(card);
527 for (i = 0; i < card->num_rtd; i++) {
528 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
529 struct snd_soc_platform *platform = card->rtd[i].platform;
531 if (card->rtd[i].dai_link->ignore_suspend)
534 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
535 cpu_dai->driver->suspend(cpu_dai);
536 if (platform->driver->suspend && !platform->suspended) {
537 platform->driver->suspend(cpu_dai);
538 platform->suspended = 1;
542 /* close any waiting streams and save state */
543 for (i = 0; i < card->num_rtd; i++) {
544 flush_delayed_work_sync(&card->rtd[i].delayed_work);
545 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
548 for (i = 0; i < card->num_rtd; i++) {
549 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
551 if (card->rtd[i].dai_link->ignore_suspend)
554 if (driver->playback.stream_name != NULL)
555 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
556 SND_SOC_DAPM_STREAM_SUSPEND);
558 if (driver->capture.stream_name != NULL)
559 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
560 SND_SOC_DAPM_STREAM_SUSPEND);
563 /* suspend all CODECs */
564 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
565 /* If there are paths active then the CODEC will be held with
566 * bias _ON and should not be suspended. */
567 if (!codec->suspended && codec->driver->suspend) {
568 switch (codec->dapm.bias_level) {
569 case SND_SOC_BIAS_STANDBY:
570 case SND_SOC_BIAS_OFF:
571 codec->driver->suspend(codec);
572 codec->suspended = 1;
573 codec->cache_sync = 1;
576 dev_dbg(codec->dev, "CODEC is on over suspend\n");
582 for (i = 0; i < card->num_rtd; i++) {
583 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
585 if (card->rtd[i].dai_link->ignore_suspend)
588 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
589 cpu_dai->driver->suspend(cpu_dai);
592 if (card->suspend_post)
593 card->suspend_post(card);
597 EXPORT_SYMBOL_GPL(snd_soc_suspend);
599 /* deferred resume work, so resume can complete before we finished
600 * setting our codec back up, which can be very slow on I2C
602 static void soc_resume_deferred(struct work_struct *work)
604 struct snd_soc_card *card =
605 container_of(work, struct snd_soc_card, deferred_resume_work);
606 struct snd_soc_codec *codec;
609 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
610 * so userspace apps are blocked from touching us
613 dev_dbg(card->dev, "starting resume work\n");
615 /* Bring us up into D2 so that DAPM starts enabling things */
616 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
618 if (card->resume_pre)
619 card->resume_pre(card);
621 /* resume AC97 DAIs */
622 for (i = 0; i < card->num_rtd; i++) {
623 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
625 if (card->rtd[i].dai_link->ignore_suspend)
628 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
629 cpu_dai->driver->resume(cpu_dai);
632 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
633 /* If the CODEC was idle over suspend then it will have been
634 * left with bias OFF or STANDBY and suspended so we must now
635 * resume. Otherwise the suspend was suppressed.
637 if (codec->driver->resume && codec->suspended) {
638 switch (codec->dapm.bias_level) {
639 case SND_SOC_BIAS_STANDBY:
640 case SND_SOC_BIAS_OFF:
641 codec->driver->resume(codec);
642 codec->suspended = 0;
645 dev_dbg(codec->dev, "CODEC was on over suspend\n");
651 for (i = 0; i < card->num_rtd; i++) {
652 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
654 if (card->rtd[i].dai_link->ignore_suspend)
657 if (driver->playback.stream_name != NULL)
658 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
659 SND_SOC_DAPM_STREAM_RESUME);
661 if (driver->capture.stream_name != NULL)
662 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
663 SND_SOC_DAPM_STREAM_RESUME);
666 /* unmute any active DACs */
667 for (i = 0; i < card->num_rtd; i++) {
668 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
669 struct snd_soc_dai_driver *drv = dai->driver;
671 if (card->rtd[i].dai_link->ignore_suspend)
674 if (drv->ops->digital_mute && dai->playback_active)
675 drv->ops->digital_mute(dai, 0);
678 for (i = 0; i < card->num_rtd; i++) {
679 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
680 struct snd_soc_platform *platform = card->rtd[i].platform;
682 if (card->rtd[i].dai_link->ignore_suspend)
685 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
686 cpu_dai->driver->resume(cpu_dai);
687 if (platform->driver->resume && platform->suspended) {
688 platform->driver->resume(cpu_dai);
689 platform->suspended = 0;
693 if (card->resume_post)
694 card->resume_post(card);
696 dev_dbg(card->dev, "resume work completed\n");
698 /* userspace can access us now we are back as we were before */
699 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
702 /* powers up audio subsystem after a suspend */
703 int snd_soc_resume(struct device *dev)
705 struct snd_soc_card *card = dev_get_drvdata(dev);
706 int i, ac97_control = 0;
708 /* If the initialization of this soc device failed, there is no codec
709 * associated with it. Just bail out in this case.
711 if (list_empty(&card->codec_dev_list))
714 /* AC97 devices might have other drivers hanging off them so
715 * need to resume immediately. Other drivers don't have that
716 * problem and may take a substantial amount of time to resume
717 * due to I/O costs and anti-pop so handle them out of line.
719 for (i = 0; i < card->num_rtd; i++) {
720 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
721 ac97_control |= cpu_dai->driver->ac97_control;
724 dev_dbg(dev, "Resuming AC97 immediately\n");
725 soc_resume_deferred(&card->deferred_resume_work);
727 dev_dbg(dev, "Scheduling resume work\n");
728 if (!schedule_work(&card->deferred_resume_work))
729 dev_err(dev, "resume work item may be lost\n");
734 EXPORT_SYMBOL_GPL(snd_soc_resume);
736 #define snd_soc_suspend NULL
737 #define snd_soc_resume NULL
740 static const struct snd_soc_dai_ops null_dai_ops = {
743 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
745 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
746 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
747 struct snd_soc_codec *codec;
748 struct snd_soc_platform *platform;
749 struct snd_soc_dai *codec_dai, *cpu_dai;
750 const char *platform_name;
754 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
756 /* do we already have the CPU DAI for this link ? */
760 /* no, then find CPU DAI from registered DAIs*/
761 list_for_each_entry(cpu_dai, &dai_list, list) {
762 if (dai_link->cpu_dai_of_node) {
763 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
766 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
770 rtd->cpu_dai = cpu_dai;
773 dev_dbg(card->dev, "CPU DAI %s not registered\n",
774 dai_link->cpu_dai_name);
777 /* do we already have the CODEC for this link ? */
782 /* no, then find CODEC from registered CODECs*/
783 list_for_each_entry(codec, &codec_list, list) {
784 if (dai_link->codec_of_node) {
785 if (codec->dev->of_node != dai_link->codec_of_node)
788 if (strcmp(codec->name, dai_link->codec_name))
795 * CODEC found, so find CODEC DAI from registered DAIs from
798 list_for_each_entry(codec_dai, &dai_list, list) {
799 if (codec->dev == codec_dai->dev &&
800 !strcmp(codec_dai->name,
801 dai_link->codec_dai_name)) {
803 rtd->codec_dai = codec_dai;
807 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
808 dai_link->codec_dai_name);
812 dev_dbg(card->dev, "CODEC %s not registered\n",
813 dai_link->codec_name);
816 /* do we need a platform? */
820 /* if there's no platform we match on the empty platform */
821 platform_name = dai_link->platform_name;
822 if (!platform_name && !dai_link->platform_of_node)
823 platform_name = "snd-soc-dummy";
825 /* no, then find one from the set of registered platforms */
826 list_for_each_entry(platform, &platform_list, list) {
827 if (dai_link->platform_of_node) {
828 if (platform->dev->of_node !=
829 dai_link->platform_of_node)
832 if (strcmp(platform->name, platform_name))
836 rtd->platform = platform;
840 dev_dbg(card->dev, "platform %s not registered\n",
841 dai_link->platform_name);
845 /* mark rtd as complete if we found all 4 of our client devices */
846 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
853 static void soc_remove_codec(struct snd_soc_codec *codec)
857 if (codec->driver->remove) {
858 err = codec->driver->remove(codec);
861 "asoc: failed to remove %s: %d\n",
865 /* Make sure all DAPM widgets are freed */
866 snd_soc_dapm_free(&codec->dapm);
868 soc_cleanup_codec_debugfs(codec);
870 list_del(&codec->card_list);
871 module_put(codec->dev->driver->owner);
874 static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
876 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
877 struct snd_soc_codec *codec = rtd->codec;
878 struct snd_soc_platform *platform = rtd->platform;
879 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
882 /* unregister the rtd device */
883 if (rtd->dev_registered) {
884 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
885 device_remove_file(rtd->dev, &dev_attr_codec_reg);
886 device_unregister(rtd->dev);
887 rtd->dev_registered = 0;
890 /* remove the CODEC DAI */
891 if (codec_dai && codec_dai->probed &&
892 codec_dai->driver->remove_order == order) {
893 if (codec_dai->driver->remove) {
894 err = codec_dai->driver->remove(codec_dai);
896 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
898 codec_dai->probed = 0;
899 list_del(&codec_dai->card_list);
902 /* remove the platform */
903 if (platform && platform->probed &&
904 platform->driver->remove_order == order) {
905 if (platform->driver->remove) {
906 err = platform->driver->remove(platform);
908 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
910 platform->probed = 0;
911 list_del(&platform->card_list);
912 module_put(platform->dev->driver->owner);
915 /* remove the CODEC */
916 if (codec && codec->probed &&
917 codec->driver->remove_order == order)
918 soc_remove_codec(codec);
920 /* remove the cpu_dai */
921 if (cpu_dai && cpu_dai->probed &&
922 cpu_dai->driver->remove_order == order) {
923 if (cpu_dai->driver->remove) {
924 err = cpu_dai->driver->remove(cpu_dai);
926 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
929 list_del(&cpu_dai->card_list);
930 module_put(cpu_dai->dev->driver->owner);
934 static void soc_remove_dai_links(struct snd_soc_card *card)
938 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
940 for (dai = 0; dai < card->num_rtd; dai++)
941 soc_remove_dai_link(card, dai, order);
946 static void soc_set_name_prefix(struct snd_soc_card *card,
947 struct snd_soc_codec *codec)
951 if (card->codec_conf == NULL)
954 for (i = 0; i < card->num_configs; i++) {
955 struct snd_soc_codec_conf *map = &card->codec_conf[i];
956 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
957 codec->name_prefix = map->name_prefix;
963 static int soc_probe_codec(struct snd_soc_card *card,
964 struct snd_soc_codec *codec)
967 const struct snd_soc_codec_driver *driver = codec->driver;
970 codec->dapm.card = card;
971 soc_set_name_prefix(card, codec);
973 if (!try_module_get(codec->dev->driver->owner))
976 soc_init_codec_debugfs(codec);
978 if (driver->dapm_widgets)
979 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
980 driver->num_dapm_widgets);
982 codec->dapm.idle_bias_off = driver->idle_bias_off;
985 ret = driver->probe(codec);
988 "asoc: failed to probe CODEC %s: %d\n",
994 if (driver->controls)
995 snd_soc_add_controls(codec, driver->controls,
996 driver->num_controls);
997 if (driver->dapm_routes)
998 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
999 driver->num_dapm_routes);
1001 /* mark codec as probed and add to card codec list */
1003 list_add(&codec->card_list, &card->codec_dev_list);
1004 list_add(&codec->dapm.list, &card->dapm_list);
1009 soc_cleanup_codec_debugfs(codec);
1010 module_put(codec->dev->driver->owner);
1015 static int soc_probe_platform(struct snd_soc_card *card,
1016 struct snd_soc_platform *platform)
1019 const struct snd_soc_platform_driver *driver = platform->driver;
1021 platform->card = card;
1022 platform->dapm.card = card;
1024 if (!try_module_get(platform->dev->driver->owner))
1027 if (driver->dapm_widgets)
1028 snd_soc_dapm_new_controls(&platform->dapm,
1029 driver->dapm_widgets, driver->num_dapm_widgets);
1031 if (driver->probe) {
1032 ret = driver->probe(platform);
1034 dev_err(platform->dev,
1035 "asoc: failed to probe platform %s: %d\n",
1036 platform->name, ret);
1041 if (driver->controls)
1042 snd_soc_add_platform_controls(platform, driver->controls,
1043 driver->num_controls);
1044 if (driver->dapm_routes)
1045 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1046 driver->num_dapm_routes);
1048 /* mark platform as probed and add to card platform list */
1049 platform->probed = 1;
1050 list_add(&platform->card_list, &card->platform_dev_list);
1051 list_add(&platform->dapm.list, &card->dapm_list);
1056 module_put(platform->dev->driver->owner);
1061 static void rtd_release(struct device *dev)
1066 static int soc_post_component_init(struct snd_soc_card *card,
1067 struct snd_soc_codec *codec,
1068 int num, int dailess)
1070 struct snd_soc_dai_link *dai_link = NULL;
1071 struct snd_soc_aux_dev *aux_dev = NULL;
1072 struct snd_soc_pcm_runtime *rtd;
1073 const char *temp, *name;
1077 dai_link = &card->dai_link[num];
1078 rtd = &card->rtd[num];
1079 name = dai_link->name;
1081 aux_dev = &card->aux_dev[num];
1082 rtd = &card->rtd_aux[num];
1083 name = aux_dev->name;
1087 /* Make sure all DAPM widgets are instantiated */
1088 snd_soc_dapm_new_widgets(&codec->dapm);
1090 /* machine controls, routes and widgets are not prefixed */
1091 temp = codec->name_prefix;
1092 codec->name_prefix = NULL;
1094 /* do machine specific initialization */
1095 if (!dailess && dai_link->init)
1096 ret = dai_link->init(rtd);
1097 else if (dailess && aux_dev->init)
1098 ret = aux_dev->init(&codec->dapm);
1100 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1103 codec->name_prefix = temp;
1105 /* register the rtd device */
1108 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1111 device_initialize(rtd->dev);
1112 rtd->dev->parent = card->dev;
1113 rtd->dev->release = rtd_release;
1114 rtd->dev->init_name = name;
1115 dev_set_drvdata(rtd->dev, rtd);
1116 mutex_init(&rtd->pcm_mutex);
1117 ret = device_add(rtd->dev);
1120 "asoc: failed to register runtime device: %d\n", ret);
1123 rtd->dev_registered = 1;
1125 /* add DAPM sysfs entries for this codec */
1126 ret = snd_soc_dapm_sys_add(rtd->dev);
1129 "asoc: failed to add codec dapm sysfs entries: %d\n",
1132 /* add codec sysfs entries */
1133 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
1136 "asoc: failed to add codec sysfs files: %d\n", ret);
1141 static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1143 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1144 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1145 struct snd_soc_codec *codec = rtd->codec;
1146 struct snd_soc_platform *platform = rtd->platform;
1147 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1150 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1151 card->name, num, order);
1153 /* config components */
1154 codec_dai->codec = codec;
1155 cpu_dai->platform = platform;
1156 codec_dai->card = card;
1157 cpu_dai->card = card;
1159 /* set default power off timeout */
1160 rtd->pmdown_time = pmdown_time;
1162 /* probe the cpu_dai */
1163 if (!cpu_dai->probed &&
1164 cpu_dai->driver->probe_order == order) {
1165 if (!try_module_get(cpu_dai->dev->driver->owner))
1168 if (cpu_dai->driver->probe) {
1169 ret = cpu_dai->driver->probe(cpu_dai);
1171 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1173 module_put(cpu_dai->dev->driver->owner);
1177 cpu_dai->probed = 1;
1178 /* mark cpu_dai as probed and add to card dai list */
1179 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1182 /* probe the CODEC */
1183 if (!codec->probed &&
1184 codec->driver->probe_order == order) {
1185 ret = soc_probe_codec(card, codec);
1190 /* probe the platform */
1191 if (!platform->probed &&
1192 platform->driver->probe_order == order) {
1193 ret = soc_probe_platform(card, platform);
1198 /* probe the CODEC DAI */
1199 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1200 if (codec_dai->driver->probe) {
1201 ret = codec_dai->driver->probe(codec_dai);
1203 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1209 /* mark codec_dai as probed and add to card dai list */
1210 codec_dai->probed = 1;
1211 list_add(&codec_dai->card_list, &card->dai_dev_list);
1214 /* complete DAI probe during last probe */
1215 if (order != SND_SOC_COMP_ORDER_LAST)
1218 ret = soc_post_component_init(card, codec, num, 0);
1222 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1224 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1226 /* create the pcm */
1227 ret = soc_new_pcm(rtd, num);
1229 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1233 /* add platform data for AC97 devices */
1234 if (rtd->codec_dai->driver->ac97_control)
1235 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1240 #ifdef CONFIG_SND_SOC_AC97_BUS
1241 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1245 /* Only instantiate AC97 if not already done by the adaptor
1246 * for the generic AC97 subsystem.
1248 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1250 * It is possible that the AC97 device is already registered to
1251 * the device subsystem. This happens when the device is created
1252 * via snd_ac97_mixer(). Currently only SoC codec that does so
1253 * is the generic AC97 glue but others migh emerge.
1255 * In those cases we don't try to register the device again.
1257 if (!rtd->codec->ac97_created)
1260 ret = soc_ac97_dev_register(rtd->codec);
1262 printk(KERN_ERR "asoc: AC97 device register failed\n");
1266 rtd->codec->ac97_registered = 1;
1271 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1273 if (codec->ac97_registered) {
1274 soc_ac97_dev_unregister(codec);
1275 codec->ac97_registered = 0;
1280 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1282 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1283 struct snd_soc_codec *codec;
1286 /* find CODEC from registered CODECs*/
1287 list_for_each_entry(codec, &codec_list, list) {
1288 if (!strcmp(codec->name, aux_dev->codec_name)) {
1289 if (codec->probed) {
1291 "asoc: codec already probed");
1298 /* codec not found */
1299 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1303 ret = soc_probe_codec(card, codec);
1307 ret = soc_post_component_init(card, codec, num, 1);
1313 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1315 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1316 struct snd_soc_codec *codec = rtd->codec;
1318 /* unregister the rtd device */
1319 if (rtd->dev_registered) {
1320 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1321 device_del(rtd->dev);
1322 rtd->dev_registered = 0;
1325 if (codec && codec->probed)
1326 soc_remove_codec(codec);
1329 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1330 enum snd_soc_compress_type compress_type)
1334 if (codec->cache_init)
1337 /* override the compress_type if necessary */
1338 if (compress_type && codec->compress_type != compress_type)
1339 codec->compress_type = compress_type;
1340 ret = snd_soc_cache_init(codec);
1342 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1346 codec->cache_init = 1;
1350 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1352 struct snd_soc_codec *codec;
1353 struct snd_soc_codec_conf *codec_conf;
1354 enum snd_soc_compress_type compress_type;
1355 struct snd_soc_dai_link *dai_link;
1358 mutex_lock(&card->mutex);
1360 if (card->instantiated) {
1361 mutex_unlock(&card->mutex);
1366 for (i = 0; i < card->num_links; i++)
1367 soc_bind_dai_link(card, i);
1369 /* bind completed ? */
1370 if (card->num_rtd != card->num_links) {
1371 mutex_unlock(&card->mutex);
1375 /* initialize the register cache for each available codec */
1376 list_for_each_entry(codec, &codec_list, list) {
1377 if (codec->cache_init)
1379 /* by default we don't override the compress_type */
1381 /* check to see if we need to override the compress_type */
1382 for (i = 0; i < card->num_configs; ++i) {
1383 codec_conf = &card->codec_conf[i];
1384 if (!strcmp(codec->name, codec_conf->dev_name)) {
1385 compress_type = codec_conf->compress_type;
1386 if (compress_type && compress_type
1387 != codec->compress_type)
1391 ret = snd_soc_init_codec_cache(codec, compress_type);
1393 mutex_unlock(&card->mutex);
1398 /* card bind complete so register a sound card */
1399 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1400 card->owner, 0, &card->snd_card);
1402 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1404 mutex_unlock(&card->mutex);
1407 card->snd_card->dev = card->dev;
1409 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1410 card->dapm.dev = card->dev;
1411 card->dapm.card = card;
1412 list_add(&card->dapm.list, &card->dapm_list);
1414 #ifdef CONFIG_DEBUG_FS
1415 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1418 #ifdef CONFIG_PM_SLEEP
1419 /* deferred resume work */
1420 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1423 if (card->dapm_widgets)
1424 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1425 card->num_dapm_widgets);
1427 /* initialise the sound card only once */
1429 ret = card->probe(card);
1431 goto card_probe_error;
1434 /* early DAI link probe */
1435 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1437 for (i = 0; i < card->num_links; i++) {
1438 ret = soc_probe_dai_link(card, i, order);
1440 pr_err("asoc: failed to instantiate card %s: %d\n",
1447 for (i = 0; i < card->num_aux_devs; i++) {
1448 ret = soc_probe_aux_dev(card, i);
1450 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1452 goto probe_aux_dev_err;
1456 /* We should have a non-codec control add function but we don't */
1458 snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
1459 struct snd_soc_codec,
1462 card->num_controls);
1464 if (card->dapm_routes)
1465 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1466 card->num_dapm_routes);
1468 snd_soc_dapm_new_widgets(&card->dapm);
1470 for (i = 0; i < card->num_links; i++) {
1471 dai_link = &card->dai_link[i];
1473 if (dai_link->dai_fmt) {
1474 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1477 dev_warn(card->rtd[i].codec_dai->dev,
1478 "Failed to set DAI format: %d\n",
1481 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1484 dev_warn(card->rtd[i].cpu_dai->dev,
1485 "Failed to set DAI format: %d\n",
1490 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1492 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1493 "%s", card->long_name ? card->long_name : card->name);
1494 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1495 "%s", card->driver_name ? card->driver_name : card->name);
1496 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1497 switch (card->snd_card->driver[i]) {
1503 if (!isalnum(card->snd_card->driver[i]))
1504 card->snd_card->driver[i] = '_';
1509 if (card->late_probe) {
1510 ret = card->late_probe(card);
1512 dev_err(card->dev, "%s late_probe() failed: %d\n",
1514 goto probe_aux_dev_err;
1518 snd_soc_dapm_new_widgets(&card->dapm);
1520 if (card->fully_routed)
1521 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1522 snd_soc_dapm_auto_nc_codec_pins(codec);
1524 ret = snd_card_register(card->snd_card);
1526 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1527 goto probe_aux_dev_err;
1530 #ifdef CONFIG_SND_SOC_AC97_BUS
1531 /* register any AC97 codecs */
1532 for (i = 0; i < card->num_rtd; i++) {
1533 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1535 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1537 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1538 goto probe_aux_dev_err;
1543 card->instantiated = 1;
1544 snd_soc_dapm_sync(&card->dapm);
1545 mutex_unlock(&card->mutex);
1549 for (i = 0; i < card->num_aux_devs; i++)
1550 soc_remove_aux_dev(card, i);
1553 soc_remove_dai_links(card);
1559 snd_card_free(card->snd_card);
1561 mutex_unlock(&card->mutex);
1565 * Attempt to initialise any uninitialised cards. Must be called with
1568 static void snd_soc_instantiate_cards(void)
1570 struct snd_soc_card *card;
1571 list_for_each_entry(card, &card_list, list)
1572 snd_soc_instantiate_card(card);
1575 /* probes a new socdev */
1576 static int soc_probe(struct platform_device *pdev)
1578 struct snd_soc_card *card = platform_get_drvdata(pdev);
1582 * no card, so machine driver should be registering card
1583 * we should not be here in that case so ret error
1588 /* Bodge while we unpick instantiation */
1589 card->dev = &pdev->dev;
1591 ret = snd_soc_register_card(card);
1593 dev_err(&pdev->dev, "Failed to register card\n");
1600 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1604 /* make sure any delayed work runs */
1605 for (i = 0; i < card->num_rtd; i++) {
1606 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1607 flush_delayed_work_sync(&rtd->delayed_work);
1610 /* remove auxiliary devices */
1611 for (i = 0; i < card->num_aux_devs; i++)
1612 soc_remove_aux_dev(card, i);
1614 /* remove and free each DAI */
1615 soc_remove_dai_links(card);
1617 soc_cleanup_card_debugfs(card);
1619 /* remove the card */
1623 snd_soc_dapm_free(&card->dapm);
1626 snd_card_free(card->snd_card);
1631 /* removes a socdev */
1632 static int soc_remove(struct platform_device *pdev)
1634 struct snd_soc_card *card = platform_get_drvdata(pdev);
1636 snd_soc_unregister_card(card);
1640 int snd_soc_poweroff(struct device *dev)
1642 struct snd_soc_card *card = dev_get_drvdata(dev);
1645 if (!card->instantiated)
1648 /* Flush out pmdown_time work - we actually do want to run it
1649 * now, we're shutting down so no imminent restart. */
1650 for (i = 0; i < card->num_rtd; i++) {
1651 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1652 flush_delayed_work_sync(&rtd->delayed_work);
1655 snd_soc_dapm_shutdown(card);
1659 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1661 const struct dev_pm_ops snd_soc_pm_ops = {
1662 .suspend = snd_soc_suspend,
1663 .resume = snd_soc_resume,
1664 .poweroff = snd_soc_poweroff,
1666 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1668 /* ASoC platform driver */
1669 static struct platform_driver soc_driver = {
1671 .name = "soc-audio",
1672 .owner = THIS_MODULE,
1673 .pm = &snd_soc_pm_ops,
1676 .remove = soc_remove,
1680 * snd_soc_codec_volatile_register: Report if a register is volatile.
1682 * @codec: CODEC to query.
1683 * @reg: Register to query.
1685 * Boolean function indiciating if a CODEC register is volatile.
1687 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1690 if (codec->volatile_register)
1691 return codec->volatile_register(codec, reg);
1695 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1698 * snd_soc_codec_readable_register: Report if a register is readable.
1700 * @codec: CODEC to query.
1701 * @reg: Register to query.
1703 * Boolean function indicating if a CODEC register is readable.
1705 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1708 if (codec->readable_register)
1709 return codec->readable_register(codec, reg);
1713 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1716 * snd_soc_codec_writable_register: Report if a register is writable.
1718 * @codec: CODEC to query.
1719 * @reg: Register to query.
1721 * Boolean function indicating if a CODEC register is writable.
1723 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1726 if (codec->writable_register)
1727 return codec->writable_register(codec, reg);
1731 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1733 int snd_soc_platform_read(struct snd_soc_platform *platform,
1738 if (!platform->driver->read) {
1739 dev_err(platform->dev, "platform has no read back\n");
1743 ret = platform->driver->read(platform, reg);
1744 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
1745 trace_snd_soc_preg_read(platform, reg, ret);
1749 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1751 int snd_soc_platform_write(struct snd_soc_platform *platform,
1752 unsigned int reg, unsigned int val)
1754 if (!platform->driver->write) {
1755 dev_err(platform->dev, "platform has no write back\n");
1759 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
1760 trace_snd_soc_preg_write(platform, reg, val);
1761 return platform->driver->write(platform, reg, val);
1763 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1766 * snd_soc_new_ac97_codec - initailise AC97 device
1767 * @codec: audio codec
1768 * @ops: AC97 bus operations
1769 * @num: AC97 codec number
1771 * Initialises AC97 codec resources for use by ad-hoc devices only.
1773 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1774 struct snd_ac97_bus_ops *ops, int num)
1776 mutex_lock(&codec->mutex);
1778 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1779 if (codec->ac97 == NULL) {
1780 mutex_unlock(&codec->mutex);
1784 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1785 if (codec->ac97->bus == NULL) {
1788 mutex_unlock(&codec->mutex);
1792 codec->ac97->bus->ops = ops;
1793 codec->ac97->num = num;
1796 * Mark the AC97 device to be created by us. This way we ensure that the
1797 * device will be registered with the device subsystem later on.
1799 codec->ac97_created = 1;
1801 mutex_unlock(&codec->mutex);
1804 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1807 * snd_soc_free_ac97_codec - free AC97 codec device
1808 * @codec: audio codec
1810 * Frees AC97 codec device resources.
1812 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1814 mutex_lock(&codec->mutex);
1815 #ifdef CONFIG_SND_SOC_AC97_BUS
1816 soc_unregister_ac97_dai_link(codec);
1818 kfree(codec->ac97->bus);
1821 codec->ac97_created = 0;
1822 mutex_unlock(&codec->mutex);
1824 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1826 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1830 ret = codec->read(codec, reg);
1831 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
1832 trace_snd_soc_reg_read(codec, reg, ret);
1836 EXPORT_SYMBOL_GPL(snd_soc_read);
1838 unsigned int snd_soc_write(struct snd_soc_codec *codec,
1839 unsigned int reg, unsigned int val)
1841 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
1842 trace_snd_soc_reg_write(codec, reg, val);
1843 return codec->write(codec, reg, val);
1845 EXPORT_SYMBOL_GPL(snd_soc_write);
1847 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1848 unsigned int reg, const void *data, size_t len)
1850 return codec->bulk_write_raw(codec, reg, data, len);
1852 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1855 * snd_soc_update_bits - update codec register bits
1856 * @codec: audio codec
1857 * @reg: codec register
1858 * @mask: register mask
1861 * Writes new register value.
1863 * Returns 1 for change, 0 for no change, or negative error code.
1865 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1866 unsigned int mask, unsigned int value)
1869 unsigned int old, new;
1872 ret = snd_soc_read(codec, reg);
1877 new = (old & ~mask) | (value & mask);
1878 change = old != new;
1880 ret = snd_soc_write(codec, reg, new);
1887 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1890 * snd_soc_update_bits_locked - update codec register bits
1891 * @codec: audio codec
1892 * @reg: codec register
1893 * @mask: register mask
1896 * Writes new register value, and takes the codec mutex.
1898 * Returns 1 for change else 0.
1900 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1901 unsigned short reg, unsigned int mask,
1906 mutex_lock(&codec->mutex);
1907 change = snd_soc_update_bits(codec, reg, mask, value);
1908 mutex_unlock(&codec->mutex);
1912 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1915 * snd_soc_test_bits - test register for change
1916 * @codec: audio codec
1917 * @reg: codec register
1918 * @mask: register mask
1921 * Tests a register with a new value and checks if the new value is
1922 * different from the old value.
1924 * Returns 1 for change else 0.
1926 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1927 unsigned int mask, unsigned int value)
1930 unsigned int old, new;
1932 old = snd_soc_read(codec, reg);
1933 new = (old & ~mask) | value;
1934 change = old != new;
1938 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1941 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1942 * @substream: the pcm substream
1943 * @hw: the hardware parameters
1945 * Sets the substream runtime hardware parameters.
1947 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1948 const struct snd_pcm_hardware *hw)
1950 struct snd_pcm_runtime *runtime = substream->runtime;
1951 runtime->hw.info = hw->info;
1952 runtime->hw.formats = hw->formats;
1953 runtime->hw.period_bytes_min = hw->period_bytes_min;
1954 runtime->hw.period_bytes_max = hw->period_bytes_max;
1955 runtime->hw.periods_min = hw->periods_min;
1956 runtime->hw.periods_max = hw->periods_max;
1957 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1958 runtime->hw.fifo_size = hw->fifo_size;
1961 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1964 * snd_soc_cnew - create new control
1965 * @_template: control template
1966 * @data: control private data
1967 * @long_name: control long name
1968 * @prefix: control name prefix
1970 * Create a new mixer control from a template control.
1972 * Returns 0 for success, else error.
1974 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1975 void *data, char *long_name,
1978 struct snd_kcontrol_new template;
1979 struct snd_kcontrol *kcontrol;
1983 memcpy(&template, _template, sizeof(template));
1987 long_name = template.name;
1990 name_len = strlen(long_name) + strlen(prefix) + 2;
1991 name = kmalloc(name_len, GFP_KERNEL);
1995 snprintf(name, name_len, "%s %s", prefix, long_name);
1997 template.name = name;
1999 template.name = long_name;
2002 kcontrol = snd_ctl_new1(&template, data);
2008 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2011 * snd_soc_add_controls - add an array of controls to a codec.
2012 * Convienience function to add a list of controls. Many codecs were
2013 * duplicating this code.
2015 * @codec: codec to add controls to
2016 * @controls: array of controls to add
2017 * @num_controls: number of elements in the array
2019 * Return 0 for success, else error.
2021 int snd_soc_add_controls(struct snd_soc_codec *codec,
2022 const struct snd_kcontrol_new *controls, int num_controls)
2024 struct snd_card *card = codec->card->snd_card;
2027 for (i = 0; i < num_controls; i++) {
2028 const struct snd_kcontrol_new *control = &controls[i];
2029 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2031 codec->name_prefix));
2033 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2034 codec->name, control->name, err);
2041 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
2044 * snd_soc_add_platform_controls - add an array of controls to a platform.
2045 * Convienience function to add a list of controls.
2047 * @platform: platform to add controls to
2048 * @controls: array of controls to add
2049 * @num_controls: number of elements in the array
2051 * Return 0 for success, else error.
2053 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2054 const struct snd_kcontrol_new *controls, int num_controls)
2056 struct snd_card *card = platform->card->snd_card;
2059 for (i = 0; i < num_controls; i++) {
2060 const struct snd_kcontrol_new *control = &controls[i];
2061 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
2062 control->name, NULL));
2064 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
2071 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2074 * snd_soc_info_enum_double - enumerated double mixer info callback
2075 * @kcontrol: mixer control
2076 * @uinfo: control element information
2078 * Callback to provide information about a double enumerated
2081 * Returns 0 for success.
2083 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2084 struct snd_ctl_elem_info *uinfo)
2086 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2088 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2089 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2090 uinfo->value.enumerated.items = e->max;
2092 if (uinfo->value.enumerated.item > e->max - 1)
2093 uinfo->value.enumerated.item = e->max - 1;
2094 strcpy(uinfo->value.enumerated.name,
2095 e->texts[uinfo->value.enumerated.item]);
2098 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2101 * snd_soc_get_enum_double - enumerated double mixer get callback
2102 * @kcontrol: mixer control
2103 * @ucontrol: control element information
2105 * Callback to get the value of a double enumerated mixer.
2107 * Returns 0 for success.
2109 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2110 struct snd_ctl_elem_value *ucontrol)
2112 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2113 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2114 unsigned int val, bitmask;
2116 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2118 val = snd_soc_read(codec, e->reg);
2119 ucontrol->value.enumerated.item[0]
2120 = (val >> e->shift_l) & (bitmask - 1);
2121 if (e->shift_l != e->shift_r)
2122 ucontrol->value.enumerated.item[1] =
2123 (val >> e->shift_r) & (bitmask - 1);
2127 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2130 * snd_soc_put_enum_double - enumerated double mixer put callback
2131 * @kcontrol: mixer control
2132 * @ucontrol: control element information
2134 * Callback to set the value of a double enumerated mixer.
2136 * Returns 0 for success.
2138 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2139 struct snd_ctl_elem_value *ucontrol)
2141 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2142 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2144 unsigned int mask, bitmask;
2146 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2148 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2150 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2151 mask = (bitmask - 1) << e->shift_l;
2152 if (e->shift_l != e->shift_r) {
2153 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2155 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2156 mask |= (bitmask - 1) << e->shift_r;
2159 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2161 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2164 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2165 * @kcontrol: mixer control
2166 * @ucontrol: control element information
2168 * Callback to get the value of a double semi enumerated mixer.
2170 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2171 * used for handling bitfield coded enumeration for example.
2173 * Returns 0 for success.
2175 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2176 struct snd_ctl_elem_value *ucontrol)
2178 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2179 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2180 unsigned int reg_val, val, mux;
2182 reg_val = snd_soc_read(codec, e->reg);
2183 val = (reg_val >> e->shift_l) & e->mask;
2184 for (mux = 0; mux < e->max; mux++) {
2185 if (val == e->values[mux])
2188 ucontrol->value.enumerated.item[0] = mux;
2189 if (e->shift_l != e->shift_r) {
2190 val = (reg_val >> e->shift_r) & e->mask;
2191 for (mux = 0; mux < e->max; mux++) {
2192 if (val == e->values[mux])
2195 ucontrol->value.enumerated.item[1] = mux;
2200 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2203 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2204 * @kcontrol: mixer control
2205 * @ucontrol: control element information
2207 * Callback to set the value of a double semi enumerated mixer.
2209 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2210 * used for handling bitfield coded enumeration for example.
2212 * Returns 0 for success.
2214 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2215 struct snd_ctl_elem_value *ucontrol)
2217 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2218 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2222 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2224 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2225 mask = e->mask << e->shift_l;
2226 if (e->shift_l != e->shift_r) {
2227 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2229 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2230 mask |= e->mask << e->shift_r;
2233 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2235 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2238 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2239 * @kcontrol: mixer control
2240 * @uinfo: control element information
2242 * Callback to provide information about an external enumerated
2245 * Returns 0 for success.
2247 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2248 struct snd_ctl_elem_info *uinfo)
2250 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2252 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2254 uinfo->value.enumerated.items = e->max;
2256 if (uinfo->value.enumerated.item > e->max - 1)
2257 uinfo->value.enumerated.item = e->max - 1;
2258 strcpy(uinfo->value.enumerated.name,
2259 e->texts[uinfo->value.enumerated.item]);
2262 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2265 * snd_soc_info_volsw_ext - external single mixer info callback
2266 * @kcontrol: mixer control
2267 * @uinfo: control element information
2269 * Callback to provide information about a single external mixer control.
2271 * Returns 0 for success.
2273 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2274 struct snd_ctl_elem_info *uinfo)
2276 int max = kcontrol->private_value;
2278 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2279 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2281 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2284 uinfo->value.integer.min = 0;
2285 uinfo->value.integer.max = max;
2288 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2291 * snd_soc_info_volsw - single mixer info callback
2292 * @kcontrol: mixer control
2293 * @uinfo: control element information
2295 * Callback to provide information about a single mixer control, or a double
2296 * mixer control that spans 2 registers.
2298 * Returns 0 for success.
2300 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_info *uinfo)
2303 struct soc_mixer_control *mc =
2304 (struct soc_mixer_control *)kcontrol->private_value;
2307 if (!mc->platform_max)
2308 mc->platform_max = mc->max;
2309 platform_max = mc->platform_max;
2311 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2312 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2314 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2316 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2317 uinfo->value.integer.min = 0;
2318 uinfo->value.integer.max = platform_max;
2321 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2324 * snd_soc_get_volsw - single mixer get callback
2325 * @kcontrol: mixer control
2326 * @ucontrol: control element information
2328 * Callback to get the value of a single mixer control, or a double mixer
2329 * control that spans 2 registers.
2331 * Returns 0 for success.
2333 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2334 struct snd_ctl_elem_value *ucontrol)
2336 struct soc_mixer_control *mc =
2337 (struct soc_mixer_control *)kcontrol->private_value;
2338 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2339 unsigned int reg = mc->reg;
2340 unsigned int reg2 = mc->rreg;
2341 unsigned int shift = mc->shift;
2342 unsigned int rshift = mc->rshift;
2344 unsigned int mask = (1 << fls(max)) - 1;
2345 unsigned int invert = mc->invert;
2347 ucontrol->value.integer.value[0] =
2348 (snd_soc_read(codec, reg) >> shift) & mask;
2350 ucontrol->value.integer.value[0] =
2351 max - ucontrol->value.integer.value[0];
2353 if (snd_soc_volsw_is_stereo(mc)) {
2355 ucontrol->value.integer.value[1] =
2356 (snd_soc_read(codec, reg) >> rshift) & mask;
2358 ucontrol->value.integer.value[1] =
2359 (snd_soc_read(codec, reg2) >> shift) & mask;
2361 ucontrol->value.integer.value[1] =
2362 max - ucontrol->value.integer.value[1];
2367 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2370 * snd_soc_put_volsw - single mixer put callback
2371 * @kcontrol: mixer control
2372 * @ucontrol: control element information
2374 * Callback to set the value of a single mixer control, or a double mixer
2375 * control that spans 2 registers.
2377 * Returns 0 for success.
2379 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2380 struct snd_ctl_elem_value *ucontrol)
2382 struct soc_mixer_control *mc =
2383 (struct soc_mixer_control *)kcontrol->private_value;
2384 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2385 unsigned int reg = mc->reg;
2386 unsigned int reg2 = mc->rreg;
2387 unsigned int shift = mc->shift;
2388 unsigned int rshift = mc->rshift;
2390 unsigned int mask = (1 << fls(max)) - 1;
2391 unsigned int invert = mc->invert;
2394 unsigned int val2 = 0;
2395 unsigned int val, val_mask;
2397 val = (ucontrol->value.integer.value[0] & mask);
2400 val_mask = mask << shift;
2402 if (snd_soc_volsw_is_stereo(mc)) {
2403 val2 = (ucontrol->value.integer.value[1] & mask);
2407 val_mask |= mask << rshift;
2408 val |= val2 << rshift;
2410 val2 = val2 << shift;
2414 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2419 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2423 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2426 * snd_soc_info_volsw_s8 - signed mixer info callback
2427 * @kcontrol: mixer control
2428 * @uinfo: control element information
2430 * Callback to provide information about a signed mixer control.
2432 * Returns 0 for success.
2434 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2435 struct snd_ctl_elem_info *uinfo)
2437 struct soc_mixer_control *mc =
2438 (struct soc_mixer_control *)kcontrol->private_value;
2442 if (!mc->platform_max)
2443 mc->platform_max = mc->max;
2444 platform_max = mc->platform_max;
2446 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2448 uinfo->value.integer.min = 0;
2449 uinfo->value.integer.max = platform_max - min;
2452 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2455 * snd_soc_get_volsw_s8 - signed mixer get callback
2456 * @kcontrol: mixer control
2457 * @ucontrol: control element information
2459 * Callback to get the value of a signed mixer control.
2461 * Returns 0 for success.
2463 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2464 struct snd_ctl_elem_value *ucontrol)
2466 struct soc_mixer_control *mc =
2467 (struct soc_mixer_control *)kcontrol->private_value;
2468 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2469 unsigned int reg = mc->reg;
2471 int val = snd_soc_read(codec, reg);
2473 ucontrol->value.integer.value[0] =
2474 ((signed char)(val & 0xff))-min;
2475 ucontrol->value.integer.value[1] =
2476 ((signed char)((val >> 8) & 0xff))-min;
2479 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2482 * snd_soc_put_volsw_sgn - signed mixer put callback
2483 * @kcontrol: mixer control
2484 * @ucontrol: control element information
2486 * Callback to set the value of a signed mixer control.
2488 * Returns 0 for success.
2490 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2491 struct snd_ctl_elem_value *ucontrol)
2493 struct soc_mixer_control *mc =
2494 (struct soc_mixer_control *)kcontrol->private_value;
2495 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2496 unsigned int reg = mc->reg;
2500 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2501 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2503 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2505 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2508 * snd_soc_limit_volume - Set new limit to an existing volume control.
2510 * @codec: where to look for the control
2511 * @name: Name of the control
2512 * @max: new maximum limit
2514 * Return 0 for success, else error.
2516 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2517 const char *name, int max)
2519 struct snd_card *card = codec->card->snd_card;
2520 struct snd_kcontrol *kctl;
2521 struct soc_mixer_control *mc;
2525 /* Sanity check for name and max */
2526 if (unlikely(!name || max <= 0))
2529 list_for_each_entry(kctl, &card->controls, list) {
2530 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2536 mc = (struct soc_mixer_control *)kctl->private_value;
2537 if (max <= mc->max) {
2538 mc->platform_max = max;
2544 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2547 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2548 * mixer info callback
2549 * @kcontrol: mixer control
2550 * @uinfo: control element information
2552 * Returns 0 for success.
2554 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_info *uinfo)
2557 struct soc_mixer_control *mc =
2558 (struct soc_mixer_control *)kcontrol->private_value;
2562 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2564 uinfo->value.integer.min = 0;
2565 uinfo->value.integer.max = max-min;
2569 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2572 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2573 * mixer get callback
2574 * @kcontrol: mixer control
2575 * @uinfo: control element information
2577 * Returns 0 for success.
2579 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2580 struct snd_ctl_elem_value *ucontrol)
2582 struct soc_mixer_control *mc =
2583 (struct soc_mixer_control *)kcontrol->private_value;
2584 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2585 unsigned int mask = (1<<mc->shift)-1;
2587 int val = snd_soc_read(codec, mc->reg) & mask;
2588 int valr = snd_soc_read(codec, mc->rreg) & mask;
2590 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2591 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2594 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2597 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2598 * mixer put callback
2599 * @kcontrol: mixer control
2600 * @uinfo: control element information
2602 * Returns 0 for success.
2604 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2605 struct snd_ctl_elem_value *ucontrol)
2607 struct soc_mixer_control *mc =
2608 (struct soc_mixer_control *)kcontrol->private_value;
2609 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2610 unsigned int mask = (1<<mc->shift)-1;
2613 unsigned int val, valr, oval, ovalr;
2615 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2617 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2620 oval = snd_soc_read(codec, mc->reg) & mask;
2621 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2625 ret = snd_soc_write(codec, mc->reg, val);
2629 if (ovalr != valr) {
2630 ret = snd_soc_write(codec, mc->rreg, valr);
2637 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2640 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2642 * @clk_id: DAI specific clock ID
2643 * @freq: new clock frequency in Hz
2644 * @dir: new clock direction - input/output.
2646 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2648 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2649 unsigned int freq, int dir)
2651 if (dai->driver && dai->driver->ops->set_sysclk)
2652 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2653 else if (dai->codec && dai->codec->driver->set_sysclk)
2654 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2659 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2662 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2664 * @clk_id: DAI specific clock ID
2665 * @source: Source for the clock
2666 * @freq: new clock frequency in Hz
2667 * @dir: new clock direction - input/output.
2669 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2671 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2672 int source, unsigned int freq, int dir)
2674 if (codec->driver->set_sysclk)
2675 return codec->driver->set_sysclk(codec, clk_id, source,
2680 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2683 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2685 * @div_id: DAI specific clock divider ID
2686 * @div: new clock divisor.
2688 * Configures the clock dividers. This is used to derive the best DAI bit and
2689 * frame clocks from the system or master clock. It's best to set the DAI bit
2690 * and frame clocks as low as possible to save system power.
2692 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2693 int div_id, int div)
2695 if (dai->driver && dai->driver->ops->set_clkdiv)
2696 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2700 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2703 * snd_soc_dai_set_pll - configure DAI PLL.
2705 * @pll_id: DAI specific PLL ID
2706 * @source: DAI specific source for the PLL
2707 * @freq_in: PLL input clock frequency in Hz
2708 * @freq_out: requested PLL output clock frequency in Hz
2710 * Configures and enables PLL to generate output clock based on input clock.
2712 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2713 unsigned int freq_in, unsigned int freq_out)
2715 if (dai->driver && dai->driver->ops->set_pll)
2716 return dai->driver->ops->set_pll(dai, pll_id, source,
2718 else if (dai->codec && dai->codec->driver->set_pll)
2719 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2724 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2727 * snd_soc_codec_set_pll - configure codec PLL.
2729 * @pll_id: DAI specific PLL ID
2730 * @source: DAI specific source for the PLL
2731 * @freq_in: PLL input clock frequency in Hz
2732 * @freq_out: requested PLL output clock frequency in Hz
2734 * Configures and enables PLL to generate output clock based on input clock.
2736 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2737 unsigned int freq_in, unsigned int freq_out)
2739 if (codec->driver->set_pll)
2740 return codec->driver->set_pll(codec, pll_id, source,
2745 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2748 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2750 * @fmt: SND_SOC_DAIFMT_ format value.
2752 * Configures the DAI hardware format and clocking.
2754 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2756 if (dai->driver && dai->driver->ops->set_fmt)
2757 return dai->driver->ops->set_fmt(dai, fmt);
2761 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2764 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2766 * @tx_mask: bitmask representing active TX slots.
2767 * @rx_mask: bitmask representing active RX slots.
2768 * @slots: Number of slots in use.
2769 * @slot_width: Width in bits for each slot.
2771 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2774 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2775 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2777 if (dai->driver && dai->driver->ops->set_tdm_slot)
2778 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2783 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2786 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2788 * @tx_num: how many TX channels
2789 * @tx_slot: pointer to an array which imply the TX slot number channel
2791 * @rx_num: how many RX channels
2792 * @rx_slot: pointer to an array which imply the RX slot number channel
2795 * configure the relationship between channel number and TDM slot number.
2797 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2798 unsigned int tx_num, unsigned int *tx_slot,
2799 unsigned int rx_num, unsigned int *rx_slot)
2801 if (dai->driver && dai->driver->ops->set_channel_map)
2802 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2807 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2810 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2812 * @tristate: tristate enable
2814 * Tristates the DAI so that others can use it.
2816 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2818 if (dai->driver && dai->driver->ops->set_tristate)
2819 return dai->driver->ops->set_tristate(dai, tristate);
2823 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2826 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2828 * @mute: mute enable
2830 * Mutes the DAI DAC.
2832 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2834 if (dai->driver && dai->driver->ops->digital_mute)
2835 return dai->driver->ops->digital_mute(dai, mute);
2839 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2842 * snd_soc_register_card - Register a card with the ASoC core
2844 * @card: Card to register
2847 int snd_soc_register_card(struct snd_soc_card *card)
2851 if (!card->name || !card->dev)
2854 for (i = 0; i < card->num_links; i++) {
2855 struct snd_soc_dai_link *link = &card->dai_link[i];
2858 * Codec must be specified by 1 of name or OF node,
2859 * not both or neither.
2861 if (!!link->codec_name == !!link->codec_of_node) {
2863 "Neither/both codec name/of_node are set\n");
2868 * Platform may be specified by either name or OF node, but
2869 * can be left unspecified, and a dummy platform will be used.
2871 if (link->platform_name && link->platform_of_node) {
2873 "Both platform name/of_node are set\n");
2878 * CPU DAI must be specified by 1 of name or OF node,
2879 * not both or neither.
2881 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2883 "Neither/both cpu_dai name/of_node are set\n");
2888 dev_set_drvdata(card->dev, card);
2890 snd_soc_initialize_card_lists(card);
2892 soc_init_card_debugfs(card);
2894 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2895 (card->num_links + card->num_aux_devs),
2897 if (card->rtd == NULL)
2899 card->rtd_aux = &card->rtd[card->num_links];
2901 for (i = 0; i < card->num_links; i++)
2902 card->rtd[i].dai_link = &card->dai_link[i];
2904 INIT_LIST_HEAD(&card->list);
2905 INIT_LIST_HEAD(&card->dapm_dirty);
2906 card->instantiated = 0;
2907 mutex_init(&card->mutex);
2909 mutex_lock(&client_mutex);
2910 list_add(&card->list, &card_list);
2911 snd_soc_instantiate_cards();
2912 mutex_unlock(&client_mutex);
2914 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2918 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2921 * snd_soc_unregister_card - Unregister a card with the ASoC core
2923 * @card: Card to unregister
2926 int snd_soc_unregister_card(struct snd_soc_card *card)
2928 if (card->instantiated)
2929 soc_cleanup_card_resources(card);
2930 mutex_lock(&client_mutex);
2931 list_del(&card->list);
2932 mutex_unlock(&client_mutex);
2933 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2937 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2940 * Simplify DAI link configuration by removing ".-1" from device names
2941 * and sanitizing names.
2943 static char *fmt_single_name(struct device *dev, int *id)
2945 char *found, name[NAME_SIZE];
2948 if (dev_name(dev) == NULL)
2951 strlcpy(name, dev_name(dev), NAME_SIZE);
2953 /* are we a "%s.%d" name (platform and SPI components) */
2954 found = strstr(name, dev->driver->name);
2957 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2959 /* discard ID from name if ID == -1 */
2961 found[strlen(dev->driver->name)] = '\0';
2965 /* I2C component devices are named "bus-addr" */
2966 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2967 char tmp[NAME_SIZE];
2969 /* create unique ID number from I2C addr and bus */
2970 *id = ((id1 & 0xffff) << 16) + id2;
2972 /* sanitize component name for DAI link creation */
2973 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2974 strlcpy(name, tmp, NAME_SIZE);
2979 return kstrdup(name, GFP_KERNEL);
2983 * Simplify DAI link naming for single devices with multiple DAIs by removing
2984 * any ".-1" and using the DAI name (instead of device name).
2986 static inline char *fmt_multiple_name(struct device *dev,
2987 struct snd_soc_dai_driver *dai_drv)
2989 if (dai_drv->name == NULL) {
2990 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2995 return kstrdup(dai_drv->name, GFP_KERNEL);
2999 * snd_soc_register_dai - Register a DAI with the ASoC core
3001 * @dai: DAI to register
3003 int snd_soc_register_dai(struct device *dev,
3004 struct snd_soc_dai_driver *dai_drv)
3006 struct snd_soc_dai *dai;
3008 dev_dbg(dev, "dai register %s\n", dev_name(dev));
3010 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3014 /* create DAI component name */
3015 dai->name = fmt_single_name(dev, &dai->id);
3016 if (dai->name == NULL) {
3022 dai->driver = dai_drv;
3023 if (!dai->driver->ops)
3024 dai->driver->ops = &null_dai_ops;
3026 mutex_lock(&client_mutex);
3027 list_add(&dai->list, &dai_list);
3028 snd_soc_instantiate_cards();
3029 mutex_unlock(&client_mutex);
3031 pr_debug("Registered DAI '%s'\n", dai->name);
3035 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3038 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3040 * @dai: DAI to unregister
3042 void snd_soc_unregister_dai(struct device *dev)
3044 struct snd_soc_dai *dai;
3046 list_for_each_entry(dai, &dai_list, list) {
3047 if (dev == dai->dev)
3053 mutex_lock(&client_mutex);
3054 list_del(&dai->list);
3055 mutex_unlock(&client_mutex);
3057 pr_debug("Unregistered DAI '%s'\n", dai->name);
3061 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3064 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3066 * @dai: Array of DAIs to register
3067 * @count: Number of DAIs
3069 int snd_soc_register_dais(struct device *dev,
3070 struct snd_soc_dai_driver *dai_drv, size_t count)
3072 struct snd_soc_dai *dai;
3075 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3077 for (i = 0; i < count; i++) {
3079 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3085 /* create DAI component name */
3086 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3087 if (dai->name == NULL) {
3094 dai->driver = &dai_drv[i];
3095 if (dai->driver->id)
3096 dai->id = dai->driver->id;
3099 if (!dai->driver->ops)
3100 dai->driver->ops = &null_dai_ops;
3102 mutex_lock(&client_mutex);
3103 list_add(&dai->list, &dai_list);
3104 mutex_unlock(&client_mutex);
3106 pr_debug("Registered DAI '%s'\n", dai->name);
3109 mutex_lock(&client_mutex);
3110 snd_soc_instantiate_cards();
3111 mutex_unlock(&client_mutex);
3115 for (i--; i >= 0; i--)
3116 snd_soc_unregister_dai(dev);
3120 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3123 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3125 * @dai: Array of DAIs to unregister
3126 * @count: Number of DAIs
3128 void snd_soc_unregister_dais(struct device *dev, size_t count)
3132 for (i = 0; i < count; i++)
3133 snd_soc_unregister_dai(dev);
3135 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3138 * snd_soc_register_platform - Register a platform with the ASoC core
3140 * @platform: platform to register
3142 int snd_soc_register_platform(struct device *dev,
3143 struct snd_soc_platform_driver *platform_drv)
3145 struct snd_soc_platform *platform;
3147 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3149 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3150 if (platform == NULL)
3153 /* create platform component name */
3154 platform->name = fmt_single_name(dev, &platform->id);
3155 if (platform->name == NULL) {
3160 platform->dev = dev;
3161 platform->driver = platform_drv;
3162 platform->dapm.dev = dev;
3163 platform->dapm.platform = platform;
3164 platform->dapm.stream_event = platform_drv->stream_event;
3166 mutex_lock(&client_mutex);
3167 list_add(&platform->list, &platform_list);
3168 snd_soc_instantiate_cards();
3169 mutex_unlock(&client_mutex);
3171 pr_debug("Registered platform '%s'\n", platform->name);
3175 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3178 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3180 * @platform: platform to unregister
3182 void snd_soc_unregister_platform(struct device *dev)
3184 struct snd_soc_platform *platform;
3186 list_for_each_entry(platform, &platform_list, list) {
3187 if (dev == platform->dev)
3193 mutex_lock(&client_mutex);
3194 list_del(&platform->list);
3195 mutex_unlock(&client_mutex);
3197 pr_debug("Unregistered platform '%s'\n", platform->name);
3198 kfree(platform->name);
3201 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3203 static u64 codec_format_map[] = {
3204 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3205 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3206 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3207 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3208 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3209 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3210 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3211 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3212 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3213 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3214 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3215 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3216 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3217 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3218 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3219 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3222 /* Fix up the DAI formats for endianness: codecs don't actually see
3223 * the endianness of the data but we're using the CPU format
3224 * definitions which do need to include endianness so we ensure that
3225 * codec DAIs always have both big and little endian variants set.
3227 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3231 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3232 if (stream->formats & codec_format_map[i])
3233 stream->formats |= codec_format_map[i];
3237 * snd_soc_register_codec - Register a codec with the ASoC core
3239 * @codec: codec to register
3241 int snd_soc_register_codec(struct device *dev,
3242 const struct snd_soc_codec_driver *codec_drv,
3243 struct snd_soc_dai_driver *dai_drv,
3247 struct snd_soc_codec *codec;
3250 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3252 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3256 /* create CODEC component name */
3257 codec->name = fmt_single_name(dev, &codec->id);
3258 if (codec->name == NULL) {
3263 if (codec_drv->compress_type)
3264 codec->compress_type = codec_drv->compress_type;
3266 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3268 codec->write = codec_drv->write;
3269 codec->read = codec_drv->read;
3270 codec->volatile_register = codec_drv->volatile_register;
3271 codec->readable_register = codec_drv->readable_register;
3272 codec->writable_register = codec_drv->writable_register;
3273 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3274 codec->dapm.dev = dev;
3275 codec->dapm.codec = codec;
3276 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3277 codec->dapm.stream_event = codec_drv->stream_event;
3279 codec->driver = codec_drv;
3280 codec->num_dai = num_dai;
3281 mutex_init(&codec->mutex);
3283 /* allocate CODEC register cache */
3284 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3285 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3286 codec->reg_size = reg_size;
3287 /* it is necessary to make a copy of the default register cache
3288 * because in the case of using a compression type that requires
3289 * the default register cache to be marked as __devinitconst the
3290 * kernel might have freed the array by the time we initialize
3293 if (codec_drv->reg_cache_default) {
3294 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3295 reg_size, GFP_KERNEL);
3296 if (!codec->reg_def_copy) {
3303 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3304 if (!codec->volatile_register)
3305 codec->volatile_register = snd_soc_default_volatile_register;
3306 if (!codec->readable_register)
3307 codec->readable_register = snd_soc_default_readable_register;
3308 if (!codec->writable_register)
3309 codec->writable_register = snd_soc_default_writable_register;
3312 for (i = 0; i < num_dai; i++) {
3313 fixup_codec_formats(&dai_drv[i].playback);
3314 fixup_codec_formats(&dai_drv[i].capture);
3317 /* register any DAIs */
3319 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3324 mutex_lock(&client_mutex);
3325 list_add(&codec->list, &codec_list);
3326 snd_soc_instantiate_cards();
3327 mutex_unlock(&client_mutex);
3329 pr_debug("Registered codec '%s'\n", codec->name);
3333 kfree(codec->reg_def_copy);
3334 codec->reg_def_copy = NULL;
3339 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3342 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3344 * @codec: codec to unregister
3346 void snd_soc_unregister_codec(struct device *dev)
3348 struct snd_soc_codec *codec;
3351 list_for_each_entry(codec, &codec_list, list) {
3352 if (dev == codec->dev)
3359 for (i = 0; i < codec->num_dai; i++)
3360 snd_soc_unregister_dai(dev);
3362 mutex_lock(&client_mutex);
3363 list_del(&codec->list);
3364 mutex_unlock(&client_mutex);
3366 pr_debug("Unregistered codec '%s'\n", codec->name);
3368 snd_soc_cache_exit(codec);
3369 kfree(codec->reg_def_copy);
3373 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3375 /* Retrieve a card's name from device tree */
3376 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3377 const char *propname)
3379 struct device_node *np = card->dev->of_node;
3382 ret = of_property_read_string_index(np, propname, 0, &card->name);
3384 * EINVAL means the property does not exist. This is fine providing
3385 * card->name was previously set, which is checked later in
3386 * snd_soc_register_card.
3388 if (ret < 0 && ret != -EINVAL) {
3390 "Property '%s' could not be read: %d\n",
3397 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3399 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3400 const char *propname)
3402 struct device_node *np = card->dev->of_node;
3404 struct snd_soc_dapm_route *routes;
3407 num_routes = of_property_count_strings(np, propname);
3408 if (num_routes & 1) {
3410 "Property '%s's length is not even\n",
3417 "Property '%s's length is zero\n",
3422 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3426 "Could not allocate DAPM route table\n");
3430 for (i = 0; i < num_routes; i++) {
3431 ret = of_property_read_string_index(np, propname,
3432 2 * i, &routes[i].sink);
3435 "Property '%s' index %d could not be read: %d\n",
3436 propname, 2 * i, ret);
3439 ret = of_property_read_string_index(np, propname,
3440 (2 * i) + 1, &routes[i].source);
3443 "Property '%s' index %d could not be read: %d\n",
3444 propname, (2 * i) + 1, ret);
3449 card->num_dapm_routes = num_routes;
3450 card->dapm_routes = routes;
3454 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3456 static int __init snd_soc_init(void)
3458 #ifdef CONFIG_DEBUG_FS
3459 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3460 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
3462 "ASoC: Failed to create debugfs directory\n");
3463 snd_soc_debugfs_root = NULL;
3466 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
3468 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3470 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
3472 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3474 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
3475 &platform_list_fops))
3476 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3479 snd_soc_util_init();
3481 return platform_driver_register(&soc_driver);
3483 module_init(snd_soc_init);
3485 static void __exit snd_soc_exit(void)
3487 snd_soc_util_exit();
3489 #ifdef CONFIG_DEBUG_FS
3490 debugfs_remove_recursive(snd_soc_debugfs_root);
3492 platform_driver_unregister(&soc_driver);
3494 module_exit(snd_soc_exit);
3496 /* Module information */
3497 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3498 MODULE_DESCRIPTION("ALSA SoC Core");
3499 MODULE_LICENSE("GPL");
3500 MODULE_ALIAS("platform:soc-audio");