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 =
173 container_of(dev, struct snd_soc_pcm_runtime, dev);
175 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
178 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
180 static ssize_t pmdown_time_show(struct device *dev,
181 struct device_attribute *attr, char *buf)
183 struct snd_soc_pcm_runtime *rtd =
184 container_of(dev, struct snd_soc_pcm_runtime, dev);
186 return sprintf(buf, "%ld\n", rtd->pmdown_time);
189 static ssize_t pmdown_time_set(struct device *dev,
190 struct device_attribute *attr,
191 const char *buf, size_t count)
193 struct snd_soc_pcm_runtime *rtd =
194 container_of(dev, struct snd_soc_pcm_runtime, dev);
197 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
204 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
206 #ifdef CONFIG_DEBUG_FS
207 static int codec_reg_open_file(struct inode *inode, struct file *file)
209 file->private_data = inode->i_private;
213 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
214 size_t count, loff_t *ppos)
217 struct snd_soc_codec *codec = file->private_data;
220 if (*ppos < 0 || !count)
223 buf = kmalloc(count, GFP_KERNEL);
227 ret = soc_codec_reg_show(codec, buf, count, *ppos);
229 if (copy_to_user(user_buf, buf, ret)) {
240 static ssize_t codec_reg_write_file(struct file *file,
241 const char __user *user_buf, size_t count, loff_t *ppos)
246 unsigned long reg, value;
247 struct snd_soc_codec *codec = file->private_data;
249 buf_size = min(count, (sizeof(buf)-1));
250 if (copy_from_user(buf, user_buf, buf_size))
254 while (*start == ' ')
256 reg = simple_strtoul(start, &start, 16);
257 while (*start == ' ')
259 if (strict_strtoul(start, 16, &value))
262 /* Userspace has been fiddling around behind the kernel's back */
263 add_taint(TAINT_USER);
265 snd_soc_write(codec, reg, value);
269 static const struct file_operations codec_reg_fops = {
270 .open = codec_reg_open_file,
271 .read = codec_reg_read_file,
272 .write = codec_reg_write_file,
273 .llseek = default_llseek,
276 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
278 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
280 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
282 if (!codec->debugfs_codec_root) {
284 "ASoC: Failed to create codec debugfs directory\n");
288 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
290 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
293 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
294 codec->debugfs_codec_root,
295 codec, &codec_reg_fops);
296 if (!codec->debugfs_reg)
298 "ASoC: Failed to create codec register debugfs file\n");
300 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
303 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
305 debugfs_remove_recursive(codec->debugfs_codec_root);
308 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
309 size_t count, loff_t *ppos)
311 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
312 ssize_t len, ret = 0;
313 struct snd_soc_codec *codec;
318 list_for_each_entry(codec, &codec_list, list) {
319 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
323 if (ret > PAGE_SIZE) {
330 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
337 static const struct file_operations codec_list_fops = {
338 .read = codec_list_read_file,
339 .llseek = default_llseek,/* read accesses f_pos */
342 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
343 size_t count, loff_t *ppos)
345 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
346 ssize_t len, ret = 0;
347 struct snd_soc_dai *dai;
352 list_for_each_entry(dai, &dai_list, list) {
353 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
356 if (ret > PAGE_SIZE) {
362 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
369 static const struct file_operations dai_list_fops = {
370 .read = dai_list_read_file,
371 .llseek = default_llseek,/* read accesses f_pos */
374 static ssize_t platform_list_read_file(struct file *file,
375 char __user *user_buf,
376 size_t count, loff_t *ppos)
378 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
379 ssize_t len, ret = 0;
380 struct snd_soc_platform *platform;
385 list_for_each_entry(platform, &platform_list, list) {
386 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
390 if (ret > PAGE_SIZE) {
396 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
403 static const struct file_operations platform_list_fops = {
404 .read = platform_list_read_file,
405 .llseek = default_llseek,/* read accesses f_pos */
408 static void soc_init_card_debugfs(struct snd_soc_card *card)
410 card->debugfs_card_root = debugfs_create_dir(card->name,
411 snd_soc_debugfs_root);
412 if (!card->debugfs_card_root) {
414 "ASoC: Failed to create card debugfs directory\n");
418 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
419 card->debugfs_card_root,
421 if (!card->debugfs_pop_time)
423 "Failed to create pop time debugfs file\n");
426 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
428 debugfs_remove_recursive(card->debugfs_card_root);
433 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
437 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
441 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
445 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
450 #ifdef CONFIG_SND_SOC_AC97_BUS
451 /* unregister ac97 codec */
452 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
454 if (codec->ac97->dev.bus)
455 device_unregister(&codec->ac97->dev);
459 /* stop no dev release warning */
460 static void soc_ac97_device_release(struct device *dev){}
462 /* register ac97 codec to bus */
463 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
467 codec->ac97->dev.bus = &ac97_bus_type;
468 codec->ac97->dev.parent = codec->card->dev;
469 codec->ac97->dev.release = soc_ac97_device_release;
471 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
472 codec->card->snd_card->number, 0, codec->name);
473 err = device_register(&codec->ac97->dev);
475 snd_printk(KERN_ERR "Can't register ac97 bus\n");
476 codec->ac97->dev.bus = NULL;
483 #ifdef CONFIG_PM_SLEEP
484 /* powers down audio subsystem for suspend */
485 int snd_soc_suspend(struct device *dev)
487 struct snd_soc_card *card = dev_get_drvdata(dev);
488 struct snd_soc_codec *codec;
491 /* If the initialization of this soc device failed, there is no codec
492 * associated with it. Just bail out in this case.
494 if (list_empty(&card->codec_dev_list))
497 /* Due to the resume being scheduled into a workqueue we could
498 * suspend before that's finished - wait for it to complete.
500 snd_power_lock(card->snd_card);
501 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
502 snd_power_unlock(card->snd_card);
504 /* we're going to block userspace touching us until resume completes */
505 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
507 /* mute any active DACs */
508 for (i = 0; i < card->num_rtd; i++) {
509 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
510 struct snd_soc_dai_driver *drv = dai->driver;
512 if (card->rtd[i].dai_link->ignore_suspend)
515 if (drv->ops->digital_mute && dai->playback_active)
516 drv->ops->digital_mute(dai, 1);
519 /* suspend all pcms */
520 for (i = 0; i < card->num_rtd; i++) {
521 if (card->rtd[i].dai_link->ignore_suspend)
524 snd_pcm_suspend_all(card->rtd[i].pcm);
527 if (card->suspend_pre)
528 card->suspend_pre(card);
530 for (i = 0; i < card->num_rtd; i++) {
531 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
532 struct snd_soc_platform *platform = card->rtd[i].platform;
534 if (card->rtd[i].dai_link->ignore_suspend)
537 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
538 cpu_dai->driver->suspend(cpu_dai);
539 if (platform->driver->suspend && !platform->suspended) {
540 platform->driver->suspend(cpu_dai);
541 platform->suspended = 1;
545 /* close any waiting streams and save state */
546 for (i = 0; i < card->num_rtd; i++) {
547 flush_delayed_work_sync(&card->rtd[i].delayed_work);
548 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
551 for (i = 0; i < card->num_rtd; i++) {
552 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
554 if (card->rtd[i].dai_link->ignore_suspend)
557 if (driver->playback.stream_name != NULL)
558 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
559 SND_SOC_DAPM_STREAM_SUSPEND);
561 if (driver->capture.stream_name != NULL)
562 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
563 SND_SOC_DAPM_STREAM_SUSPEND);
566 /* suspend all CODECs */
567 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
568 /* If there are paths active then the CODEC will be held with
569 * bias _ON and should not be suspended. */
570 if (!codec->suspended && codec->driver->suspend) {
571 switch (codec->dapm.bias_level) {
572 case SND_SOC_BIAS_STANDBY:
573 case SND_SOC_BIAS_OFF:
574 codec->driver->suspend(codec);
575 codec->suspended = 1;
576 codec->cache_sync = 1;
579 dev_dbg(codec->dev, "CODEC is on over suspend\n");
585 for (i = 0; i < card->num_rtd; i++) {
586 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
588 if (card->rtd[i].dai_link->ignore_suspend)
591 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
592 cpu_dai->driver->suspend(cpu_dai);
595 if (card->suspend_post)
596 card->suspend_post(card);
600 EXPORT_SYMBOL_GPL(snd_soc_suspend);
602 /* deferred resume work, so resume can complete before we finished
603 * setting our codec back up, which can be very slow on I2C
605 static void soc_resume_deferred(struct work_struct *work)
607 struct snd_soc_card *card =
608 container_of(work, struct snd_soc_card, deferred_resume_work);
609 struct snd_soc_codec *codec;
612 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
613 * so userspace apps are blocked from touching us
616 dev_dbg(card->dev, "starting resume work\n");
618 /* Bring us up into D2 so that DAPM starts enabling things */
619 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
621 if (card->resume_pre)
622 card->resume_pre(card);
624 /* resume AC97 DAIs */
625 for (i = 0; i < card->num_rtd; i++) {
626 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
628 if (card->rtd[i].dai_link->ignore_suspend)
631 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
632 cpu_dai->driver->resume(cpu_dai);
635 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
636 /* If the CODEC was idle over suspend then it will have been
637 * left with bias OFF or STANDBY and suspended so we must now
638 * resume. Otherwise the suspend was suppressed.
640 if (codec->driver->resume && codec->suspended) {
641 switch (codec->dapm.bias_level) {
642 case SND_SOC_BIAS_STANDBY:
643 case SND_SOC_BIAS_OFF:
644 codec->driver->resume(codec);
645 codec->suspended = 0;
648 dev_dbg(codec->dev, "CODEC was on over suspend\n");
654 for (i = 0; i < card->num_rtd; i++) {
655 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
657 if (card->rtd[i].dai_link->ignore_suspend)
660 if (driver->playback.stream_name != NULL)
661 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
662 SND_SOC_DAPM_STREAM_RESUME);
664 if (driver->capture.stream_name != NULL)
665 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
666 SND_SOC_DAPM_STREAM_RESUME);
669 /* unmute any active DACs */
670 for (i = 0; i < card->num_rtd; i++) {
671 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
672 struct snd_soc_dai_driver *drv = dai->driver;
674 if (card->rtd[i].dai_link->ignore_suspend)
677 if (drv->ops->digital_mute && dai->playback_active)
678 drv->ops->digital_mute(dai, 0);
681 for (i = 0; i < card->num_rtd; i++) {
682 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
683 struct snd_soc_platform *platform = card->rtd[i].platform;
685 if (card->rtd[i].dai_link->ignore_suspend)
688 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
689 cpu_dai->driver->resume(cpu_dai);
690 if (platform->driver->resume && platform->suspended) {
691 platform->driver->resume(cpu_dai);
692 platform->suspended = 0;
696 if (card->resume_post)
697 card->resume_post(card);
699 dev_dbg(card->dev, "resume work completed\n");
701 /* userspace can access us now we are back as we were before */
702 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
705 /* powers up audio subsystem after a suspend */
706 int snd_soc_resume(struct device *dev)
708 struct snd_soc_card *card = dev_get_drvdata(dev);
709 int i, ac97_control = 0;
711 /* If the initialization of this soc device failed, there is no codec
712 * associated with it. Just bail out in this case.
714 if (list_empty(&card->codec_dev_list))
717 /* AC97 devices might have other drivers hanging off them so
718 * need to resume immediately. Other drivers don't have that
719 * problem and may take a substantial amount of time to resume
720 * due to I/O costs and anti-pop so handle them out of line.
722 for (i = 0; i < card->num_rtd; i++) {
723 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
724 ac97_control |= cpu_dai->driver->ac97_control;
727 dev_dbg(dev, "Resuming AC97 immediately\n");
728 soc_resume_deferred(&card->deferred_resume_work);
730 dev_dbg(dev, "Scheduling resume work\n");
731 if (!schedule_work(&card->deferred_resume_work))
732 dev_err(dev, "resume work item may be lost\n");
737 EXPORT_SYMBOL_GPL(snd_soc_resume);
739 #define snd_soc_suspend NULL
740 #define snd_soc_resume NULL
743 static const struct snd_soc_dai_ops null_dai_ops = {
746 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
748 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
749 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
750 struct snd_soc_codec *codec;
751 struct snd_soc_platform *platform;
752 struct snd_soc_dai *codec_dai, *cpu_dai;
753 const char *platform_name;
757 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
759 /* do we already have the CPU DAI for this link ? */
763 /* no, then find CPU DAI from registered DAIs*/
764 list_for_each_entry(cpu_dai, &dai_list, list) {
765 if (dai_link->cpu_dai_of_node) {
766 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
769 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
773 rtd->cpu_dai = cpu_dai;
776 dev_dbg(card->dev, "CPU DAI %s not registered\n",
777 dai_link->cpu_dai_name);
780 /* do we already have the CODEC for this link ? */
785 /* no, then find CODEC from registered CODECs*/
786 list_for_each_entry(codec, &codec_list, list) {
787 if (dai_link->codec_of_node) {
788 if (codec->dev->of_node != dai_link->codec_of_node)
791 if (strcmp(codec->name, dai_link->codec_name))
798 * CODEC found, so find CODEC DAI from registered DAIs from
801 list_for_each_entry(codec_dai, &dai_list, list) {
802 if (codec->dev == codec_dai->dev &&
803 !strcmp(codec_dai->name,
804 dai_link->codec_dai_name)) {
806 rtd->codec_dai = codec_dai;
810 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
811 dai_link->codec_dai_name);
815 dev_dbg(card->dev, "CODEC %s not registered\n",
816 dai_link->codec_name);
819 /* do we need a platform? */
823 /* if there's no platform we match on the empty platform */
824 platform_name = dai_link->platform_name;
825 if (!platform_name && !dai_link->platform_of_node)
826 platform_name = "snd-soc-dummy";
828 /* no, then find one from the set of registered platforms */
829 list_for_each_entry(platform, &platform_list, list) {
830 if (dai_link->platform_of_node) {
831 if (platform->dev->of_node !=
832 dai_link->platform_of_node)
835 if (strcmp(platform->name, platform_name))
839 rtd->platform = platform;
843 dev_dbg(card->dev, "platform %s not registered\n",
844 dai_link->platform_name);
848 /* mark rtd as complete if we found all 4 of our client devices */
849 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
856 static void soc_remove_codec(struct snd_soc_codec *codec)
860 if (codec->driver->remove) {
861 err = codec->driver->remove(codec);
864 "asoc: failed to remove %s: %d\n",
868 /* Make sure all DAPM widgets are freed */
869 snd_soc_dapm_free(&codec->dapm);
871 soc_cleanup_codec_debugfs(codec);
873 list_del(&codec->card_list);
874 module_put(codec->dev->driver->owner);
877 static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
879 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
880 struct snd_soc_codec *codec = rtd->codec;
881 struct snd_soc_platform *platform = rtd->platform;
882 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
885 /* unregister the rtd device */
886 if (rtd->dev_registered) {
887 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
888 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
889 device_unregister(&rtd->dev);
890 rtd->dev_registered = 0;
893 /* remove the CODEC DAI */
894 if (codec_dai && codec_dai->probed &&
895 codec_dai->driver->remove_order == order) {
896 if (codec_dai->driver->remove) {
897 err = codec_dai->driver->remove(codec_dai);
899 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
901 codec_dai->probed = 0;
902 list_del(&codec_dai->card_list);
905 /* remove the platform */
906 if (platform && platform->probed &&
907 platform->driver->remove_order == order) {
908 if (platform->driver->remove) {
909 err = platform->driver->remove(platform);
911 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
913 platform->probed = 0;
914 list_del(&platform->card_list);
915 module_put(platform->dev->driver->owner);
918 /* remove the CODEC */
919 if (codec && codec->probed &&
920 codec->driver->remove_order == order)
921 soc_remove_codec(codec);
923 /* remove the cpu_dai */
924 if (cpu_dai && cpu_dai->probed &&
925 cpu_dai->driver->remove_order == order) {
926 if (cpu_dai->driver->remove) {
927 err = cpu_dai->driver->remove(cpu_dai);
929 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
932 list_del(&cpu_dai->card_list);
933 module_put(cpu_dai->dev->driver->owner);
937 static void soc_remove_dai_links(struct snd_soc_card *card)
941 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
943 for (dai = 0; dai < card->num_rtd; dai++)
944 soc_remove_dai_link(card, dai, order);
949 static void soc_set_name_prefix(struct snd_soc_card *card,
950 struct snd_soc_codec *codec)
954 if (card->codec_conf == NULL)
957 for (i = 0; i < card->num_configs; i++) {
958 struct snd_soc_codec_conf *map = &card->codec_conf[i];
959 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
960 codec->name_prefix = map->name_prefix;
966 static int soc_probe_codec(struct snd_soc_card *card,
967 struct snd_soc_codec *codec)
970 const struct snd_soc_codec_driver *driver = codec->driver;
973 codec->dapm.card = card;
974 soc_set_name_prefix(card, codec);
976 if (!try_module_get(codec->dev->driver->owner))
979 soc_init_codec_debugfs(codec);
981 if (driver->dapm_widgets)
982 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
983 driver->num_dapm_widgets);
985 codec->dapm.idle_bias_off = driver->idle_bias_off;
988 ret = driver->probe(codec);
991 "asoc: failed to probe CODEC %s: %d\n",
997 if (driver->controls)
998 snd_soc_add_controls(codec, driver->controls,
999 driver->num_controls);
1000 if (driver->dapm_routes)
1001 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1002 driver->num_dapm_routes);
1004 /* mark codec as probed and add to card codec list */
1006 list_add(&codec->card_list, &card->codec_dev_list);
1007 list_add(&codec->dapm.list, &card->dapm_list);
1012 soc_cleanup_codec_debugfs(codec);
1013 module_put(codec->dev->driver->owner);
1018 static int soc_probe_platform(struct snd_soc_card *card,
1019 struct snd_soc_platform *platform)
1022 const struct snd_soc_platform_driver *driver = platform->driver;
1024 platform->card = card;
1025 platform->dapm.card = card;
1027 if (!try_module_get(platform->dev->driver->owner))
1030 if (driver->dapm_widgets)
1031 snd_soc_dapm_new_controls(&platform->dapm,
1032 driver->dapm_widgets, driver->num_dapm_widgets);
1034 if (driver->probe) {
1035 ret = driver->probe(platform);
1037 dev_err(platform->dev,
1038 "asoc: failed to probe platform %s: %d\n",
1039 platform->name, ret);
1044 if (driver->controls)
1045 snd_soc_add_platform_controls(platform, driver->controls,
1046 driver->num_controls);
1047 if (driver->dapm_routes)
1048 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1049 driver->num_dapm_routes);
1051 /* mark platform as probed and add to card platform list */
1052 platform->probed = 1;
1053 list_add(&platform->card_list, &card->platform_dev_list);
1054 list_add(&platform->dapm.list, &card->dapm_list);
1059 module_put(platform->dev->driver->owner);
1064 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 */
1107 rtd->dev.parent = card->dev;
1108 rtd->dev.release = rtd_release;
1109 rtd->dev.init_name = name;
1110 mutex_init(&rtd->pcm_mutex);
1111 ret = device_register(&rtd->dev);
1114 "asoc: failed to register runtime device: %d\n", ret);
1117 rtd->dev_registered = 1;
1119 /* add DAPM sysfs entries for this codec */
1120 ret = snd_soc_dapm_sys_add(&rtd->dev);
1123 "asoc: failed to add codec dapm sysfs entries: %d\n",
1126 /* add codec sysfs entries */
1127 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1130 "asoc: failed to add codec sysfs files: %d\n", ret);
1135 static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
1137 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1138 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1139 struct snd_soc_codec *codec = rtd->codec;
1140 struct snd_soc_platform *platform = rtd->platform;
1141 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1144 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1145 card->name, num, order);
1147 /* config components */
1148 codec_dai->codec = codec;
1149 cpu_dai->platform = platform;
1150 codec_dai->card = card;
1151 cpu_dai->card = card;
1153 /* set default power off timeout */
1154 rtd->pmdown_time = pmdown_time;
1156 /* probe the cpu_dai */
1157 if (!cpu_dai->probed &&
1158 cpu_dai->driver->probe_order == order) {
1159 if (!try_module_get(cpu_dai->dev->driver->owner))
1162 if (cpu_dai->driver->probe) {
1163 ret = cpu_dai->driver->probe(cpu_dai);
1165 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1167 module_put(cpu_dai->dev->driver->owner);
1171 cpu_dai->probed = 1;
1172 /* mark cpu_dai as probed and add to card dai list */
1173 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1176 /* probe the CODEC */
1177 if (!codec->probed &&
1178 codec->driver->probe_order == order) {
1179 ret = soc_probe_codec(card, codec);
1184 /* probe the platform */
1185 if (!platform->probed &&
1186 platform->driver->probe_order == order) {
1187 ret = soc_probe_platform(card, platform);
1192 /* probe the CODEC DAI */
1193 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1194 if (codec_dai->driver->probe) {
1195 ret = codec_dai->driver->probe(codec_dai);
1197 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1203 /* mark codec_dai as probed and add to card dai list */
1204 codec_dai->probed = 1;
1205 list_add(&codec_dai->card_list, &card->dai_dev_list);
1208 /* complete DAI probe during last probe */
1209 if (order != SND_SOC_COMP_ORDER_LAST)
1212 ret = soc_post_component_init(card, codec, num, 0);
1216 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1218 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1220 /* create the pcm */
1221 ret = soc_new_pcm(rtd, num);
1223 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1227 /* add platform data for AC97 devices */
1228 if (rtd->codec_dai->driver->ac97_control)
1229 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1234 #ifdef CONFIG_SND_SOC_AC97_BUS
1235 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1239 /* Only instantiate AC97 if not already done by the adaptor
1240 * for the generic AC97 subsystem.
1242 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1244 * It is possible that the AC97 device is already registered to
1245 * the device subsystem. This happens when the device is created
1246 * via snd_ac97_mixer(). Currently only SoC codec that does so
1247 * is the generic AC97 glue but others migh emerge.
1249 * In those cases we don't try to register the device again.
1251 if (!rtd->codec->ac97_created)
1254 ret = soc_ac97_dev_register(rtd->codec);
1256 printk(KERN_ERR "asoc: AC97 device register failed\n");
1260 rtd->codec->ac97_registered = 1;
1265 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1267 if (codec->ac97_registered) {
1268 soc_ac97_dev_unregister(codec);
1269 codec->ac97_registered = 0;
1274 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1276 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1277 struct snd_soc_codec *codec;
1280 /* find CODEC from registered CODECs*/
1281 list_for_each_entry(codec, &codec_list, list) {
1282 if (!strcmp(codec->name, aux_dev->codec_name)) {
1283 if (codec->probed) {
1285 "asoc: codec already probed");
1292 /* codec not found */
1293 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1297 ret = soc_probe_codec(card, codec);
1301 ret = soc_post_component_init(card, codec, num, 1);
1307 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1309 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1310 struct snd_soc_codec *codec = rtd->codec;
1312 /* unregister the rtd device */
1313 if (rtd->dev_registered) {
1314 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1315 device_unregister(&rtd->dev);
1316 rtd->dev_registered = 0;
1319 if (codec && codec->probed)
1320 soc_remove_codec(codec);
1323 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1324 enum snd_soc_compress_type compress_type)
1328 if (codec->cache_init)
1331 /* override the compress_type if necessary */
1332 if (compress_type && codec->compress_type != compress_type)
1333 codec->compress_type = compress_type;
1334 ret = snd_soc_cache_init(codec);
1336 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1340 codec->cache_init = 1;
1344 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1346 struct snd_soc_codec *codec;
1347 struct snd_soc_codec_conf *codec_conf;
1348 enum snd_soc_compress_type compress_type;
1349 struct snd_soc_dai_link *dai_link;
1352 mutex_lock(&card->mutex);
1354 if (card->instantiated) {
1355 mutex_unlock(&card->mutex);
1360 for (i = 0; i < card->num_links; i++)
1361 soc_bind_dai_link(card, i);
1363 /* bind completed ? */
1364 if (card->num_rtd != card->num_links) {
1365 mutex_unlock(&card->mutex);
1369 /* initialize the register cache for each available codec */
1370 list_for_each_entry(codec, &codec_list, list) {
1371 if (codec->cache_init)
1373 /* by default we don't override the compress_type */
1375 /* check to see if we need to override the compress_type */
1376 for (i = 0; i < card->num_configs; ++i) {
1377 codec_conf = &card->codec_conf[i];
1378 if (!strcmp(codec->name, codec_conf->dev_name)) {
1379 compress_type = codec_conf->compress_type;
1380 if (compress_type && compress_type
1381 != codec->compress_type)
1385 ret = snd_soc_init_codec_cache(codec, compress_type);
1387 mutex_unlock(&card->mutex);
1392 /* card bind complete so register a sound card */
1393 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1394 card->owner, 0, &card->snd_card);
1396 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1398 mutex_unlock(&card->mutex);
1401 card->snd_card->dev = card->dev;
1403 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1404 card->dapm.dev = card->dev;
1405 card->dapm.card = card;
1406 list_add(&card->dapm.list, &card->dapm_list);
1408 #ifdef CONFIG_DEBUG_FS
1409 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1412 #ifdef CONFIG_PM_SLEEP
1413 /* deferred resume work */
1414 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1417 if (card->dapm_widgets)
1418 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1419 card->num_dapm_widgets);
1421 /* initialise the sound card only once */
1423 ret = card->probe(card);
1425 goto card_probe_error;
1428 /* early DAI link probe */
1429 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1431 for (i = 0; i < card->num_links; i++) {
1432 ret = soc_probe_dai_link(card, i, order);
1434 pr_err("asoc: failed to instantiate card %s: %d\n",
1441 for (i = 0; i < card->num_aux_devs; i++) {
1442 ret = soc_probe_aux_dev(card, i);
1444 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1446 goto probe_aux_dev_err;
1450 /* We should have a non-codec control add function but we don't */
1452 snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
1453 struct snd_soc_codec,
1456 card->num_controls);
1458 if (card->dapm_routes)
1459 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1460 card->num_dapm_routes);
1462 snd_soc_dapm_new_widgets(&card->dapm);
1464 for (i = 0; i < card->num_links; i++) {
1465 dai_link = &card->dai_link[i];
1467 if (dai_link->dai_fmt) {
1468 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1471 dev_warn(card->rtd[i].codec_dai->dev,
1472 "Failed to set DAI format: %d\n",
1475 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1478 dev_warn(card->rtd[i].cpu_dai->dev,
1479 "Failed to set DAI format: %d\n",
1484 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1486 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1487 "%s", card->long_name ? card->long_name : card->name);
1488 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1489 "%s", card->driver_name ? card->driver_name : card->name);
1490 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1491 switch (card->snd_card->driver[i]) {
1497 if (!isalnum(card->snd_card->driver[i]))
1498 card->snd_card->driver[i] = '_';
1503 if (card->late_probe) {
1504 ret = card->late_probe(card);
1506 dev_err(card->dev, "%s late_probe() failed: %d\n",
1508 goto probe_aux_dev_err;
1512 snd_soc_dapm_new_widgets(&card->dapm);
1514 if (card->fully_routed)
1515 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1516 snd_soc_dapm_auto_nc_codec_pins(codec);
1518 ret = snd_card_register(card->snd_card);
1520 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1521 goto probe_aux_dev_err;
1524 #ifdef CONFIG_SND_SOC_AC97_BUS
1525 /* register any AC97 codecs */
1526 for (i = 0; i < card->num_rtd; i++) {
1527 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1529 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1531 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1532 goto probe_aux_dev_err;
1537 card->instantiated = 1;
1538 snd_soc_dapm_sync(&card->dapm);
1539 mutex_unlock(&card->mutex);
1543 for (i = 0; i < card->num_aux_devs; i++)
1544 soc_remove_aux_dev(card, i);
1547 soc_remove_dai_links(card);
1553 snd_card_free(card->snd_card);
1555 mutex_unlock(&card->mutex);
1559 * Attempt to initialise any uninitialised cards. Must be called with
1562 static void snd_soc_instantiate_cards(void)
1564 struct snd_soc_card *card;
1565 list_for_each_entry(card, &card_list, list)
1566 snd_soc_instantiate_card(card);
1569 /* probes a new socdev */
1570 static int soc_probe(struct platform_device *pdev)
1572 struct snd_soc_card *card = platform_get_drvdata(pdev);
1576 * no card, so machine driver should be registering card
1577 * we should not be here in that case so ret error
1582 /* Bodge while we unpick instantiation */
1583 card->dev = &pdev->dev;
1585 ret = snd_soc_register_card(card);
1587 dev_err(&pdev->dev, "Failed to register card\n");
1594 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1598 /* make sure any delayed work runs */
1599 for (i = 0; i < card->num_rtd; i++) {
1600 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1601 flush_delayed_work_sync(&rtd->delayed_work);
1604 /* remove auxiliary devices */
1605 for (i = 0; i < card->num_aux_devs; i++)
1606 soc_remove_aux_dev(card, i);
1608 /* remove and free each DAI */
1609 soc_remove_dai_links(card);
1611 soc_cleanup_card_debugfs(card);
1613 /* remove the card */
1617 snd_soc_dapm_free(&card->dapm);
1620 snd_card_free(card->snd_card);
1625 /* removes a socdev */
1626 static int soc_remove(struct platform_device *pdev)
1628 struct snd_soc_card *card = platform_get_drvdata(pdev);
1630 snd_soc_unregister_card(card);
1634 int snd_soc_poweroff(struct device *dev)
1636 struct snd_soc_card *card = dev_get_drvdata(dev);
1639 if (!card->instantiated)
1642 /* Flush out pmdown_time work - we actually do want to run it
1643 * now, we're shutting down so no imminent restart. */
1644 for (i = 0; i < card->num_rtd; i++) {
1645 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1646 flush_delayed_work_sync(&rtd->delayed_work);
1649 snd_soc_dapm_shutdown(card);
1653 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1655 const struct dev_pm_ops snd_soc_pm_ops = {
1656 .suspend = snd_soc_suspend,
1657 .resume = snd_soc_resume,
1658 .poweroff = snd_soc_poweroff,
1660 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1662 /* ASoC platform driver */
1663 static struct platform_driver soc_driver = {
1665 .name = "soc-audio",
1666 .owner = THIS_MODULE,
1667 .pm = &snd_soc_pm_ops,
1670 .remove = soc_remove,
1674 * snd_soc_codec_volatile_register: Report if a register is volatile.
1676 * @codec: CODEC to query.
1677 * @reg: Register to query.
1679 * Boolean function indiciating if a CODEC register is volatile.
1681 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1684 if (codec->volatile_register)
1685 return codec->volatile_register(codec, reg);
1689 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1692 * snd_soc_codec_readable_register: Report if a register is readable.
1694 * @codec: CODEC to query.
1695 * @reg: Register to query.
1697 * Boolean function indicating if a CODEC register is readable.
1699 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1702 if (codec->readable_register)
1703 return codec->readable_register(codec, reg);
1707 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1710 * snd_soc_codec_writable_register: Report if a register is writable.
1712 * @codec: CODEC to query.
1713 * @reg: Register to query.
1715 * Boolean function indicating if a CODEC register is writable.
1717 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1720 if (codec->writable_register)
1721 return codec->writable_register(codec, reg);
1725 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1727 int snd_soc_platform_read(struct snd_soc_platform *platform,
1732 if (!platform->driver->read) {
1733 dev_err(platform->dev, "platform has no read back\n");
1737 ret = platform->driver->read(platform, reg);
1738 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
1739 trace_snd_soc_preg_read(platform, reg, ret);
1743 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1745 int snd_soc_platform_write(struct snd_soc_platform *platform,
1746 unsigned int reg, unsigned int val)
1748 if (!platform->driver->write) {
1749 dev_err(platform->dev, "platform has no write back\n");
1753 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
1754 trace_snd_soc_preg_write(platform, reg, val);
1755 return platform->driver->write(platform, reg, val);
1757 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1760 * snd_soc_new_ac97_codec - initailise AC97 device
1761 * @codec: audio codec
1762 * @ops: AC97 bus operations
1763 * @num: AC97 codec number
1765 * Initialises AC97 codec resources for use by ad-hoc devices only.
1767 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1768 struct snd_ac97_bus_ops *ops, int num)
1770 mutex_lock(&codec->mutex);
1772 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1773 if (codec->ac97 == NULL) {
1774 mutex_unlock(&codec->mutex);
1778 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1779 if (codec->ac97->bus == NULL) {
1782 mutex_unlock(&codec->mutex);
1786 codec->ac97->bus->ops = ops;
1787 codec->ac97->num = num;
1790 * Mark the AC97 device to be created by us. This way we ensure that the
1791 * device will be registered with the device subsystem later on.
1793 codec->ac97_created = 1;
1795 mutex_unlock(&codec->mutex);
1798 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1801 * snd_soc_free_ac97_codec - free AC97 codec device
1802 * @codec: audio codec
1804 * Frees AC97 codec device resources.
1806 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1808 mutex_lock(&codec->mutex);
1809 #ifdef CONFIG_SND_SOC_AC97_BUS
1810 soc_unregister_ac97_dai_link(codec);
1812 kfree(codec->ac97->bus);
1815 codec->ac97_created = 0;
1816 mutex_unlock(&codec->mutex);
1818 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1820 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1824 ret = codec->read(codec, reg);
1825 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
1826 trace_snd_soc_reg_read(codec, reg, ret);
1830 EXPORT_SYMBOL_GPL(snd_soc_read);
1832 unsigned int snd_soc_write(struct snd_soc_codec *codec,
1833 unsigned int reg, unsigned int val)
1835 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
1836 trace_snd_soc_reg_write(codec, reg, val);
1837 return codec->write(codec, reg, val);
1839 EXPORT_SYMBOL_GPL(snd_soc_write);
1841 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1842 unsigned int reg, const void *data, size_t len)
1844 return codec->bulk_write_raw(codec, reg, data, len);
1846 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1849 * snd_soc_update_bits - update codec register bits
1850 * @codec: audio codec
1851 * @reg: codec register
1852 * @mask: register mask
1855 * Writes new register value.
1857 * Returns 1 for change, 0 for no change, or negative error code.
1859 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1860 unsigned int mask, unsigned int value)
1863 unsigned int old, new;
1866 ret = snd_soc_read(codec, reg);
1871 new = (old & ~mask) | (value & mask);
1872 change = old != new;
1874 ret = snd_soc_write(codec, reg, new);
1881 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1884 * snd_soc_update_bits_locked - update codec register bits
1885 * @codec: audio codec
1886 * @reg: codec register
1887 * @mask: register mask
1890 * Writes new register value, and takes the codec mutex.
1892 * Returns 1 for change else 0.
1894 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1895 unsigned short reg, unsigned int mask,
1900 mutex_lock(&codec->mutex);
1901 change = snd_soc_update_bits(codec, reg, mask, value);
1902 mutex_unlock(&codec->mutex);
1906 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1909 * snd_soc_test_bits - test register for change
1910 * @codec: audio codec
1911 * @reg: codec register
1912 * @mask: register mask
1915 * Tests a register with a new value and checks if the new value is
1916 * different from the old value.
1918 * Returns 1 for change else 0.
1920 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1921 unsigned int mask, unsigned int value)
1924 unsigned int old, new;
1926 old = snd_soc_read(codec, reg);
1927 new = (old & ~mask) | value;
1928 change = old != new;
1932 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1935 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1936 * @substream: the pcm substream
1937 * @hw: the hardware parameters
1939 * Sets the substream runtime hardware parameters.
1941 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1942 const struct snd_pcm_hardware *hw)
1944 struct snd_pcm_runtime *runtime = substream->runtime;
1945 runtime->hw.info = hw->info;
1946 runtime->hw.formats = hw->formats;
1947 runtime->hw.period_bytes_min = hw->period_bytes_min;
1948 runtime->hw.period_bytes_max = hw->period_bytes_max;
1949 runtime->hw.periods_min = hw->periods_min;
1950 runtime->hw.periods_max = hw->periods_max;
1951 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1952 runtime->hw.fifo_size = hw->fifo_size;
1955 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1958 * snd_soc_cnew - create new control
1959 * @_template: control template
1960 * @data: control private data
1961 * @long_name: control long name
1962 * @prefix: control name prefix
1964 * Create a new mixer control from a template control.
1966 * Returns 0 for success, else error.
1968 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1969 void *data, char *long_name,
1972 struct snd_kcontrol_new template;
1973 struct snd_kcontrol *kcontrol;
1977 memcpy(&template, _template, sizeof(template));
1981 long_name = template.name;
1984 name_len = strlen(long_name) + strlen(prefix) + 2;
1985 name = kmalloc(name_len, GFP_KERNEL);
1989 snprintf(name, name_len, "%s %s", prefix, long_name);
1991 template.name = name;
1993 template.name = long_name;
1996 kcontrol = snd_ctl_new1(&template, data);
2002 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2005 * snd_soc_add_controls - add an array of controls to a codec.
2006 * Convienience function to add a list of controls. Many codecs were
2007 * duplicating this code.
2009 * @codec: codec to add controls to
2010 * @controls: array of controls to add
2011 * @num_controls: number of elements in the array
2013 * Return 0 for success, else error.
2015 int snd_soc_add_controls(struct snd_soc_codec *codec,
2016 const struct snd_kcontrol_new *controls, int num_controls)
2018 struct snd_card *card = codec->card->snd_card;
2021 for (i = 0; i < num_controls; i++) {
2022 const struct snd_kcontrol_new *control = &controls[i];
2023 err = snd_ctl_add(card, snd_soc_cnew(control, codec,
2025 codec->name_prefix));
2027 dev_err(codec->dev, "%s: Failed to add %s: %d\n",
2028 codec->name, control->name, err);
2035 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
2038 * snd_soc_add_platform_controls - add an array of controls to a platform.
2039 * Convienience function to add a list of controls.
2041 * @platform: platform to add controls to
2042 * @controls: array of controls to add
2043 * @num_controls: number of elements in the array
2045 * Return 0 for success, else error.
2047 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2048 const struct snd_kcontrol_new *controls, int num_controls)
2050 struct snd_card *card = platform->card->snd_card;
2053 for (i = 0; i < num_controls; i++) {
2054 const struct snd_kcontrol_new *control = &controls[i];
2055 err = snd_ctl_add(card, snd_soc_cnew(control, platform,
2056 control->name, NULL));
2058 dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
2065 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2068 * snd_soc_info_enum_double - enumerated double mixer info callback
2069 * @kcontrol: mixer control
2070 * @uinfo: control element information
2072 * Callback to provide information about a double enumerated
2075 * Returns 0 for success.
2077 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2078 struct snd_ctl_elem_info *uinfo)
2080 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2082 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2083 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2084 uinfo->value.enumerated.items = e->max;
2086 if (uinfo->value.enumerated.item > e->max - 1)
2087 uinfo->value.enumerated.item = e->max - 1;
2088 strcpy(uinfo->value.enumerated.name,
2089 e->texts[uinfo->value.enumerated.item]);
2092 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2095 * snd_soc_get_enum_double - enumerated double mixer get callback
2096 * @kcontrol: mixer control
2097 * @ucontrol: control element information
2099 * Callback to get the value of a double enumerated mixer.
2101 * Returns 0 for success.
2103 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2104 struct snd_ctl_elem_value *ucontrol)
2106 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2107 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2108 unsigned int val, bitmask;
2110 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2112 val = snd_soc_read(codec, e->reg);
2113 ucontrol->value.enumerated.item[0]
2114 = (val >> e->shift_l) & (bitmask - 1);
2115 if (e->shift_l != e->shift_r)
2116 ucontrol->value.enumerated.item[1] =
2117 (val >> e->shift_r) & (bitmask - 1);
2121 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2124 * snd_soc_put_enum_double - enumerated double mixer put callback
2125 * @kcontrol: mixer control
2126 * @ucontrol: control element information
2128 * Callback to set the value of a double enumerated mixer.
2130 * Returns 0 for success.
2132 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2133 struct snd_ctl_elem_value *ucontrol)
2135 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2136 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2138 unsigned int mask, bitmask;
2140 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
2142 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2144 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2145 mask = (bitmask - 1) << e->shift_l;
2146 if (e->shift_l != e->shift_r) {
2147 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2149 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2150 mask |= (bitmask - 1) << e->shift_r;
2153 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2155 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2158 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2159 * @kcontrol: mixer control
2160 * @ucontrol: control element information
2162 * Callback to get the value of a double semi enumerated mixer.
2164 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2165 * used for handling bitfield coded enumeration for example.
2167 * Returns 0 for success.
2169 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2170 struct snd_ctl_elem_value *ucontrol)
2172 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2173 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2174 unsigned int reg_val, val, mux;
2176 reg_val = snd_soc_read(codec, e->reg);
2177 val = (reg_val >> e->shift_l) & e->mask;
2178 for (mux = 0; mux < e->max; mux++) {
2179 if (val == e->values[mux])
2182 ucontrol->value.enumerated.item[0] = mux;
2183 if (e->shift_l != e->shift_r) {
2184 val = (reg_val >> e->shift_r) & e->mask;
2185 for (mux = 0; mux < e->max; mux++) {
2186 if (val == e->values[mux])
2189 ucontrol->value.enumerated.item[1] = mux;
2194 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2197 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2198 * @kcontrol: mixer control
2199 * @ucontrol: control element information
2201 * Callback to set the value of a double semi enumerated mixer.
2203 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2204 * used for handling bitfield coded enumeration for example.
2206 * Returns 0 for success.
2208 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2209 struct snd_ctl_elem_value *ucontrol)
2211 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2212 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2216 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2218 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2219 mask = e->mask << e->shift_l;
2220 if (e->shift_l != e->shift_r) {
2221 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2223 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2224 mask |= e->mask << e->shift_r;
2227 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2229 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2232 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2233 * @kcontrol: mixer control
2234 * @uinfo: control element information
2236 * Callback to provide information about an external enumerated
2239 * Returns 0 for success.
2241 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2242 struct snd_ctl_elem_info *uinfo)
2244 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2246 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2248 uinfo->value.enumerated.items = e->max;
2250 if (uinfo->value.enumerated.item > e->max - 1)
2251 uinfo->value.enumerated.item = e->max - 1;
2252 strcpy(uinfo->value.enumerated.name,
2253 e->texts[uinfo->value.enumerated.item]);
2256 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2259 * snd_soc_info_volsw_ext - external single mixer info callback
2260 * @kcontrol: mixer control
2261 * @uinfo: control element information
2263 * Callback to provide information about a single external mixer control.
2265 * Returns 0 for success.
2267 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2268 struct snd_ctl_elem_info *uinfo)
2270 int max = kcontrol->private_value;
2272 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2273 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2275 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2278 uinfo->value.integer.min = 0;
2279 uinfo->value.integer.max = max;
2282 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2285 * snd_soc_info_volsw - single mixer info callback
2286 * @kcontrol: mixer control
2287 * @uinfo: control element information
2289 * Callback to provide information about a single mixer control, or a double
2290 * mixer control that spans 2 registers.
2292 * Returns 0 for success.
2294 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2295 struct snd_ctl_elem_info *uinfo)
2297 struct soc_mixer_control *mc =
2298 (struct soc_mixer_control *)kcontrol->private_value;
2301 if (!mc->platform_max)
2302 mc->platform_max = mc->max;
2303 platform_max = mc->platform_max;
2305 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2306 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2308 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2310 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2311 uinfo->value.integer.min = 0;
2312 uinfo->value.integer.max = platform_max;
2315 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2318 * snd_soc_get_volsw - single mixer get callback
2319 * @kcontrol: mixer control
2320 * @ucontrol: control element information
2322 * Callback to get the value of a single mixer control, or a double mixer
2323 * control that spans 2 registers.
2325 * Returns 0 for success.
2327 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2328 struct snd_ctl_elem_value *ucontrol)
2330 struct soc_mixer_control *mc =
2331 (struct soc_mixer_control *)kcontrol->private_value;
2332 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2333 unsigned int reg = mc->reg;
2334 unsigned int reg2 = mc->rreg;
2335 unsigned int shift = mc->shift;
2336 unsigned int rshift = mc->rshift;
2338 unsigned int mask = (1 << fls(max)) - 1;
2339 unsigned int invert = mc->invert;
2341 ucontrol->value.integer.value[0] =
2342 (snd_soc_read(codec, reg) >> shift) & mask;
2344 ucontrol->value.integer.value[0] =
2345 max - ucontrol->value.integer.value[0];
2347 if (snd_soc_volsw_is_stereo(mc)) {
2349 ucontrol->value.integer.value[1] =
2350 (snd_soc_read(codec, reg) >> rshift) & mask;
2352 ucontrol->value.integer.value[1] =
2353 (snd_soc_read(codec, reg2) >> shift) & mask;
2355 ucontrol->value.integer.value[1] =
2356 max - ucontrol->value.integer.value[1];
2361 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2364 * snd_soc_put_volsw - single mixer put callback
2365 * @kcontrol: mixer control
2366 * @ucontrol: control element information
2368 * Callback to set the value of a single mixer control, or a double mixer
2369 * control that spans 2 registers.
2371 * Returns 0 for success.
2373 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2374 struct snd_ctl_elem_value *ucontrol)
2376 struct soc_mixer_control *mc =
2377 (struct soc_mixer_control *)kcontrol->private_value;
2378 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2379 unsigned int reg = mc->reg;
2380 unsigned int reg2 = mc->rreg;
2381 unsigned int shift = mc->shift;
2382 unsigned int rshift = mc->rshift;
2384 unsigned int mask = (1 << fls(max)) - 1;
2385 unsigned int invert = mc->invert;
2388 unsigned int val2 = 0;
2389 unsigned int val, val_mask;
2391 val = (ucontrol->value.integer.value[0] & mask);
2394 val_mask = mask << shift;
2396 if (snd_soc_volsw_is_stereo(mc)) {
2397 val2 = (ucontrol->value.integer.value[1] & mask);
2401 val_mask |= mask << rshift;
2402 val |= val2 << rshift;
2404 val2 = val2 << shift;
2408 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2413 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2417 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2420 * snd_soc_info_volsw_s8 - signed mixer info callback
2421 * @kcontrol: mixer control
2422 * @uinfo: control element information
2424 * Callback to provide information about a signed mixer control.
2426 * Returns 0 for success.
2428 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2429 struct snd_ctl_elem_info *uinfo)
2431 struct soc_mixer_control *mc =
2432 (struct soc_mixer_control *)kcontrol->private_value;
2436 if (!mc->platform_max)
2437 mc->platform_max = mc->max;
2438 platform_max = mc->platform_max;
2440 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2442 uinfo->value.integer.min = 0;
2443 uinfo->value.integer.max = platform_max - min;
2446 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2449 * snd_soc_get_volsw_s8 - signed mixer get callback
2450 * @kcontrol: mixer control
2451 * @ucontrol: control element information
2453 * Callback to get the value of a signed mixer control.
2455 * Returns 0 for success.
2457 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2458 struct snd_ctl_elem_value *ucontrol)
2460 struct soc_mixer_control *mc =
2461 (struct soc_mixer_control *)kcontrol->private_value;
2462 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2463 unsigned int reg = mc->reg;
2465 int val = snd_soc_read(codec, reg);
2467 ucontrol->value.integer.value[0] =
2468 ((signed char)(val & 0xff))-min;
2469 ucontrol->value.integer.value[1] =
2470 ((signed char)((val >> 8) & 0xff))-min;
2473 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2476 * snd_soc_put_volsw_sgn - signed mixer put callback
2477 * @kcontrol: mixer control
2478 * @ucontrol: control element information
2480 * Callback to set the value of a signed mixer control.
2482 * Returns 0 for success.
2484 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2485 struct snd_ctl_elem_value *ucontrol)
2487 struct soc_mixer_control *mc =
2488 (struct soc_mixer_control *)kcontrol->private_value;
2489 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2490 unsigned int reg = mc->reg;
2494 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2495 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2497 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2499 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2502 * snd_soc_limit_volume - Set new limit to an existing volume control.
2504 * @codec: where to look for the control
2505 * @name: Name of the control
2506 * @max: new maximum limit
2508 * Return 0 for success, else error.
2510 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2511 const char *name, int max)
2513 struct snd_card *card = codec->card->snd_card;
2514 struct snd_kcontrol *kctl;
2515 struct soc_mixer_control *mc;
2519 /* Sanity check for name and max */
2520 if (unlikely(!name || max <= 0))
2523 list_for_each_entry(kctl, &card->controls, list) {
2524 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2530 mc = (struct soc_mixer_control *)kctl->private_value;
2531 if (max <= mc->max) {
2532 mc->platform_max = max;
2538 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2541 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2542 * mixer info callback
2543 * @kcontrol: mixer control
2544 * @uinfo: control element information
2546 * Returns 0 for success.
2548 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2549 struct snd_ctl_elem_info *uinfo)
2551 struct soc_mixer_control *mc =
2552 (struct soc_mixer_control *)kcontrol->private_value;
2556 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2558 uinfo->value.integer.min = 0;
2559 uinfo->value.integer.max = max-min;
2563 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2566 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2567 * mixer get callback
2568 * @kcontrol: mixer control
2569 * @uinfo: control element information
2571 * Returns 0 for success.
2573 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2574 struct snd_ctl_elem_value *ucontrol)
2576 struct soc_mixer_control *mc =
2577 (struct soc_mixer_control *)kcontrol->private_value;
2578 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2579 unsigned int mask = (1<<mc->shift)-1;
2581 int val = snd_soc_read(codec, mc->reg) & mask;
2582 int valr = snd_soc_read(codec, mc->rreg) & mask;
2584 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2585 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2588 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2591 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2592 * mixer put callback
2593 * @kcontrol: mixer control
2594 * @uinfo: control element information
2596 * Returns 0 for success.
2598 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2599 struct snd_ctl_elem_value *ucontrol)
2601 struct soc_mixer_control *mc =
2602 (struct soc_mixer_control *)kcontrol->private_value;
2603 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2604 unsigned int mask = (1<<mc->shift)-1;
2607 unsigned int val, valr, oval, ovalr;
2609 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2611 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2614 oval = snd_soc_read(codec, mc->reg) & mask;
2615 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2619 ret = snd_soc_write(codec, mc->reg, val);
2623 if (ovalr != valr) {
2624 ret = snd_soc_write(codec, mc->rreg, valr);
2631 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2634 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2636 * @clk_id: DAI specific clock ID
2637 * @freq: new clock frequency in Hz
2638 * @dir: new clock direction - input/output.
2640 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2642 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2643 unsigned int freq, int dir)
2645 if (dai->driver && dai->driver->ops->set_sysclk)
2646 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2647 else if (dai->codec && dai->codec->driver->set_sysclk)
2648 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
2653 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2656 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2658 * @clk_id: DAI specific clock ID
2659 * @source: Source for the clock
2660 * @freq: new clock frequency in Hz
2661 * @dir: new clock direction - input/output.
2663 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2665 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
2666 int source, unsigned int freq, int dir)
2668 if (codec->driver->set_sysclk)
2669 return codec->driver->set_sysclk(codec, clk_id, source,
2674 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2677 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2679 * @div_id: DAI specific clock divider ID
2680 * @div: new clock divisor.
2682 * Configures the clock dividers. This is used to derive the best DAI bit and
2683 * frame clocks from the system or master clock. It's best to set the DAI bit
2684 * and frame clocks as low as possible to save system power.
2686 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2687 int div_id, int div)
2689 if (dai->driver && dai->driver->ops->set_clkdiv)
2690 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2694 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2697 * snd_soc_dai_set_pll - configure DAI PLL.
2699 * @pll_id: DAI specific PLL ID
2700 * @source: DAI specific source for the PLL
2701 * @freq_in: PLL input clock frequency in Hz
2702 * @freq_out: requested PLL output clock frequency in Hz
2704 * Configures and enables PLL to generate output clock based on input clock.
2706 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2707 unsigned int freq_in, unsigned int freq_out)
2709 if (dai->driver && dai->driver->ops->set_pll)
2710 return dai->driver->ops->set_pll(dai, pll_id, source,
2712 else if (dai->codec && dai->codec->driver->set_pll)
2713 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2718 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2721 * snd_soc_codec_set_pll - configure codec PLL.
2723 * @pll_id: DAI specific PLL ID
2724 * @source: DAI specific source for the PLL
2725 * @freq_in: PLL input clock frequency in Hz
2726 * @freq_out: requested PLL output clock frequency in Hz
2728 * Configures and enables PLL to generate output clock based on input clock.
2730 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2731 unsigned int freq_in, unsigned int freq_out)
2733 if (codec->driver->set_pll)
2734 return codec->driver->set_pll(codec, pll_id, source,
2739 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2742 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2744 * @fmt: SND_SOC_DAIFMT_ format value.
2746 * Configures the DAI hardware format and clocking.
2748 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2750 if (dai->driver && dai->driver->ops->set_fmt)
2751 return dai->driver->ops->set_fmt(dai, fmt);
2755 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2758 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2760 * @tx_mask: bitmask representing active TX slots.
2761 * @rx_mask: bitmask representing active RX slots.
2762 * @slots: Number of slots in use.
2763 * @slot_width: Width in bits for each slot.
2765 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2768 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2769 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2771 if (dai->driver && dai->driver->ops->set_tdm_slot)
2772 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2777 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2780 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2782 * @tx_num: how many TX channels
2783 * @tx_slot: pointer to an array which imply the TX slot number channel
2785 * @rx_num: how many RX channels
2786 * @rx_slot: pointer to an array which imply the RX slot number channel
2789 * configure the relationship between channel number and TDM slot number.
2791 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2792 unsigned int tx_num, unsigned int *tx_slot,
2793 unsigned int rx_num, unsigned int *rx_slot)
2795 if (dai->driver && dai->driver->ops->set_channel_map)
2796 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2801 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2804 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2806 * @tristate: tristate enable
2808 * Tristates the DAI so that others can use it.
2810 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2812 if (dai->driver && dai->driver->ops->set_tristate)
2813 return dai->driver->ops->set_tristate(dai, tristate);
2817 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2820 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2822 * @mute: mute enable
2824 * Mutes the DAI DAC.
2826 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2828 if (dai->driver && dai->driver->ops->digital_mute)
2829 return dai->driver->ops->digital_mute(dai, mute);
2833 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2836 * snd_soc_register_card - Register a card with the ASoC core
2838 * @card: Card to register
2841 int snd_soc_register_card(struct snd_soc_card *card)
2845 if (!card->name || !card->dev)
2848 for (i = 0; i < card->num_links; i++) {
2849 struct snd_soc_dai_link *link = &card->dai_link[i];
2852 * Codec must be specified by 1 of name or OF node,
2853 * not both or neither.
2855 if (!!link->codec_name == !!link->codec_of_node) {
2857 "Neither/both codec name/of_node are set\n");
2862 * Platform may be specified by either name or OF node, but
2863 * can be left unspecified, and a dummy platform will be used.
2865 if (link->platform_name && link->platform_of_node) {
2867 "Both platform name/of_node are set\n");
2872 * CPU DAI must be specified by 1 of name or OF node,
2873 * not both or neither.
2875 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2877 "Neither/both cpu_dai name/of_node are set\n");
2882 dev_set_drvdata(card->dev, card);
2884 snd_soc_initialize_card_lists(card);
2886 soc_init_card_debugfs(card);
2888 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2889 (card->num_links + card->num_aux_devs),
2891 if (card->rtd == NULL)
2893 card->rtd_aux = &card->rtd[card->num_links];
2895 for (i = 0; i < card->num_links; i++)
2896 card->rtd[i].dai_link = &card->dai_link[i];
2898 INIT_LIST_HEAD(&card->list);
2899 INIT_LIST_HEAD(&card->dapm_dirty);
2900 card->instantiated = 0;
2901 mutex_init(&card->mutex);
2903 mutex_lock(&client_mutex);
2904 list_add(&card->list, &card_list);
2905 snd_soc_instantiate_cards();
2906 mutex_unlock(&client_mutex);
2908 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2912 EXPORT_SYMBOL_GPL(snd_soc_register_card);
2915 * snd_soc_unregister_card - Unregister a card with the ASoC core
2917 * @card: Card to unregister
2920 int snd_soc_unregister_card(struct snd_soc_card *card)
2922 if (card->instantiated)
2923 soc_cleanup_card_resources(card);
2924 mutex_lock(&client_mutex);
2925 list_del(&card->list);
2926 mutex_unlock(&client_mutex);
2927 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2931 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2934 * Simplify DAI link configuration by removing ".-1" from device names
2935 * and sanitizing names.
2937 static char *fmt_single_name(struct device *dev, int *id)
2939 char *found, name[NAME_SIZE];
2942 if (dev_name(dev) == NULL)
2945 strlcpy(name, dev_name(dev), NAME_SIZE);
2947 /* are we a "%s.%d" name (platform and SPI components) */
2948 found = strstr(name, dev->driver->name);
2951 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2953 /* discard ID from name if ID == -1 */
2955 found[strlen(dev->driver->name)] = '\0';
2959 /* I2C component devices are named "bus-addr" */
2960 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2961 char tmp[NAME_SIZE];
2963 /* create unique ID number from I2C addr and bus */
2964 *id = ((id1 & 0xffff) << 16) + id2;
2966 /* sanitize component name for DAI link creation */
2967 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2968 strlcpy(name, tmp, NAME_SIZE);
2973 return kstrdup(name, GFP_KERNEL);
2977 * Simplify DAI link naming for single devices with multiple DAIs by removing
2978 * any ".-1" and using the DAI name (instead of device name).
2980 static inline char *fmt_multiple_name(struct device *dev,
2981 struct snd_soc_dai_driver *dai_drv)
2983 if (dai_drv->name == NULL) {
2984 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2989 return kstrdup(dai_drv->name, GFP_KERNEL);
2993 * snd_soc_register_dai - Register a DAI with the ASoC core
2995 * @dai: DAI to register
2997 int snd_soc_register_dai(struct device *dev,
2998 struct snd_soc_dai_driver *dai_drv)
3000 struct snd_soc_dai *dai;
3002 dev_dbg(dev, "dai register %s\n", dev_name(dev));
3004 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3008 /* create DAI component name */
3009 dai->name = fmt_single_name(dev, &dai->id);
3010 if (dai->name == NULL) {
3016 dai->driver = dai_drv;
3017 if (!dai->driver->ops)
3018 dai->driver->ops = &null_dai_ops;
3020 mutex_lock(&client_mutex);
3021 list_add(&dai->list, &dai_list);
3022 snd_soc_instantiate_cards();
3023 mutex_unlock(&client_mutex);
3025 pr_debug("Registered DAI '%s'\n", dai->name);
3029 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3032 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3034 * @dai: DAI to unregister
3036 void snd_soc_unregister_dai(struct device *dev)
3038 struct snd_soc_dai *dai;
3040 list_for_each_entry(dai, &dai_list, list) {
3041 if (dev == dai->dev)
3047 mutex_lock(&client_mutex);
3048 list_del(&dai->list);
3049 mutex_unlock(&client_mutex);
3051 pr_debug("Unregistered DAI '%s'\n", dai->name);
3055 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3058 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3060 * @dai: Array of DAIs to register
3061 * @count: Number of DAIs
3063 int snd_soc_register_dais(struct device *dev,
3064 struct snd_soc_dai_driver *dai_drv, size_t count)
3066 struct snd_soc_dai *dai;
3069 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
3071 for (i = 0; i < count; i++) {
3073 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3079 /* create DAI component name */
3080 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3081 if (dai->name == NULL) {
3088 dai->driver = &dai_drv[i];
3089 if (dai->driver->id)
3090 dai->id = dai->driver->id;
3093 if (!dai->driver->ops)
3094 dai->driver->ops = &null_dai_ops;
3096 mutex_lock(&client_mutex);
3097 list_add(&dai->list, &dai_list);
3098 mutex_unlock(&client_mutex);
3100 pr_debug("Registered DAI '%s'\n", dai->name);
3103 mutex_lock(&client_mutex);
3104 snd_soc_instantiate_cards();
3105 mutex_unlock(&client_mutex);
3109 for (i--; i >= 0; i--)
3110 snd_soc_unregister_dai(dev);
3114 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3117 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3119 * @dai: Array of DAIs to unregister
3120 * @count: Number of DAIs
3122 void snd_soc_unregister_dais(struct device *dev, size_t count)
3126 for (i = 0; i < count; i++)
3127 snd_soc_unregister_dai(dev);
3129 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3132 * snd_soc_register_platform - Register a platform with the ASoC core
3134 * @platform: platform to register
3136 int snd_soc_register_platform(struct device *dev,
3137 struct snd_soc_platform_driver *platform_drv)
3139 struct snd_soc_platform *platform;
3141 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3143 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3144 if (platform == NULL)
3147 /* create platform component name */
3148 platform->name = fmt_single_name(dev, &platform->id);
3149 if (platform->name == NULL) {
3154 platform->dev = dev;
3155 platform->driver = platform_drv;
3156 platform->dapm.dev = dev;
3157 platform->dapm.platform = platform;
3158 platform->dapm.stream_event = platform_drv->stream_event;
3160 mutex_lock(&client_mutex);
3161 list_add(&platform->list, &platform_list);
3162 snd_soc_instantiate_cards();
3163 mutex_unlock(&client_mutex);
3165 pr_debug("Registered platform '%s'\n", platform->name);
3169 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3172 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3174 * @platform: platform to unregister
3176 void snd_soc_unregister_platform(struct device *dev)
3178 struct snd_soc_platform *platform;
3180 list_for_each_entry(platform, &platform_list, list) {
3181 if (dev == platform->dev)
3187 mutex_lock(&client_mutex);
3188 list_del(&platform->list);
3189 mutex_unlock(&client_mutex);
3191 pr_debug("Unregistered platform '%s'\n", platform->name);
3192 kfree(platform->name);
3195 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3197 static u64 codec_format_map[] = {
3198 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3199 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3200 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3201 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3202 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3203 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3204 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3205 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3206 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3207 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3208 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3209 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3210 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3211 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3212 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3213 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3216 /* Fix up the DAI formats for endianness: codecs don't actually see
3217 * the endianness of the data but we're using the CPU format
3218 * definitions which do need to include endianness so we ensure that
3219 * codec DAIs always have both big and little endian variants set.
3221 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3225 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3226 if (stream->formats & codec_format_map[i])
3227 stream->formats |= codec_format_map[i];
3231 * snd_soc_register_codec - Register a codec with the ASoC core
3233 * @codec: codec to register
3235 int snd_soc_register_codec(struct device *dev,
3236 const struct snd_soc_codec_driver *codec_drv,
3237 struct snd_soc_dai_driver *dai_drv,
3241 struct snd_soc_codec *codec;
3244 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3246 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3250 /* create CODEC component name */
3251 codec->name = fmt_single_name(dev, &codec->id);
3252 if (codec->name == NULL) {
3257 if (codec_drv->compress_type)
3258 codec->compress_type = codec_drv->compress_type;
3260 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3262 codec->write = codec_drv->write;
3263 codec->read = codec_drv->read;
3264 codec->volatile_register = codec_drv->volatile_register;
3265 codec->readable_register = codec_drv->readable_register;
3266 codec->writable_register = codec_drv->writable_register;
3267 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3268 codec->dapm.dev = dev;
3269 codec->dapm.codec = codec;
3270 codec->dapm.seq_notifier = codec_drv->seq_notifier;
3271 codec->dapm.stream_event = codec_drv->stream_event;
3273 codec->driver = codec_drv;
3274 codec->num_dai = num_dai;
3275 mutex_init(&codec->mutex);
3277 /* allocate CODEC register cache */
3278 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3279 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
3280 codec->reg_size = reg_size;
3281 /* it is necessary to make a copy of the default register cache
3282 * because in the case of using a compression type that requires
3283 * the default register cache to be marked as __devinitconst the
3284 * kernel might have freed the array by the time we initialize
3287 if (codec_drv->reg_cache_default) {
3288 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3289 reg_size, GFP_KERNEL);
3290 if (!codec->reg_def_copy) {
3297 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3298 if (!codec->volatile_register)
3299 codec->volatile_register = snd_soc_default_volatile_register;
3300 if (!codec->readable_register)
3301 codec->readable_register = snd_soc_default_readable_register;
3302 if (!codec->writable_register)
3303 codec->writable_register = snd_soc_default_writable_register;
3306 for (i = 0; i < num_dai; i++) {
3307 fixup_codec_formats(&dai_drv[i].playback);
3308 fixup_codec_formats(&dai_drv[i].capture);
3311 /* register any DAIs */
3313 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3318 mutex_lock(&client_mutex);
3319 list_add(&codec->list, &codec_list);
3320 snd_soc_instantiate_cards();
3321 mutex_unlock(&client_mutex);
3323 pr_debug("Registered codec '%s'\n", codec->name);
3327 kfree(codec->reg_def_copy);
3328 codec->reg_def_copy = NULL;
3333 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3336 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3338 * @codec: codec to unregister
3340 void snd_soc_unregister_codec(struct device *dev)
3342 struct snd_soc_codec *codec;
3345 list_for_each_entry(codec, &codec_list, list) {
3346 if (dev == codec->dev)
3353 for (i = 0; i < codec->num_dai; i++)
3354 snd_soc_unregister_dai(dev);
3356 mutex_lock(&client_mutex);
3357 list_del(&codec->list);
3358 mutex_unlock(&client_mutex);
3360 pr_debug("Unregistered codec '%s'\n", codec->name);
3362 snd_soc_cache_exit(codec);
3363 kfree(codec->reg_def_copy);
3367 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3369 /* Retrieve a card's name from device tree */
3370 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3371 const char *propname)
3373 struct device_node *np = card->dev->of_node;
3376 ret = of_property_read_string_index(np, propname, 0, &card->name);
3378 * EINVAL means the property does not exist. This is fine providing
3379 * card->name was previously set, which is checked later in
3380 * snd_soc_register_card.
3382 if (ret < 0 && ret != -EINVAL) {
3384 "Property '%s' could not be read: %d\n",
3391 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3393 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3394 const char *propname)
3396 struct device_node *np = card->dev->of_node;
3398 struct snd_soc_dapm_route *routes;
3401 num_routes = of_property_count_strings(np, propname);
3402 if (num_routes & 1) {
3404 "Property '%s's length is not even\n",
3411 "Property '%s's length is zero\n",
3416 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3420 "Could not allocate DAPM route table\n");
3424 for (i = 0; i < num_routes; i++) {
3425 ret = of_property_read_string_index(np, propname,
3426 2 * i, &routes[i].sink);
3429 "Property '%s' index %d could not be read: %d\n",
3430 propname, 2 * i, ret);
3433 ret = of_property_read_string_index(np, propname,
3434 (2 * i) + 1, &routes[i].source);
3437 "Property '%s' index %d could not be read: %d\n",
3438 propname, (2 * i) + 1, ret);
3443 card->num_dapm_routes = num_routes;
3444 card->dapm_routes = routes;
3448 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3450 static int __init snd_soc_init(void)
3452 #ifdef CONFIG_DEBUG_FS
3453 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3454 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
3456 "ASoC: Failed to create debugfs directory\n");
3457 snd_soc_debugfs_root = NULL;
3460 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
3462 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3464 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
3466 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3468 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
3469 &platform_list_fops))
3470 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3473 snd_soc_util_init();
3475 return platform_driver_register(&soc_driver);
3477 module_init(snd_soc_init);
3479 static void __exit snd_soc_exit(void)
3481 snd_soc_util_exit();
3483 #ifdef CONFIG_DEBUG_FS
3484 debugfs_remove_recursive(snd_soc_debugfs_root);
3486 platform_driver_unregister(&soc_driver);
3488 module_exit(snd_soc_exit);
3490 /* Module information */
3491 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3492 MODULE_DESCRIPTION("ALSA SoC Core");
3493 MODULE_LICENSE("GPL");
3494 MODULE_ALIAS("platform:soc-audio");