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/soc-dpcm.h>
43 #include <sound/initval.h>
45 #define CREATE_TRACE_POINTS
46 #include <trace/events/asoc.h>
50 #ifdef CONFIG_DEBUG_FS
51 struct dentry *snd_soc_debugfs_root;
52 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
55 static DEFINE_MUTEX(client_mutex);
56 static LIST_HEAD(dai_list);
57 static LIST_HEAD(platform_list);
58 static LIST_HEAD(codec_list);
59 static LIST_HEAD(component_list);
62 * This is a timeout to do a DAPM powerdown after a stream is closed().
63 * It can be used to eliminate pops between different playback streams, e.g.
64 * between two audio tracks.
66 static int pmdown_time = 5000;
67 module_param(pmdown_time, int, 0);
68 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
70 /* returns the minimum number of bytes needed to represent
71 * a particular given value */
72 static int min_bytes_needed(unsigned long val)
77 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
80 c = (sizeof val * 8) - c;
88 /* fill buf which is 'len' bytes with a formatted
89 * string of the form 'reg: value\n' */
90 static int format_register_str(struct snd_soc_codec *codec,
91 unsigned int reg, char *buf, size_t len)
93 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
94 int regsize = codec->driver->reg_word_size * 2;
97 char regbuf[regsize + 1];
99 /* since tmpbuf is allocated on the stack, warn the callers if they
100 * try to abuse this function */
103 /* +2 for ': ' and + 1 for '\n' */
104 if (wordsize + regsize + 2 + 1 != len)
107 ret = snd_soc_read(codec, reg);
109 memset(regbuf, 'X', regsize);
110 regbuf[regsize] = '\0';
112 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
115 /* prepare the buffer */
116 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
117 /* copy it back to the caller without the '\0' */
118 memcpy(buf, tmpbuf, len);
123 /* codec register dump */
124 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
125 size_t count, loff_t pos)
128 int wordsize, regsize;
133 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
134 regsize = codec->driver->reg_word_size * 2;
136 len = wordsize + regsize + 2 + 1;
138 if (!codec->driver->reg_cache_size)
141 if (codec->driver->reg_cache_step)
142 step = codec->driver->reg_cache_step;
144 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
145 if (!snd_soc_codec_readable_register(codec, i))
147 if (codec->driver->display_register) {
148 count += codec->driver->display_register(codec, buf + count,
149 PAGE_SIZE - count, i);
151 /* only support larger than PAGE_SIZE bytes debugfs
152 * entries for the default case */
154 if (total + len >= count - 1)
156 format_register_str(codec, i, buf + total, len);
163 total = min(total, count - 1);
168 static ssize_t codec_reg_show(struct device *dev,
169 struct device_attribute *attr, char *buf)
171 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
173 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
176 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
178 static ssize_t pmdown_time_show(struct device *dev,
179 struct device_attribute *attr, char *buf)
181 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
183 return sprintf(buf, "%ld\n", rtd->pmdown_time);
186 static ssize_t pmdown_time_set(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
190 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
193 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
200 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
202 #ifdef CONFIG_DEBUG_FS
203 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
204 size_t count, loff_t *ppos)
207 struct snd_soc_codec *codec = file->private_data;
210 if (*ppos < 0 || !count)
213 buf = kmalloc(count, GFP_KERNEL);
217 ret = soc_codec_reg_show(codec, buf, count, *ppos);
219 if (copy_to_user(user_buf, buf, ret)) {
230 static ssize_t codec_reg_write_file(struct file *file,
231 const char __user *user_buf, size_t count, loff_t *ppos)
236 unsigned long reg, value;
237 struct snd_soc_codec *codec = file->private_data;
239 buf_size = min(count, (sizeof(buf)-1));
240 if (copy_from_user(buf, user_buf, buf_size))
244 while (*start == ' ')
246 reg = simple_strtoul(start, &start, 16);
247 while (*start == ' ')
249 if (strict_strtoul(start, 16, &value))
252 /* Userspace has been fiddling around behind the kernel's back */
253 add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
255 snd_soc_write(codec, reg, value);
259 static const struct file_operations codec_reg_fops = {
261 .read = codec_reg_read_file,
262 .write = codec_reg_write_file,
263 .llseek = default_llseek,
266 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
268 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
270 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
272 if (!codec->debugfs_codec_root) {
274 "ASoC: Failed to create codec debugfs directory\n");
278 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
280 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
283 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
284 codec->debugfs_codec_root,
285 codec, &codec_reg_fops);
286 if (!codec->debugfs_reg)
288 "ASoC: Failed to create codec register debugfs file\n");
290 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
293 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
295 debugfs_remove_recursive(codec->debugfs_codec_root);
298 static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
300 struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
302 platform->debugfs_platform_root = debugfs_create_dir(platform->name,
304 if (!platform->debugfs_platform_root) {
305 dev_warn(platform->dev,
306 "ASoC: Failed to create platform debugfs directory\n");
310 snd_soc_dapm_debugfs_init(&platform->dapm,
311 platform->debugfs_platform_root);
314 static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
316 debugfs_remove_recursive(platform->debugfs_platform_root);
319 static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
320 size_t count, loff_t *ppos)
322 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
323 ssize_t len, ret = 0;
324 struct snd_soc_codec *codec;
329 list_for_each_entry(codec, &codec_list, list) {
330 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
334 if (ret > PAGE_SIZE) {
341 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
348 static const struct file_operations codec_list_fops = {
349 .read = codec_list_read_file,
350 .llseek = default_llseek,/* read accesses f_pos */
353 static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
354 size_t count, loff_t *ppos)
356 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
357 ssize_t len, ret = 0;
358 struct snd_soc_dai *dai;
363 list_for_each_entry(dai, &dai_list, list) {
364 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
367 if (ret > PAGE_SIZE) {
373 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
380 static const struct file_operations dai_list_fops = {
381 .read = dai_list_read_file,
382 .llseek = default_llseek,/* read accesses f_pos */
385 static ssize_t platform_list_read_file(struct file *file,
386 char __user *user_buf,
387 size_t count, loff_t *ppos)
389 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
390 ssize_t len, ret = 0;
391 struct snd_soc_platform *platform;
396 list_for_each_entry(platform, &platform_list, list) {
397 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
401 if (ret > PAGE_SIZE) {
407 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
414 static const struct file_operations platform_list_fops = {
415 .read = platform_list_read_file,
416 .llseek = default_llseek,/* read accesses f_pos */
419 static void soc_init_card_debugfs(struct snd_soc_card *card)
421 card->debugfs_card_root = debugfs_create_dir(card->name,
422 snd_soc_debugfs_root);
423 if (!card->debugfs_card_root) {
425 "ASoC: Failed to create card debugfs directory\n");
429 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
430 card->debugfs_card_root,
432 if (!card->debugfs_pop_time)
434 "ASoC: Failed to create pop time debugfs file\n");
437 static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
439 debugfs_remove_recursive(card->debugfs_card_root);
444 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
448 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
452 static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
456 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
460 static inline void soc_init_card_debugfs(struct snd_soc_card *card)
464 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
469 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
470 const char *dai_link, int stream)
474 for (i = 0; i < card->num_links; i++) {
475 if (card->rtd[i].dai_link->no_pcm &&
476 !strcmp(card->rtd[i].dai_link->name, dai_link))
477 return card->rtd[i].pcm->streams[stream].substream;
479 dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
482 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
484 struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
485 const char *dai_link)
489 for (i = 0; i < card->num_links; i++) {
490 if (!strcmp(card->rtd[i].dai_link->name, dai_link))
491 return &card->rtd[i];
493 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
496 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
498 #ifdef CONFIG_SND_SOC_AC97_BUS
499 /* unregister ac97 codec */
500 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
502 if (codec->ac97->dev.bus)
503 device_unregister(&codec->ac97->dev);
507 /* stop no dev release warning */
508 static void soc_ac97_device_release(struct device *dev){}
510 /* register ac97 codec to bus */
511 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
515 codec->ac97->dev.bus = &ac97_bus_type;
516 codec->ac97->dev.parent = codec->card->dev;
517 codec->ac97->dev.release = soc_ac97_device_release;
519 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
520 codec->card->snd_card->number, 0, codec->name);
521 err = device_register(&codec->ac97->dev);
523 dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
524 codec->ac97->dev.bus = NULL;
531 static void codec2codec_close_delayed_work(struct work_struct *work)
533 /* Currently nothing to do for c2c links
534 * Since c2c links are internal nodes in the DAPM graph and
535 * don't interface with the outside world or application layer
536 * we don't have to do any special handling on close.
540 #ifdef CONFIG_PM_SLEEP
541 /* powers down audio subsystem for suspend */
542 int snd_soc_suspend(struct device *dev)
544 struct snd_soc_card *card = dev_get_drvdata(dev);
545 struct snd_soc_codec *codec;
548 /* If the initialization of this soc device failed, there is no codec
549 * associated with it. Just bail out in this case.
551 if (list_empty(&card->codec_dev_list))
554 /* Due to the resume being scheduled into a workqueue we could
555 * suspend before that's finished - wait for it to complete.
557 snd_power_lock(card->snd_card);
558 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
559 snd_power_unlock(card->snd_card);
561 /* we're going to block userspace touching us until resume completes */
562 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
564 /* mute any active DACs */
565 for (i = 0; i < card->num_rtd; i++) {
566 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
567 struct snd_soc_dai_driver *drv = dai->driver;
569 if (card->rtd[i].dai_link->ignore_suspend)
572 if (drv->ops->digital_mute && dai->playback_active)
573 drv->ops->digital_mute(dai, 1);
576 /* suspend all pcms */
577 for (i = 0; i < card->num_rtd; i++) {
578 if (card->rtd[i].dai_link->ignore_suspend)
581 snd_pcm_suspend_all(card->rtd[i].pcm);
584 if (card->suspend_pre)
585 card->suspend_pre(card);
587 for (i = 0; i < card->num_rtd; i++) {
588 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
589 struct snd_soc_platform *platform = card->rtd[i].platform;
591 if (card->rtd[i].dai_link->ignore_suspend)
594 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
595 cpu_dai->driver->suspend(cpu_dai);
596 if (platform->driver->suspend && !platform->suspended) {
597 platform->driver->suspend(cpu_dai);
598 platform->suspended = 1;
602 /* close any waiting streams and save state */
603 for (i = 0; i < card->num_rtd; i++) {
604 flush_delayed_work(&card->rtd[i].delayed_work);
605 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
608 for (i = 0; i < card->num_rtd; i++) {
610 if (card->rtd[i].dai_link->ignore_suspend)
613 snd_soc_dapm_stream_event(&card->rtd[i],
614 SNDRV_PCM_STREAM_PLAYBACK,
615 SND_SOC_DAPM_STREAM_SUSPEND);
617 snd_soc_dapm_stream_event(&card->rtd[i],
618 SNDRV_PCM_STREAM_CAPTURE,
619 SND_SOC_DAPM_STREAM_SUSPEND);
622 /* Recheck all analogue paths too */
623 dapm_mark_io_dirty(&card->dapm);
624 snd_soc_dapm_sync(&card->dapm);
626 /* suspend all CODECs */
627 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
628 /* If there are paths active then the CODEC will be held with
629 * bias _ON and should not be suspended. */
630 if (!codec->suspended && codec->driver->suspend) {
631 switch (codec->dapm.bias_level) {
632 case SND_SOC_BIAS_STANDBY:
634 * If the CODEC is capable of idle
635 * bias off then being in STANDBY
636 * means it's doing something,
637 * otherwise fall through.
639 if (codec->dapm.idle_bias_off) {
641 "ASoC: idle_bias_off CODEC on over suspend\n");
644 case SND_SOC_BIAS_OFF:
645 codec->driver->suspend(codec);
646 codec->suspended = 1;
647 codec->cache_sync = 1;
648 if (codec->using_regmap)
649 regcache_mark_dirty(codec->control_data);
653 "ASoC: CODEC is on over suspend\n");
659 for (i = 0; i < card->num_rtd; i++) {
660 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
662 if (card->rtd[i].dai_link->ignore_suspend)
665 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
666 cpu_dai->driver->suspend(cpu_dai);
669 if (card->suspend_post)
670 card->suspend_post(card);
674 EXPORT_SYMBOL_GPL(snd_soc_suspend);
676 /* deferred resume work, so resume can complete before we finished
677 * setting our codec back up, which can be very slow on I2C
679 static void soc_resume_deferred(struct work_struct *work)
681 struct snd_soc_card *card =
682 container_of(work, struct snd_soc_card, deferred_resume_work);
683 struct snd_soc_codec *codec;
686 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
687 * so userspace apps are blocked from touching us
690 dev_dbg(card->dev, "ASoC: starting resume work\n");
692 /* Bring us up into D2 so that DAPM starts enabling things */
693 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
695 if (card->resume_pre)
696 card->resume_pre(card);
698 /* resume AC97 DAIs */
699 for (i = 0; i < card->num_rtd; i++) {
700 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
702 if (card->rtd[i].dai_link->ignore_suspend)
705 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
706 cpu_dai->driver->resume(cpu_dai);
709 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
710 /* If the CODEC was idle over suspend then it will have been
711 * left with bias OFF or STANDBY and suspended so we must now
712 * resume. Otherwise the suspend was suppressed.
714 if (codec->driver->resume && codec->suspended) {
715 switch (codec->dapm.bias_level) {
716 case SND_SOC_BIAS_STANDBY:
717 case SND_SOC_BIAS_OFF:
718 codec->driver->resume(codec);
719 codec->suspended = 0;
723 "ASoC: CODEC was on over suspend\n");
729 for (i = 0; i < card->num_rtd; i++) {
731 if (card->rtd[i].dai_link->ignore_suspend)
734 snd_soc_dapm_stream_event(&card->rtd[i],
735 SNDRV_PCM_STREAM_PLAYBACK,
736 SND_SOC_DAPM_STREAM_RESUME);
738 snd_soc_dapm_stream_event(&card->rtd[i],
739 SNDRV_PCM_STREAM_CAPTURE,
740 SND_SOC_DAPM_STREAM_RESUME);
743 /* unmute any active DACs */
744 for (i = 0; i < card->num_rtd; i++) {
745 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
746 struct snd_soc_dai_driver *drv = dai->driver;
748 if (card->rtd[i].dai_link->ignore_suspend)
751 if (drv->ops->digital_mute && dai->playback_active)
752 drv->ops->digital_mute(dai, 0);
755 for (i = 0; i < card->num_rtd; i++) {
756 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
757 struct snd_soc_platform *platform = card->rtd[i].platform;
759 if (card->rtd[i].dai_link->ignore_suspend)
762 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
763 cpu_dai->driver->resume(cpu_dai);
764 if (platform->driver->resume && platform->suspended) {
765 platform->driver->resume(cpu_dai);
766 platform->suspended = 0;
770 if (card->resume_post)
771 card->resume_post(card);
773 dev_dbg(card->dev, "ASoC: resume work completed\n");
775 /* userspace can access us now we are back as we were before */
776 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
778 /* Recheck all analogue paths too */
779 dapm_mark_io_dirty(&card->dapm);
780 snd_soc_dapm_sync(&card->dapm);
783 /* powers up audio subsystem after a suspend */
784 int snd_soc_resume(struct device *dev)
786 struct snd_soc_card *card = dev_get_drvdata(dev);
787 int i, ac97_control = 0;
789 /* If the initialization of this soc device failed, there is no codec
790 * associated with it. Just bail out in this case.
792 if (list_empty(&card->codec_dev_list))
795 /* AC97 devices might have other drivers hanging off them so
796 * need to resume immediately. Other drivers don't have that
797 * problem and may take a substantial amount of time to resume
798 * due to I/O costs and anti-pop so handle them out of line.
800 for (i = 0; i < card->num_rtd; i++) {
801 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
802 ac97_control |= cpu_dai->driver->ac97_control;
805 dev_dbg(dev, "ASoC: Resuming AC97 immediately\n");
806 soc_resume_deferred(&card->deferred_resume_work);
808 dev_dbg(dev, "ASoC: Scheduling resume work\n");
809 if (!schedule_work(&card->deferred_resume_work))
810 dev_err(dev, "ASoC: resume work item may be lost\n");
815 EXPORT_SYMBOL_GPL(snd_soc_resume);
817 #define snd_soc_suspend NULL
818 #define snd_soc_resume NULL
821 static const struct snd_soc_dai_ops null_dai_ops = {
824 static int soc_bind_dai_link(struct snd_soc_card *card, int num)
826 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
827 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
828 struct snd_soc_codec *codec;
829 struct snd_soc_platform *platform;
830 struct snd_soc_dai *codec_dai, *cpu_dai;
831 const char *platform_name;
833 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
835 /* Find CPU DAI from registered DAIs*/
836 list_for_each_entry(cpu_dai, &dai_list, list) {
837 if (dai_link->cpu_of_node &&
838 (cpu_dai->dev->of_node != dai_link->cpu_of_node))
840 if (dai_link->cpu_name &&
841 strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name))
843 if (dai_link->cpu_dai_name &&
844 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
847 rtd->cpu_dai = cpu_dai;
851 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
852 dai_link->cpu_dai_name);
853 return -EPROBE_DEFER;
856 /* Find CODEC from registered CODECs */
857 list_for_each_entry(codec, &codec_list, list) {
858 if (dai_link->codec_of_node) {
859 if (codec->dev->of_node != dai_link->codec_of_node)
862 if (strcmp(codec->name, dai_link->codec_name))
869 * CODEC found, so find CODEC DAI from registered DAIs from
872 list_for_each_entry(codec_dai, &dai_list, list) {
873 if (codec->dev == codec_dai->dev &&
874 !strcmp(codec_dai->name,
875 dai_link->codec_dai_name)) {
877 rtd->codec_dai = codec_dai;
881 if (!rtd->codec_dai) {
882 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
883 dai_link->codec_dai_name);
884 return -EPROBE_DEFER;
889 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
890 dai_link->codec_name);
891 return -EPROBE_DEFER;
894 /* if there's no platform we match on the empty platform */
895 platform_name = dai_link->platform_name;
896 if (!platform_name && !dai_link->platform_of_node)
897 platform_name = "snd-soc-dummy";
899 /* find one from the set of registered platforms */
900 list_for_each_entry(platform, &platform_list, list) {
901 if (dai_link->platform_of_node) {
902 if (platform->dev->of_node !=
903 dai_link->platform_of_node)
906 if (strcmp(platform->name, platform_name))
910 rtd->platform = platform;
912 if (!rtd->platform) {
913 dev_err(card->dev, "ASoC: platform %s not registered\n",
914 dai_link->platform_name);
915 return -EPROBE_DEFER;
923 static int soc_remove_platform(struct snd_soc_platform *platform)
927 if (platform->driver->remove) {
928 ret = platform->driver->remove(platform);
930 dev_err(platform->dev, "ASoC: failed to remove %d\n",
934 /* Make sure all DAPM widgets are freed */
935 snd_soc_dapm_free(&platform->dapm);
937 soc_cleanup_platform_debugfs(platform);
938 platform->probed = 0;
939 list_del(&platform->card_list);
940 module_put(platform->dev->driver->owner);
945 static void soc_remove_codec(struct snd_soc_codec *codec)
949 if (codec->driver->remove) {
950 err = codec->driver->remove(codec);
952 dev_err(codec->dev, "ASoC: failed to remove %d\n", err);
955 /* Make sure all DAPM widgets are freed */
956 snd_soc_dapm_free(&codec->dapm);
958 soc_cleanup_codec_debugfs(codec);
960 list_del(&codec->card_list);
961 module_put(codec->dev->driver->owner);
964 static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
966 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
967 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
970 /* unregister the rtd device */
971 if (rtd->dev_registered) {
972 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
973 device_remove_file(rtd->dev, &dev_attr_codec_reg);
974 device_unregister(rtd->dev);
975 rtd->dev_registered = 0;
978 /* remove the CODEC DAI */
979 if (codec_dai && codec_dai->probed &&
980 codec_dai->driver->remove_order == order) {
981 if (codec_dai->driver->remove) {
982 err = codec_dai->driver->remove(codec_dai);
984 dev_err(codec_dai->dev,
985 "ASoC: failed to remove %s: %d\n",
986 codec_dai->name, err);
988 codec_dai->probed = 0;
989 list_del(&codec_dai->card_list);
992 /* remove the cpu_dai */
993 if (cpu_dai && cpu_dai->probed &&
994 cpu_dai->driver->remove_order == order) {
995 if (cpu_dai->driver->remove) {
996 err = cpu_dai->driver->remove(cpu_dai);
998 dev_err(cpu_dai->dev,
999 "ASoC: failed to remove %s: %d\n",
1000 cpu_dai->name, err);
1002 cpu_dai->probed = 0;
1003 list_del(&cpu_dai->card_list);
1005 if (!cpu_dai->codec) {
1006 snd_soc_dapm_free(&cpu_dai->dapm);
1007 module_put(cpu_dai->dev->driver->owner);
1012 static void soc_remove_link_components(struct snd_soc_card *card, int num,
1015 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1016 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1017 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1018 struct snd_soc_platform *platform = rtd->platform;
1019 struct snd_soc_codec *codec;
1021 /* remove the platform */
1022 if (platform && platform->probed &&
1023 platform->driver->remove_order == order) {
1024 soc_remove_platform(platform);
1027 /* remove the CODEC-side CODEC */
1029 codec = codec_dai->codec;
1030 if (codec && codec->probed &&
1031 codec->driver->remove_order == order)
1032 soc_remove_codec(codec);
1035 /* remove any CPU-side CODEC */
1037 codec = cpu_dai->codec;
1038 if (codec && codec->probed &&
1039 codec->driver->remove_order == order)
1040 soc_remove_codec(codec);
1044 static void soc_remove_dai_links(struct snd_soc_card *card)
1048 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1050 for (dai = 0; dai < card->num_rtd; dai++)
1051 soc_remove_link_dais(card, dai, order);
1054 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1056 for (dai = 0; dai < card->num_rtd; dai++)
1057 soc_remove_link_components(card, dai, order);
1063 static void soc_set_name_prefix(struct snd_soc_card *card,
1064 struct snd_soc_codec *codec)
1068 if (card->codec_conf == NULL)
1071 for (i = 0; i < card->num_configs; i++) {
1072 struct snd_soc_codec_conf *map = &card->codec_conf[i];
1073 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1074 codec->name_prefix = map->name_prefix;
1080 static int soc_probe_codec(struct snd_soc_card *card,
1081 struct snd_soc_codec *codec)
1084 const struct snd_soc_codec_driver *driver = codec->driver;
1085 struct snd_soc_dai *dai;
1088 codec->dapm.card = card;
1089 soc_set_name_prefix(card, codec);
1091 if (!try_module_get(codec->dev->driver->owner))
1094 soc_init_codec_debugfs(codec);
1096 if (driver->dapm_widgets)
1097 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
1098 driver->num_dapm_widgets);
1100 /* Create DAPM widgets for each DAI stream */
1101 list_for_each_entry(dai, &dai_list, list) {
1102 if (dai->dev != codec->dev)
1105 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
1108 codec->dapm.idle_bias_off = driver->idle_bias_off;
1110 if (driver->probe) {
1111 ret = driver->probe(codec);
1114 "ASoC: failed to probe CODEC %d\n", ret);
1117 WARN(codec->dapm.idle_bias_off &&
1118 codec->dapm.bias_level != SND_SOC_BIAS_OFF,
1119 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1123 /* If the driver didn't set I/O up try regmap */
1124 if (!codec->write && dev_get_regmap(codec->dev, NULL))
1125 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1127 if (driver->controls)
1128 snd_soc_add_codec_controls(codec, driver->controls,
1129 driver->num_controls);
1130 if (driver->dapm_routes)
1131 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1132 driver->num_dapm_routes);
1134 /* mark codec as probed and add to card codec list */
1136 list_add(&codec->card_list, &card->codec_dev_list);
1137 list_add(&codec->dapm.list, &card->dapm_list);
1142 soc_cleanup_codec_debugfs(codec);
1143 module_put(codec->dev->driver->owner);
1148 static int soc_probe_platform(struct snd_soc_card *card,
1149 struct snd_soc_platform *platform)
1152 const struct snd_soc_platform_driver *driver = platform->driver;
1153 struct snd_soc_dai *dai;
1155 platform->card = card;
1156 platform->dapm.card = card;
1158 if (!try_module_get(platform->dev->driver->owner))
1161 soc_init_platform_debugfs(platform);
1163 if (driver->dapm_widgets)
1164 snd_soc_dapm_new_controls(&platform->dapm,
1165 driver->dapm_widgets, driver->num_dapm_widgets);
1167 /* Create DAPM widgets for each DAI stream */
1168 list_for_each_entry(dai, &dai_list, list) {
1169 if (dai->dev != platform->dev)
1172 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
1175 platform->dapm.idle_bias_off = 1;
1177 if (driver->probe) {
1178 ret = driver->probe(platform);
1180 dev_err(platform->dev,
1181 "ASoC: failed to probe platform %d\n", ret);
1186 if (driver->controls)
1187 snd_soc_add_platform_controls(platform, driver->controls,
1188 driver->num_controls);
1189 if (driver->dapm_routes)
1190 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1191 driver->num_dapm_routes);
1193 /* mark platform as probed and add to card platform list */
1194 platform->probed = 1;
1195 list_add(&platform->card_list, &card->platform_dev_list);
1196 list_add(&platform->dapm.list, &card->dapm_list);
1201 soc_cleanup_platform_debugfs(platform);
1202 module_put(platform->dev->driver->owner);
1207 static void rtd_release(struct device *dev)
1212 static int soc_post_component_init(struct snd_soc_card *card,
1213 struct snd_soc_codec *codec,
1214 int num, int dailess)
1216 struct snd_soc_dai_link *dai_link = NULL;
1217 struct snd_soc_aux_dev *aux_dev = NULL;
1218 struct snd_soc_pcm_runtime *rtd;
1219 const char *temp, *name;
1223 dai_link = &card->dai_link[num];
1224 rtd = &card->rtd[num];
1225 name = dai_link->name;
1227 aux_dev = &card->aux_dev[num];
1228 rtd = &card->rtd_aux[num];
1229 name = aux_dev->name;
1233 /* machine controls, routes and widgets are not prefixed */
1234 temp = codec->name_prefix;
1235 codec->name_prefix = NULL;
1237 /* do machine specific initialization */
1238 if (!dailess && dai_link->init)
1239 ret = dai_link->init(rtd);
1240 else if (dailess && aux_dev->init)
1241 ret = aux_dev->init(&codec->dapm);
1243 dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
1246 codec->name_prefix = temp;
1248 /* register the rtd device */
1251 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1254 device_initialize(rtd->dev);
1255 rtd->dev->parent = card->dev;
1256 rtd->dev->release = rtd_release;
1257 rtd->dev->init_name = name;
1258 dev_set_drvdata(rtd->dev, rtd);
1259 mutex_init(&rtd->pcm_mutex);
1260 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1261 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1262 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1263 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
1264 ret = device_add(rtd->dev);
1266 /* calling put_device() here to free the rtd->dev */
1267 put_device(rtd->dev);
1269 "ASoC: failed to register runtime device: %d\n", ret);
1272 rtd->dev_registered = 1;
1274 /* add DAPM sysfs entries for this codec */
1275 ret = snd_soc_dapm_sys_add(rtd->dev);
1278 "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
1280 /* add codec sysfs entries */
1281 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
1284 "ASoC: failed to add codec sysfs files: %d\n", ret);
1286 #ifdef CONFIG_DEBUG_FS
1287 /* add DPCM sysfs entries */
1288 if (!dailess && !dai_link->dynamic)
1291 ret = soc_dpcm_debugfs_add(rtd);
1293 dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
1300 static int soc_probe_link_components(struct snd_soc_card *card, int num,
1303 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1304 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1305 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1306 struct snd_soc_platform *platform = rtd->platform;
1309 /* probe the CPU-side component, if it is a CODEC */
1310 if (cpu_dai->codec &&
1311 !cpu_dai->codec->probed &&
1312 cpu_dai->codec->driver->probe_order == order) {
1313 ret = soc_probe_codec(card, cpu_dai->codec);
1318 /* probe the CODEC-side component */
1319 if (!codec_dai->codec->probed &&
1320 codec_dai->codec->driver->probe_order == order) {
1321 ret = soc_probe_codec(card, codec_dai->codec);
1326 /* probe the platform */
1327 if (!platform->probed &&
1328 platform->driver->probe_order == order) {
1329 ret = soc_probe_platform(card, platform);
1337 static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1339 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1340 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1341 struct snd_soc_codec *codec = rtd->codec;
1342 struct snd_soc_platform *platform = rtd->platform;
1343 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1344 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1345 struct snd_soc_dapm_widget *play_w, *capture_w;
1348 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
1349 card->name, num, order);
1351 /* config components */
1352 cpu_dai->platform = platform;
1353 codec_dai->card = card;
1354 cpu_dai->card = card;
1356 /* set default power off timeout */
1357 rtd->pmdown_time = pmdown_time;
1359 /* probe the cpu_dai */
1360 if (!cpu_dai->probed &&
1361 cpu_dai->driver->probe_order == order) {
1362 if (!cpu_dai->codec) {
1363 cpu_dai->dapm.card = card;
1364 if (!try_module_get(cpu_dai->dev->driver->owner))
1367 list_add(&cpu_dai->dapm.list, &card->dapm_list);
1368 snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
1371 if (cpu_dai->driver->probe) {
1372 ret = cpu_dai->driver->probe(cpu_dai);
1374 dev_err(cpu_dai->dev,
1375 "ASoC: failed to probe CPU DAI %s: %d\n",
1376 cpu_dai->name, ret);
1377 module_put(cpu_dai->dev->driver->owner);
1381 cpu_dai->probed = 1;
1382 /* mark cpu_dai as probed and add to card dai list */
1383 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1386 /* probe the CODEC DAI */
1387 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1388 if (codec_dai->driver->probe) {
1389 ret = codec_dai->driver->probe(codec_dai);
1391 dev_err(codec_dai->dev,
1392 "ASoC: failed to probe CODEC DAI %s: %d\n",
1393 codec_dai->name, ret);
1398 /* mark codec_dai as probed and add to card dai list */
1399 codec_dai->probed = 1;
1400 list_add(&codec_dai->card_list, &card->dai_dev_list);
1403 /* complete DAI probe during last probe */
1404 if (order != SND_SOC_COMP_ORDER_LAST)
1407 ret = soc_post_component_init(card, codec, num, 0);
1411 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1413 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
1416 if (cpu_dai->driver->compress_dai) {
1417 /*create compress_device"*/
1418 ret = soc_new_compress(rtd, num);
1420 dev_err(card->dev, "ASoC: can't create compress %s\n",
1421 dai_link->stream_name);
1426 if (!dai_link->params) {
1427 /* create the pcm */
1428 ret = soc_new_pcm(rtd, num);
1430 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1431 dai_link->stream_name, ret);
1435 INIT_DELAYED_WORK(&rtd->delayed_work,
1436 codec2codec_close_delayed_work);
1438 /* link the DAI widgets */
1439 play_w = codec_dai->playback_widget;
1440 capture_w = cpu_dai->capture_widget;
1441 if (play_w && capture_w) {
1442 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1445 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1446 play_w->name, capture_w->name, ret);
1451 play_w = cpu_dai->playback_widget;
1452 capture_w = codec_dai->capture_widget;
1453 if (play_w && capture_w) {
1454 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1457 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1458 play_w->name, capture_w->name, ret);
1465 /* add platform data for AC97 devices */
1466 if (rtd->codec_dai->driver->ac97_control)
1467 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1472 #ifdef CONFIG_SND_SOC_AC97_BUS
1473 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1477 /* Only instantiate AC97 if not already done by the adaptor
1478 * for the generic AC97 subsystem.
1480 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1482 * It is possible that the AC97 device is already registered to
1483 * the device subsystem. This happens when the device is created
1484 * via snd_ac97_mixer(). Currently only SoC codec that does so
1485 * is the generic AC97 glue but others migh emerge.
1487 * In those cases we don't try to register the device again.
1489 if (!rtd->codec->ac97_created)
1492 ret = soc_ac97_dev_register(rtd->codec);
1494 dev_err(rtd->codec->dev,
1495 "ASoC: AC97 device register failed: %d\n", ret);
1499 rtd->codec->ac97_registered = 1;
1504 static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1506 if (codec->ac97_registered) {
1507 soc_ac97_dev_unregister(codec);
1508 codec->ac97_registered = 0;
1513 static int soc_check_aux_dev(struct snd_soc_card *card, int num)
1515 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1516 struct snd_soc_codec *codec;
1518 /* find CODEC from registered CODECs*/
1519 list_for_each_entry(codec, &codec_list, list) {
1520 if (!strcmp(codec->name, aux_dev->codec_name))
1524 dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name);
1526 return -EPROBE_DEFER;
1529 static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1531 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1532 struct snd_soc_codec *codec;
1535 /* find CODEC from registered CODECs*/
1536 list_for_each_entry(codec, &codec_list, list) {
1537 if (!strcmp(codec->name, aux_dev->codec_name)) {
1538 if (codec->probed) {
1540 "ASoC: codec already probed");
1547 /* codec not found */
1548 dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name);
1549 return -EPROBE_DEFER;
1552 ret = soc_probe_codec(card, codec);
1556 ret = soc_post_component_init(card, codec, num, 1);
1562 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1564 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1565 struct snd_soc_codec *codec = rtd->codec;
1567 /* unregister the rtd device */
1568 if (rtd->dev_registered) {
1569 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1570 device_unregister(rtd->dev);
1571 rtd->dev_registered = 0;
1574 if (codec && codec->probed)
1575 soc_remove_codec(codec);
1578 static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1579 enum snd_soc_compress_type compress_type)
1583 if (codec->cache_init)
1586 /* override the compress_type if necessary */
1587 if (compress_type && codec->compress_type != compress_type)
1588 codec->compress_type = compress_type;
1589 ret = snd_soc_cache_init(codec);
1592 "ASoC: Failed to set cache compression type: %d\n",
1596 codec->cache_init = 1;
1600 static int snd_soc_instantiate_card(struct snd_soc_card *card)
1602 struct snd_soc_codec *codec;
1603 struct snd_soc_codec_conf *codec_conf;
1604 enum snd_soc_compress_type compress_type;
1605 struct snd_soc_dai_link *dai_link;
1606 int ret, i, order, dai_fmt;
1608 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1611 for (i = 0; i < card->num_links; i++) {
1612 ret = soc_bind_dai_link(card, i);
1617 /* check aux_devs too */
1618 for (i = 0; i < card->num_aux_devs; i++) {
1619 ret = soc_check_aux_dev(card, i);
1624 /* initialize the register cache for each available codec */
1625 list_for_each_entry(codec, &codec_list, list) {
1626 if (codec->cache_init)
1628 /* by default we don't override the compress_type */
1630 /* check to see if we need to override the compress_type */
1631 for (i = 0; i < card->num_configs; ++i) {
1632 codec_conf = &card->codec_conf[i];
1633 if (!strcmp(codec->name, codec_conf->dev_name)) {
1634 compress_type = codec_conf->compress_type;
1635 if (compress_type && compress_type
1636 != codec->compress_type)
1640 ret = snd_soc_init_codec_cache(codec, compress_type);
1645 /* card bind complete so register a sound card */
1646 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1647 card->owner, 0, &card->snd_card);
1650 "ASoC: can't create sound card for card %s: %d\n",
1654 card->snd_card->dev = card->dev;
1656 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1657 card->dapm.dev = card->dev;
1658 card->dapm.card = card;
1659 list_add(&card->dapm.list, &card->dapm_list);
1661 #ifdef CONFIG_DEBUG_FS
1662 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1665 #ifdef CONFIG_PM_SLEEP
1666 /* deferred resume work */
1667 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1670 if (card->dapm_widgets)
1671 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1672 card->num_dapm_widgets);
1674 /* initialise the sound card only once */
1676 ret = card->probe(card);
1678 goto card_probe_error;
1681 /* probe all components used by DAI links on this card */
1682 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1684 for (i = 0; i < card->num_links; i++) {
1685 ret = soc_probe_link_components(card, i, order);
1688 "ASoC: failed to instantiate card %d\n",
1695 /* probe all DAI links on this card */
1696 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1698 for (i = 0; i < card->num_links; i++) {
1699 ret = soc_probe_link_dais(card, i, order);
1702 "ASoC: failed to instantiate card %d\n",
1709 for (i = 0; i < card->num_aux_devs; i++) {
1710 ret = soc_probe_aux_dev(card, i);
1713 "ASoC: failed to add auxiliary devices %d\n",
1715 goto probe_aux_dev_err;
1719 snd_soc_dapm_link_dai_widgets(card);
1722 snd_soc_add_card_controls(card, card->controls, card->num_controls);
1724 if (card->dapm_routes)
1725 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1726 card->num_dapm_routes);
1728 for (i = 0; i < card->num_links; i++) {
1729 dai_link = &card->dai_link[i];
1730 dai_fmt = dai_link->dai_fmt;
1733 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1735 if (ret != 0 && ret != -ENOTSUPP)
1736 dev_warn(card->rtd[i].codec_dai->dev,
1737 "ASoC: Failed to set DAI format: %d\n",
1741 /* If this is a regular CPU link there will be a platform */
1743 (dai_link->platform_name || dai_link->platform_of_node)) {
1744 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1746 if (ret != 0 && ret != -ENOTSUPP)
1747 dev_warn(card->rtd[i].cpu_dai->dev,
1748 "ASoC: Failed to set DAI format: %d\n",
1750 } else if (dai_fmt) {
1751 /* Flip the polarity for the "CPU" end */
1752 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1753 switch (dai_link->dai_fmt &
1754 SND_SOC_DAIFMT_MASTER_MASK) {
1755 case SND_SOC_DAIFMT_CBM_CFM:
1756 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1758 case SND_SOC_DAIFMT_CBM_CFS:
1759 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1761 case SND_SOC_DAIFMT_CBS_CFM:
1762 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1764 case SND_SOC_DAIFMT_CBS_CFS:
1765 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1769 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1771 if (ret != 0 && ret != -ENOTSUPP)
1772 dev_warn(card->rtd[i].cpu_dai->dev,
1773 "ASoC: Failed to set DAI format: %d\n",
1778 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1780 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1781 "%s", card->long_name ? card->long_name : card->name);
1782 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1783 "%s", card->driver_name ? card->driver_name : card->name);
1784 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1785 switch (card->snd_card->driver[i]) {
1791 if (!isalnum(card->snd_card->driver[i]))
1792 card->snd_card->driver[i] = '_';
1797 if (card->late_probe) {
1798 ret = card->late_probe(card);
1800 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
1802 goto probe_aux_dev_err;
1806 if (card->fully_routed)
1807 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1808 snd_soc_dapm_auto_nc_codec_pins(codec);
1810 snd_soc_dapm_new_widgets(card);
1812 ret = snd_card_register(card->snd_card);
1814 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
1816 goto probe_aux_dev_err;
1819 #ifdef CONFIG_SND_SOC_AC97_BUS
1820 /* register any AC97 codecs */
1821 for (i = 0; i < card->num_rtd; i++) {
1822 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1825 "ASoC: failed to register AC97: %d\n", ret);
1827 soc_unregister_ac97_dai_link(card->rtd[i].codec);
1828 goto probe_aux_dev_err;
1833 card->instantiated = 1;
1834 snd_soc_dapm_sync(&card->dapm);
1835 mutex_unlock(&card->mutex);
1840 for (i = 0; i < card->num_aux_devs; i++)
1841 soc_remove_aux_dev(card, i);
1844 soc_remove_dai_links(card);
1850 snd_card_free(card->snd_card);
1853 mutex_unlock(&card->mutex);
1858 /* probes a new socdev */
1859 static int soc_probe(struct platform_device *pdev)
1861 struct snd_soc_card *card = platform_get_drvdata(pdev);
1864 * no card, so machine driver should be registering card
1865 * we should not be here in that case so ret error
1870 dev_warn(&pdev->dev,
1871 "ASoC: machine %s should use snd_soc_register_card()\n",
1874 /* Bodge while we unpick instantiation */
1875 card->dev = &pdev->dev;
1877 return snd_soc_register_card(card);
1880 static int soc_cleanup_card_resources(struct snd_soc_card *card)
1884 /* make sure any delayed work runs */
1885 for (i = 0; i < card->num_rtd; i++) {
1886 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1887 flush_delayed_work(&rtd->delayed_work);
1890 /* remove auxiliary devices */
1891 for (i = 0; i < card->num_aux_devs; i++)
1892 soc_remove_aux_dev(card, i);
1894 /* remove and free each DAI */
1895 soc_remove_dai_links(card);
1897 soc_cleanup_card_debugfs(card);
1899 /* remove the card */
1903 snd_soc_dapm_free(&card->dapm);
1905 snd_card_free(card->snd_card);
1910 /* removes a socdev */
1911 static int soc_remove(struct platform_device *pdev)
1913 struct snd_soc_card *card = platform_get_drvdata(pdev);
1915 snd_soc_unregister_card(card);
1919 int snd_soc_poweroff(struct device *dev)
1921 struct snd_soc_card *card = dev_get_drvdata(dev);
1924 if (!card->instantiated)
1927 /* Flush out pmdown_time work - we actually do want to run it
1928 * now, we're shutting down so no imminent restart. */
1929 for (i = 0; i < card->num_rtd; i++) {
1930 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1931 flush_delayed_work(&rtd->delayed_work);
1934 snd_soc_dapm_shutdown(card);
1938 EXPORT_SYMBOL_GPL(snd_soc_poweroff);
1940 const struct dev_pm_ops snd_soc_pm_ops = {
1941 .suspend = snd_soc_suspend,
1942 .resume = snd_soc_resume,
1943 .freeze = snd_soc_suspend,
1944 .thaw = snd_soc_resume,
1945 .poweroff = snd_soc_poweroff,
1946 .restore = snd_soc_resume,
1948 EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
1950 /* ASoC platform driver */
1951 static struct platform_driver soc_driver = {
1953 .name = "soc-audio",
1954 .owner = THIS_MODULE,
1955 .pm = &snd_soc_pm_ops,
1958 .remove = soc_remove,
1962 * snd_soc_codec_volatile_register: Report if a register is volatile.
1964 * @codec: CODEC to query.
1965 * @reg: Register to query.
1967 * Boolean function indiciating if a CODEC register is volatile.
1969 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1972 if (codec->volatile_register)
1973 return codec->volatile_register(codec, reg);
1977 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1980 * snd_soc_codec_readable_register: Report if a register is readable.
1982 * @codec: CODEC to query.
1983 * @reg: Register to query.
1985 * Boolean function indicating if a CODEC register is readable.
1987 int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1990 if (codec->readable_register)
1991 return codec->readable_register(codec, reg);
1995 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1998 * snd_soc_codec_writable_register: Report if a register is writable.
2000 * @codec: CODEC to query.
2001 * @reg: Register to query.
2003 * Boolean function indicating if a CODEC register is writable.
2005 int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
2008 if (codec->writable_register)
2009 return codec->writable_register(codec, reg);
2013 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
2015 int snd_soc_platform_read(struct snd_soc_platform *platform,
2020 if (!platform->driver->read) {
2021 dev_err(platform->dev, "ASoC: platform has no read back\n");
2025 ret = platform->driver->read(platform, reg);
2026 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
2027 trace_snd_soc_preg_read(platform, reg, ret);
2031 EXPORT_SYMBOL_GPL(snd_soc_platform_read);
2033 int snd_soc_platform_write(struct snd_soc_platform *platform,
2034 unsigned int reg, unsigned int val)
2036 if (!platform->driver->write) {
2037 dev_err(platform->dev, "ASoC: platform has no write back\n");
2041 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
2042 trace_snd_soc_preg_write(platform, reg, val);
2043 return platform->driver->write(platform, reg, val);
2045 EXPORT_SYMBOL_GPL(snd_soc_platform_write);
2048 * snd_soc_new_ac97_codec - initailise AC97 device
2049 * @codec: audio codec
2050 * @ops: AC97 bus operations
2051 * @num: AC97 codec number
2053 * Initialises AC97 codec resources for use by ad-hoc devices only.
2055 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
2056 struct snd_ac97_bus_ops *ops, int num)
2058 mutex_lock(&codec->mutex);
2060 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
2061 if (codec->ac97 == NULL) {
2062 mutex_unlock(&codec->mutex);
2066 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
2067 if (codec->ac97->bus == NULL) {
2070 mutex_unlock(&codec->mutex);
2074 codec->ac97->bus->ops = ops;
2075 codec->ac97->num = num;
2078 * Mark the AC97 device to be created by us. This way we ensure that the
2079 * device will be registered with the device subsystem later on.
2081 codec->ac97_created = 1;
2083 mutex_unlock(&codec->mutex);
2086 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
2088 struct snd_ac97_bus_ops *soc_ac97_ops;
2089 EXPORT_SYMBOL_GPL(soc_ac97_ops);
2091 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
2093 if (ops == soc_ac97_ops)
2096 if (soc_ac97_ops && ops)
2103 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops);
2106 * snd_soc_free_ac97_codec - free AC97 codec device
2107 * @codec: audio codec
2109 * Frees AC97 codec device resources.
2111 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
2113 mutex_lock(&codec->mutex);
2114 #ifdef CONFIG_SND_SOC_AC97_BUS
2115 soc_unregister_ac97_dai_link(codec);
2117 kfree(codec->ac97->bus);
2120 codec->ac97_created = 0;
2121 mutex_unlock(&codec->mutex);
2123 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
2125 unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
2129 ret = codec->read(codec, reg);
2130 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
2131 trace_snd_soc_reg_read(codec, reg, ret);
2135 EXPORT_SYMBOL_GPL(snd_soc_read);
2137 unsigned int snd_soc_write(struct snd_soc_codec *codec,
2138 unsigned int reg, unsigned int val)
2140 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
2141 trace_snd_soc_reg_write(codec, reg, val);
2142 return codec->write(codec, reg, val);
2144 EXPORT_SYMBOL_GPL(snd_soc_write);
2146 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
2147 unsigned int reg, const void *data, size_t len)
2149 return codec->bulk_write_raw(codec, reg, data, len);
2151 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
2154 * snd_soc_update_bits - update codec register bits
2155 * @codec: audio codec
2156 * @reg: codec register
2157 * @mask: register mask
2160 * Writes new register value.
2162 * Returns 1 for change, 0 for no change, or negative error code.
2164 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
2165 unsigned int mask, unsigned int value)
2168 unsigned int old, new;
2171 if (codec->using_regmap) {
2172 ret = regmap_update_bits_check(codec->control_data, reg,
2173 mask, value, &change);
2175 ret = snd_soc_read(codec, reg);
2180 new = (old & ~mask) | (value & mask);
2181 change = old != new;
2183 ret = snd_soc_write(codec, reg, new);
2191 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
2194 * snd_soc_update_bits_locked - update codec register bits
2195 * @codec: audio codec
2196 * @reg: codec register
2197 * @mask: register mask
2200 * Writes new register value, and takes the codec mutex.
2202 * Returns 1 for change else 0.
2204 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
2205 unsigned short reg, unsigned int mask,
2210 mutex_lock(&codec->mutex);
2211 change = snd_soc_update_bits(codec, reg, mask, value);
2212 mutex_unlock(&codec->mutex);
2216 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
2219 * snd_soc_test_bits - test register for change
2220 * @codec: audio codec
2221 * @reg: codec register
2222 * @mask: register mask
2225 * Tests a register with a new value and checks if the new value is
2226 * different from the old value.
2228 * Returns 1 for change else 0.
2230 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
2231 unsigned int mask, unsigned int value)
2234 unsigned int old, new;
2236 old = snd_soc_read(codec, reg);
2237 new = (old & ~mask) | value;
2238 change = old != new;
2242 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
2245 * snd_soc_cnew - create new control
2246 * @_template: control template
2247 * @data: control private data
2248 * @long_name: control long name
2249 * @prefix: control name prefix
2251 * Create a new mixer control from a template control.
2253 * Returns 0 for success, else error.
2255 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
2256 void *data, const char *long_name,
2259 struct snd_kcontrol_new template;
2260 struct snd_kcontrol *kcontrol;
2263 memcpy(&template, _template, sizeof(template));
2267 long_name = template.name;
2270 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2274 template.name = name;
2276 template.name = long_name;
2279 kcontrol = snd_ctl_new1(&template, data);
2285 EXPORT_SYMBOL_GPL(snd_soc_cnew);
2287 static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2288 const struct snd_kcontrol_new *controls, int num_controls,
2289 const char *prefix, void *data)
2293 for (i = 0; i < num_controls; i++) {
2294 const struct snd_kcontrol_new *control = &controls[i];
2295 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2296 control->name, prefix));
2298 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2299 control->name, err);
2308 * snd_soc_add_codec_controls - add an array of controls to a codec.
2309 * Convenience function to add a list of controls. Many codecs were
2310 * duplicating this code.
2312 * @codec: codec to add controls to
2313 * @controls: array of controls to add
2314 * @num_controls: number of elements in the array
2316 * Return 0 for success, else error.
2318 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
2319 const struct snd_kcontrol_new *controls, int num_controls)
2321 struct snd_card *card = codec->card->snd_card;
2323 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2324 codec->name_prefix, codec);
2326 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
2329 * snd_soc_add_platform_controls - add an array of controls to a platform.
2330 * Convenience function to add a list of controls.
2332 * @platform: platform to add controls to
2333 * @controls: array of controls to add
2334 * @num_controls: number of elements in the array
2336 * Return 0 for success, else error.
2338 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2339 const struct snd_kcontrol_new *controls, int num_controls)
2341 struct snd_card *card = platform->card->snd_card;
2343 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2346 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2349 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2350 * Convenience function to add a list of controls.
2352 * @soc_card: SoC card to add controls to
2353 * @controls: array of controls to add
2354 * @num_controls: number of elements in the array
2356 * Return 0 for success, else error.
2358 int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2359 const struct snd_kcontrol_new *controls, int num_controls)
2361 struct snd_card *card = soc_card->snd_card;
2363 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2366 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2369 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2370 * Convienience function to add a list of controls.
2372 * @dai: DAI to add controls to
2373 * @controls: array of controls to add
2374 * @num_controls: number of elements in the array
2376 * Return 0 for success, else error.
2378 int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2379 const struct snd_kcontrol_new *controls, int num_controls)
2381 struct snd_card *card = dai->card->snd_card;
2383 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2386 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2389 * snd_soc_info_enum_double - enumerated double mixer info callback
2390 * @kcontrol: mixer control
2391 * @uinfo: control element information
2393 * Callback to provide information about a double enumerated
2396 * Returns 0 for success.
2398 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2399 struct snd_ctl_elem_info *uinfo)
2401 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2403 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2404 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2405 uinfo->value.enumerated.items = e->max;
2407 if (uinfo->value.enumerated.item > e->max - 1)
2408 uinfo->value.enumerated.item = e->max - 1;
2409 strcpy(uinfo->value.enumerated.name,
2410 e->texts[uinfo->value.enumerated.item]);
2413 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2416 * snd_soc_get_enum_double - enumerated double mixer get callback
2417 * @kcontrol: mixer control
2418 * @ucontrol: control element information
2420 * Callback to get the value of a double enumerated mixer.
2422 * Returns 0 for success.
2424 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2425 struct snd_ctl_elem_value *ucontrol)
2427 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2428 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2431 val = snd_soc_read(codec, e->reg);
2432 ucontrol->value.enumerated.item[0]
2433 = (val >> e->shift_l) & e->mask;
2434 if (e->shift_l != e->shift_r)
2435 ucontrol->value.enumerated.item[1] =
2436 (val >> e->shift_r) & e->mask;
2440 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2443 * snd_soc_put_enum_double - enumerated double mixer put callback
2444 * @kcontrol: mixer control
2445 * @ucontrol: control element information
2447 * Callback to set the value of a double enumerated mixer.
2449 * Returns 0 for success.
2451 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2452 struct snd_ctl_elem_value *ucontrol)
2454 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2455 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2459 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2461 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2462 mask = e->mask << e->shift_l;
2463 if (e->shift_l != e->shift_r) {
2464 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2466 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2467 mask |= e->mask << e->shift_r;
2470 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2472 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2475 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2476 * @kcontrol: mixer control
2477 * @ucontrol: control element information
2479 * Callback to get the value of a double semi enumerated mixer.
2481 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2482 * used for handling bitfield coded enumeration for example.
2484 * Returns 0 for success.
2486 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2487 struct snd_ctl_elem_value *ucontrol)
2489 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2490 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2491 unsigned int reg_val, val, mux;
2493 reg_val = snd_soc_read(codec, e->reg);
2494 val = (reg_val >> e->shift_l) & e->mask;
2495 for (mux = 0; mux < e->max; mux++) {
2496 if (val == e->values[mux])
2499 ucontrol->value.enumerated.item[0] = mux;
2500 if (e->shift_l != e->shift_r) {
2501 val = (reg_val >> e->shift_r) & e->mask;
2502 for (mux = 0; mux < e->max; mux++) {
2503 if (val == e->values[mux])
2506 ucontrol->value.enumerated.item[1] = mux;
2511 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2514 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2515 * @kcontrol: mixer control
2516 * @ucontrol: control element information
2518 * Callback to set the value of a double semi enumerated mixer.
2520 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2521 * used for handling bitfield coded enumeration for example.
2523 * Returns 0 for success.
2525 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_value *ucontrol)
2528 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2529 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2533 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2535 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2536 mask = e->mask << e->shift_l;
2537 if (e->shift_l != e->shift_r) {
2538 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2540 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2541 mask |= e->mask << e->shift_r;
2544 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2546 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2549 * snd_soc_info_volsw - single mixer info callback
2550 * @kcontrol: mixer control
2551 * @uinfo: control element information
2553 * Callback to provide information about a single mixer control, or a double
2554 * mixer control that spans 2 registers.
2556 * Returns 0 for success.
2558 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2559 struct snd_ctl_elem_info *uinfo)
2561 struct soc_mixer_control *mc =
2562 (struct soc_mixer_control *)kcontrol->private_value;
2565 if (!mc->platform_max)
2566 mc->platform_max = mc->max;
2567 platform_max = mc->platform_max;
2569 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2570 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2572 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2574 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2575 uinfo->value.integer.min = 0;
2576 uinfo->value.integer.max = platform_max;
2579 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2582 * snd_soc_get_volsw - single mixer get callback
2583 * @kcontrol: mixer control
2584 * @ucontrol: control element information
2586 * Callback to get the value of a single mixer control, or a double mixer
2587 * control that spans 2 registers.
2589 * Returns 0 for success.
2591 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2592 struct snd_ctl_elem_value *ucontrol)
2594 struct soc_mixer_control *mc =
2595 (struct soc_mixer_control *)kcontrol->private_value;
2596 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2597 unsigned int reg = mc->reg;
2598 unsigned int reg2 = mc->rreg;
2599 unsigned int shift = mc->shift;
2600 unsigned int rshift = mc->rshift;
2602 unsigned int mask = (1 << fls(max)) - 1;
2603 unsigned int invert = mc->invert;
2605 ucontrol->value.integer.value[0] =
2606 (snd_soc_read(codec, reg) >> shift) & mask;
2608 ucontrol->value.integer.value[0] =
2609 max - ucontrol->value.integer.value[0];
2611 if (snd_soc_volsw_is_stereo(mc)) {
2613 ucontrol->value.integer.value[1] =
2614 (snd_soc_read(codec, reg) >> rshift) & mask;
2616 ucontrol->value.integer.value[1] =
2617 (snd_soc_read(codec, reg2) >> shift) & mask;
2619 ucontrol->value.integer.value[1] =
2620 max - ucontrol->value.integer.value[1];
2625 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2628 * snd_soc_put_volsw - single mixer put callback
2629 * @kcontrol: mixer control
2630 * @ucontrol: control element information
2632 * Callback to set the value of a single mixer control, or a double mixer
2633 * control that spans 2 registers.
2635 * Returns 0 for success.
2637 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2638 struct snd_ctl_elem_value *ucontrol)
2640 struct soc_mixer_control *mc =
2641 (struct soc_mixer_control *)kcontrol->private_value;
2642 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2643 unsigned int reg = mc->reg;
2644 unsigned int reg2 = mc->rreg;
2645 unsigned int shift = mc->shift;
2646 unsigned int rshift = mc->rshift;
2648 unsigned int mask = (1 << fls(max)) - 1;
2649 unsigned int invert = mc->invert;
2652 unsigned int val2 = 0;
2653 unsigned int val, val_mask;
2655 val = (ucontrol->value.integer.value[0] & mask);
2658 val_mask = mask << shift;
2660 if (snd_soc_volsw_is_stereo(mc)) {
2661 val2 = (ucontrol->value.integer.value[1] & mask);
2665 val_mask |= mask << rshift;
2666 val |= val2 << rshift;
2668 val2 = val2 << shift;
2672 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2677 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2681 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2684 * snd_soc_get_volsw_sx - single mixer get callback
2685 * @kcontrol: mixer control
2686 * @ucontrol: control element information
2688 * Callback to get the value of a single mixer control, or a double mixer
2689 * control that spans 2 registers.
2691 * Returns 0 for success.
2693 int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2694 struct snd_ctl_elem_value *ucontrol)
2696 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2697 struct soc_mixer_control *mc =
2698 (struct soc_mixer_control *)kcontrol->private_value;
2700 unsigned int reg = mc->reg;
2701 unsigned int reg2 = mc->rreg;
2702 unsigned int shift = mc->shift;
2703 unsigned int rshift = mc->rshift;
2706 int mask = (1 << (fls(min + max) - 1)) - 1;
2708 ucontrol->value.integer.value[0] =
2709 ((snd_soc_read(codec, reg) >> shift) - min) & mask;
2711 if (snd_soc_volsw_is_stereo(mc))
2712 ucontrol->value.integer.value[1] =
2713 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
2717 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2720 * snd_soc_put_volsw_sx - double mixer set callback
2721 * @kcontrol: mixer control
2722 * @uinfo: control element information
2724 * Callback to set the value of a double mixer control that spans 2 registers.
2726 * Returns 0 for success.
2728 int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2729 struct snd_ctl_elem_value *ucontrol)
2731 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2732 struct soc_mixer_control *mc =
2733 (struct soc_mixer_control *)kcontrol->private_value;
2735 unsigned int reg = mc->reg;
2736 unsigned int reg2 = mc->rreg;
2737 unsigned int shift = mc->shift;
2738 unsigned int rshift = mc->rshift;
2741 int mask = (1 << (fls(min + max) - 1)) - 1;
2743 unsigned short val, val_mask, val2 = 0;
2745 val_mask = mask << shift;
2746 val = (ucontrol->value.integer.value[0] + min) & mask;
2749 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2753 if (snd_soc_volsw_is_stereo(mc)) {
2754 val_mask = mask << rshift;
2755 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2756 val2 = val2 << rshift;
2758 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
2763 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2766 * snd_soc_info_volsw_s8 - signed mixer info callback
2767 * @kcontrol: mixer control
2768 * @uinfo: control element information
2770 * Callback to provide information about a signed mixer control.
2772 * Returns 0 for success.
2774 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2775 struct snd_ctl_elem_info *uinfo)
2777 struct soc_mixer_control *mc =
2778 (struct soc_mixer_control *)kcontrol->private_value;
2782 if (!mc->platform_max)
2783 mc->platform_max = mc->max;
2784 platform_max = mc->platform_max;
2786 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2788 uinfo->value.integer.min = 0;
2789 uinfo->value.integer.max = platform_max - min;
2792 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2795 * snd_soc_get_volsw_s8 - signed mixer get callback
2796 * @kcontrol: mixer control
2797 * @ucontrol: control element information
2799 * Callback to get the value of a signed mixer control.
2801 * Returns 0 for success.
2803 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2804 struct snd_ctl_elem_value *ucontrol)
2806 struct soc_mixer_control *mc =
2807 (struct soc_mixer_control *)kcontrol->private_value;
2808 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2809 unsigned int reg = mc->reg;
2811 int val = snd_soc_read(codec, reg);
2813 ucontrol->value.integer.value[0] =
2814 ((signed char)(val & 0xff))-min;
2815 ucontrol->value.integer.value[1] =
2816 ((signed char)((val >> 8) & 0xff))-min;
2819 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2822 * snd_soc_put_volsw_sgn - signed mixer put callback
2823 * @kcontrol: mixer control
2824 * @ucontrol: control element information
2826 * Callback to set the value of a signed mixer control.
2828 * Returns 0 for success.
2830 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2831 struct snd_ctl_elem_value *ucontrol)
2833 struct soc_mixer_control *mc =
2834 (struct soc_mixer_control *)kcontrol->private_value;
2835 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2836 unsigned int reg = mc->reg;
2840 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2841 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2843 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2845 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2848 * snd_soc_info_volsw_range - single mixer info callback with range.
2849 * @kcontrol: mixer control
2850 * @uinfo: control element information
2852 * Callback to provide information, within a range, about a single
2855 * returns 0 for success.
2857 int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
2858 struct snd_ctl_elem_info *uinfo)
2860 struct soc_mixer_control *mc =
2861 (struct soc_mixer_control *)kcontrol->private_value;
2865 if (!mc->platform_max)
2866 mc->platform_max = mc->max;
2867 platform_max = mc->platform_max;
2869 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2870 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2871 uinfo->value.integer.min = 0;
2872 uinfo->value.integer.max = platform_max - min;
2876 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
2879 * snd_soc_put_volsw_range - single mixer put value callback with range.
2880 * @kcontrol: mixer control
2881 * @ucontrol: control element information
2883 * Callback to set the value, within a range, for a single mixer control.
2885 * Returns 0 for success.
2887 int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
2888 struct snd_ctl_elem_value *ucontrol)
2890 struct soc_mixer_control *mc =
2891 (struct soc_mixer_control *)kcontrol->private_value;
2892 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2893 unsigned int reg = mc->reg;
2894 unsigned int rreg = mc->rreg;
2895 unsigned int shift = mc->shift;
2898 unsigned int mask = (1 << fls(max)) - 1;
2899 unsigned int invert = mc->invert;
2900 unsigned int val, val_mask;
2903 val = ((ucontrol->value.integer.value[0] + min) & mask);
2906 val_mask = mask << shift;
2909 ret = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2913 if (snd_soc_volsw_is_stereo(mc)) {
2914 val = ((ucontrol->value.integer.value[1] + min) & mask);
2917 val_mask = mask << shift;
2920 ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val);
2925 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
2928 * snd_soc_get_volsw_range - single mixer get callback with range
2929 * @kcontrol: mixer control
2930 * @ucontrol: control element information
2932 * Callback to get the value, within a range, of a single mixer control.
2934 * Returns 0 for success.
2936 int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
2937 struct snd_ctl_elem_value *ucontrol)
2939 struct soc_mixer_control *mc =
2940 (struct soc_mixer_control *)kcontrol->private_value;
2941 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2942 unsigned int reg = mc->reg;
2943 unsigned int rreg = mc->rreg;
2944 unsigned int shift = mc->shift;
2947 unsigned int mask = (1 << fls(max)) - 1;
2948 unsigned int invert = mc->invert;
2950 ucontrol->value.integer.value[0] =
2951 (snd_soc_read(codec, reg) >> shift) & mask;
2953 ucontrol->value.integer.value[0] =
2954 max - ucontrol->value.integer.value[0];
2955 ucontrol->value.integer.value[0] =
2956 ucontrol->value.integer.value[0] - min;
2958 if (snd_soc_volsw_is_stereo(mc)) {
2959 ucontrol->value.integer.value[1] =
2960 (snd_soc_read(codec, rreg) >> shift) & mask;
2962 ucontrol->value.integer.value[1] =
2963 max - ucontrol->value.integer.value[1];
2964 ucontrol->value.integer.value[1] =
2965 ucontrol->value.integer.value[1] - min;
2970 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
2973 * snd_soc_limit_volume - Set new limit to an existing volume control.
2975 * @codec: where to look for the control
2976 * @name: Name of the control
2977 * @max: new maximum limit
2979 * Return 0 for success, else error.
2981 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2982 const char *name, int max)
2984 struct snd_card *card = codec->card->snd_card;
2985 struct snd_kcontrol *kctl;
2986 struct soc_mixer_control *mc;
2990 /* Sanity check for name and max */
2991 if (unlikely(!name || max <= 0))
2994 list_for_each_entry(kctl, &card->controls, list) {
2995 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
3001 mc = (struct soc_mixer_control *)kctl->private_value;
3002 if (max <= mc->max) {
3003 mc->platform_max = max;
3009 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
3011 int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
3012 struct snd_ctl_elem_info *uinfo)
3014 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3015 struct soc_bytes *params = (void *)kcontrol->private_value;
3017 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3018 uinfo->count = params->num_regs * codec->val_bytes;
3022 EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3024 int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3025 struct snd_ctl_elem_value *ucontrol)
3027 struct soc_bytes *params = (void *)kcontrol->private_value;
3028 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3031 if (codec->using_regmap)
3032 ret = regmap_raw_read(codec->control_data, params->base,
3033 ucontrol->value.bytes.data,
3034 params->num_regs * codec->val_bytes);
3038 /* Hide any masked bytes to ensure consistent data reporting */
3039 if (ret == 0 && params->mask) {
3040 switch (codec->val_bytes) {
3042 ucontrol->value.bytes.data[0] &= ~params->mask;
3045 ((u16 *)(&ucontrol->value.bytes.data))[0]
3049 ((u32 *)(&ucontrol->value.bytes.data))[0]
3059 EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3061 int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3062 struct snd_ctl_elem_value *ucontrol)
3064 struct soc_bytes *params = (void *)kcontrol->private_value;
3065 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3070 if (!codec->using_regmap)
3073 len = params->num_regs * codec->val_bytes;
3075 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3080 * If we've got a mask then we need to preserve the register
3081 * bits. We shouldn't modify the incoming data so take a
3085 ret = regmap_read(codec->control_data, params->base, &val);
3089 val &= params->mask;
3091 switch (codec->val_bytes) {
3093 ((u8 *)data)[0] &= ~params->mask;
3094 ((u8 *)data)[0] |= val;
3097 ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
3098 ((u16 *)data)[0] |= cpu_to_be16(val);
3101 ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
3102 ((u32 *)data)[0] |= cpu_to_be32(val);
3110 ret = regmap_raw_write(codec->control_data, params->base,
3118 EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
3121 * snd_soc_info_xr_sx - signed multi register info callback
3122 * @kcontrol: mreg control
3123 * @uinfo: control element information
3125 * Callback to provide information of a control that can
3126 * span multiple codec registers which together
3127 * forms a single signed value in a MSB/LSB manner.
3129 * Returns 0 for success.
3131 int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
3132 struct snd_ctl_elem_info *uinfo)
3134 struct soc_mreg_control *mc =
3135 (struct soc_mreg_control *)kcontrol->private_value;
3136 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3138 uinfo->value.integer.min = mc->min;
3139 uinfo->value.integer.max = mc->max;
3143 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3146 * snd_soc_get_xr_sx - signed multi register get callback
3147 * @kcontrol: mreg control
3148 * @ucontrol: control element information
3150 * Callback to get the value of a control that can span
3151 * multiple codec registers which together forms a single
3152 * signed value in a MSB/LSB manner. The control supports
3153 * specifying total no of bits used to allow for bitfields
3154 * across the multiple codec registers.
3156 * Returns 0 for success.
3158 int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3159 struct snd_ctl_elem_value *ucontrol)
3161 struct soc_mreg_control *mc =
3162 (struct soc_mreg_control *)kcontrol->private_value;
3163 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3164 unsigned int regbase = mc->regbase;
3165 unsigned int regcount = mc->regcount;
3166 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3167 unsigned int regwmask = (1<<regwshift)-1;
3168 unsigned int invert = mc->invert;
3169 unsigned long mask = (1UL<<mc->nbits)-1;
3173 unsigned long regval;
3176 for (i = 0; i < regcount; i++) {
3177 regval = snd_soc_read(codec, regbase+i) & regwmask;
3178 val |= regval << (regwshift*(regcount-i-1));
3181 if (min < 0 && val > max)
3185 ucontrol->value.integer.value[0] = val;
3189 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3192 * snd_soc_put_xr_sx - signed multi register get callback
3193 * @kcontrol: mreg control
3194 * @ucontrol: control element information
3196 * Callback to set the value of a control that can span
3197 * multiple codec registers which together forms a single
3198 * signed value in a MSB/LSB manner. The control supports
3199 * specifying total no of bits used to allow for bitfields
3200 * across the multiple codec registers.
3202 * Returns 0 for success.
3204 int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3205 struct snd_ctl_elem_value *ucontrol)
3207 struct soc_mreg_control *mc =
3208 (struct soc_mreg_control *)kcontrol->private_value;
3209 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3210 unsigned int regbase = mc->regbase;
3211 unsigned int regcount = mc->regcount;
3212 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3213 unsigned int regwmask = (1<<regwshift)-1;
3214 unsigned int invert = mc->invert;
3215 unsigned long mask = (1UL<<mc->nbits)-1;
3217 long val = ucontrol->value.integer.value[0];
3218 unsigned int i, regval, regmask;
3224 for (i = 0; i < regcount; i++) {
3225 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3226 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3227 err = snd_soc_update_bits_locked(codec, regbase+i,
3235 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3238 * snd_soc_get_strobe - strobe get callback
3239 * @kcontrol: mixer control
3240 * @ucontrol: control element information
3242 * Callback get the value of a strobe mixer control.
3244 * Returns 0 for success.
3246 int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3247 struct snd_ctl_elem_value *ucontrol)
3249 struct soc_mixer_control *mc =
3250 (struct soc_mixer_control *)kcontrol->private_value;
3251 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3252 unsigned int reg = mc->reg;
3253 unsigned int shift = mc->shift;
3254 unsigned int mask = 1 << shift;
3255 unsigned int invert = mc->invert != 0;
3256 unsigned int val = snd_soc_read(codec, reg) & mask;
3258 if (shift != 0 && val != 0)
3260 ucontrol->value.enumerated.item[0] = val ^ invert;
3264 EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3267 * snd_soc_put_strobe - strobe put callback
3268 * @kcontrol: mixer control
3269 * @ucontrol: control element information
3271 * Callback strobe a register bit to high then low (or the inverse)
3272 * in one pass of a single mixer enum control.
3274 * Returns 1 for success.
3276 int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3277 struct snd_ctl_elem_value *ucontrol)
3279 struct soc_mixer_control *mc =
3280 (struct soc_mixer_control *)kcontrol->private_value;
3281 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3282 unsigned int reg = mc->reg;
3283 unsigned int shift = mc->shift;
3284 unsigned int mask = 1 << shift;
3285 unsigned int invert = mc->invert != 0;
3286 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3287 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3288 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3291 err = snd_soc_update_bits_locked(codec, reg, mask, val1);
3295 err = snd_soc_update_bits_locked(codec, reg, mask, val2);
3298 EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3301 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3303 * @clk_id: DAI specific clock ID
3304 * @freq: new clock frequency in Hz
3305 * @dir: new clock direction - input/output.
3307 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3309 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
3310 unsigned int freq, int dir)
3312 if (dai->driver && dai->driver->ops->set_sysclk)
3313 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
3314 else if (dai->codec && dai->codec->driver->set_sysclk)
3315 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
3320 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
3323 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3325 * @clk_id: DAI specific clock ID
3326 * @source: Source for the clock
3327 * @freq: new clock frequency in Hz
3328 * @dir: new clock direction - input/output.
3330 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3332 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
3333 int source, unsigned int freq, int dir)
3335 if (codec->driver->set_sysclk)
3336 return codec->driver->set_sysclk(codec, clk_id, source,
3341 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
3344 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3346 * @div_id: DAI specific clock divider ID
3347 * @div: new clock divisor.
3349 * Configures the clock dividers. This is used to derive the best DAI bit and
3350 * frame clocks from the system or master clock. It's best to set the DAI bit
3351 * and frame clocks as low as possible to save system power.
3353 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
3354 int div_id, int div)
3356 if (dai->driver && dai->driver->ops->set_clkdiv)
3357 return dai->driver->ops->set_clkdiv(dai, div_id, div);
3361 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
3364 * snd_soc_dai_set_pll - configure DAI PLL.
3366 * @pll_id: DAI specific PLL ID
3367 * @source: DAI specific source for the PLL
3368 * @freq_in: PLL input clock frequency in Hz
3369 * @freq_out: requested PLL output clock frequency in Hz
3371 * Configures and enables PLL to generate output clock based on input clock.
3373 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
3374 unsigned int freq_in, unsigned int freq_out)
3376 if (dai->driver && dai->driver->ops->set_pll)
3377 return dai->driver->ops->set_pll(dai, pll_id, source,
3379 else if (dai->codec && dai->codec->driver->set_pll)
3380 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
3385 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
3388 * snd_soc_codec_set_pll - configure codec PLL.
3390 * @pll_id: DAI specific PLL ID
3391 * @source: DAI specific source for the PLL
3392 * @freq_in: PLL input clock frequency in Hz
3393 * @freq_out: requested PLL output clock frequency in Hz
3395 * Configures and enables PLL to generate output clock based on input clock.
3397 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
3398 unsigned int freq_in, unsigned int freq_out)
3400 if (codec->driver->set_pll)
3401 return codec->driver->set_pll(codec, pll_id, source,
3406 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
3409 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3411 * @fmt: SND_SOC_DAIFMT_ format value.
3413 * Configures the DAI hardware format and clocking.
3415 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3417 if (dai->driver == NULL)
3419 if (dai->driver->ops->set_fmt == NULL)
3421 return dai->driver->ops->set_fmt(dai, fmt);
3423 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3426 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3428 * @tx_mask: bitmask representing active TX slots.
3429 * @rx_mask: bitmask representing active RX slots.
3430 * @slots: Number of slots in use.
3431 * @slot_width: Width in bits for each slot.
3433 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3436 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
3437 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
3439 if (dai->driver && dai->driver->ops->set_tdm_slot)
3440 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
3445 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
3448 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3450 * @tx_num: how many TX channels
3451 * @tx_slot: pointer to an array which imply the TX slot number channel
3453 * @rx_num: how many RX channels
3454 * @rx_slot: pointer to an array which imply the RX slot number channel
3457 * configure the relationship between channel number and TDM slot number.
3459 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
3460 unsigned int tx_num, unsigned int *tx_slot,
3461 unsigned int rx_num, unsigned int *rx_slot)
3463 if (dai->driver && dai->driver->ops->set_channel_map)
3464 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
3469 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
3472 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3474 * @tristate: tristate enable
3476 * Tristates the DAI so that others can use it.
3478 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
3480 if (dai->driver && dai->driver->ops->set_tristate)
3481 return dai->driver->ops->set_tristate(dai, tristate);
3485 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
3488 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3490 * @mute: mute enable
3491 * @direction: stream to mute
3493 * Mutes the DAI DAC.
3495 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
3501 if (dai->driver->ops->mute_stream)
3502 return dai->driver->ops->mute_stream(dai, mute, direction);
3503 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
3504 dai->driver->ops->digital_mute)
3505 return dai->driver->ops->digital_mute(dai, mute);
3509 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3512 * snd_soc_register_card - Register a card with the ASoC core
3514 * @card: Card to register
3517 int snd_soc_register_card(struct snd_soc_card *card)
3521 if (!card->name || !card->dev)
3524 for (i = 0; i < card->num_links; i++) {
3525 struct snd_soc_dai_link *link = &card->dai_link[i];
3528 * Codec must be specified by 1 of name or OF node,
3529 * not both or neither.
3531 if (!!link->codec_name == !!link->codec_of_node) {
3533 "ASoC: Neither/both codec name/of_node are set for %s\n",
3537 /* Codec DAI name must be specified */
3538 if (!link->codec_dai_name) {
3540 "ASoC: codec_dai_name not set for %s\n",
3546 * Platform may be specified by either name or OF node, but
3547 * can be left unspecified, and a dummy platform will be used.
3549 if (link->platform_name && link->platform_of_node) {
3551 "ASoC: Both platform name/of_node are set for %s\n",
3557 * CPU device may be specified by either name or OF node, but
3558 * can be left unspecified, and will be matched based on DAI
3561 if (link->cpu_name && link->cpu_of_node) {
3563 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3568 * At least one of CPU DAI name or CPU device name/node must be
3571 if (!link->cpu_dai_name &&
3572 !(link->cpu_name || link->cpu_of_node)) {
3574 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3580 dev_set_drvdata(card->dev, card);
3582 snd_soc_initialize_card_lists(card);
3584 soc_init_card_debugfs(card);
3586 card->rtd = devm_kzalloc(card->dev,
3587 sizeof(struct snd_soc_pcm_runtime) *
3588 (card->num_links + card->num_aux_devs),
3590 if (card->rtd == NULL)
3593 card->rtd_aux = &card->rtd[card->num_links];
3595 for (i = 0; i < card->num_links; i++)
3596 card->rtd[i].dai_link = &card->dai_link[i];
3598 INIT_LIST_HEAD(&card->list);
3599 INIT_LIST_HEAD(&card->dapm_dirty);
3600 card->instantiated = 0;
3601 mutex_init(&card->mutex);
3602 mutex_init(&card->dapm_mutex);
3604 ret = snd_soc_instantiate_card(card);
3606 soc_cleanup_card_debugfs(card);
3610 EXPORT_SYMBOL_GPL(snd_soc_register_card);
3613 * snd_soc_unregister_card - Unregister a card with the ASoC core
3615 * @card: Card to unregister
3618 int snd_soc_unregister_card(struct snd_soc_card *card)
3620 if (card->instantiated)
3621 soc_cleanup_card_resources(card);
3622 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
3626 EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
3629 * Simplify DAI link configuration by removing ".-1" from device names
3630 * and sanitizing names.
3632 static char *fmt_single_name(struct device *dev, int *id)
3634 char *found, name[NAME_SIZE];
3637 if (dev_name(dev) == NULL)
3640 strlcpy(name, dev_name(dev), NAME_SIZE);
3642 /* are we a "%s.%d" name (platform and SPI components) */
3643 found = strstr(name, dev->driver->name);
3646 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3648 /* discard ID from name if ID == -1 */
3650 found[strlen(dev->driver->name)] = '\0';
3654 /* I2C component devices are named "bus-addr" */
3655 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3656 char tmp[NAME_SIZE];
3658 /* create unique ID number from I2C addr and bus */
3659 *id = ((id1 & 0xffff) << 16) + id2;
3661 /* sanitize component name for DAI link creation */
3662 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
3663 strlcpy(name, tmp, NAME_SIZE);
3668 return kstrdup(name, GFP_KERNEL);
3672 * Simplify DAI link naming for single devices with multiple DAIs by removing
3673 * any ".-1" and using the DAI name (instead of device name).
3675 static inline char *fmt_multiple_name(struct device *dev,
3676 struct snd_soc_dai_driver *dai_drv)
3678 if (dai_drv->name == NULL) {
3680 "ASoC: error - multiple DAI %s registered with no name\n",
3685 return kstrdup(dai_drv->name, GFP_KERNEL);
3689 * snd_soc_register_dai - Register a DAI with the ASoC core
3691 * @dai: DAI to register
3693 static int snd_soc_register_dai(struct device *dev,
3694 struct snd_soc_dai_driver *dai_drv)
3696 struct snd_soc_codec *codec;
3697 struct snd_soc_dai *dai;
3699 dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
3701 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3705 /* create DAI component name */
3706 dai->name = fmt_single_name(dev, &dai->id);
3707 if (dai->name == NULL) {
3713 dai->driver = dai_drv;
3714 dai->dapm.dev = dev;
3715 if (!dai->driver->ops)
3716 dai->driver->ops = &null_dai_ops;
3718 mutex_lock(&client_mutex);
3720 list_for_each_entry(codec, &codec_list, list) {
3721 if (codec->dev == dev) {
3722 dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
3723 dai->name, codec->name);
3730 dai->dapm.idle_bias_off = 1;
3732 list_add(&dai->list, &dai_list);
3734 mutex_unlock(&client_mutex);
3736 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
3742 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3744 * @dai: DAI to unregister
3746 static void snd_soc_unregister_dai(struct device *dev)
3748 struct snd_soc_dai *dai;
3750 list_for_each_entry(dai, &dai_list, list) {
3751 if (dev == dai->dev)
3757 mutex_lock(&client_mutex);
3758 list_del(&dai->list);
3759 mutex_unlock(&client_mutex);
3761 dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
3767 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3769 * @dai: Array of DAIs to register
3770 * @count: Number of DAIs
3772 static int snd_soc_register_dais(struct device *dev,
3773 struct snd_soc_dai_driver *dai_drv, size_t count)
3775 struct snd_soc_codec *codec;
3776 struct snd_soc_dai *dai;
3779 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
3781 for (i = 0; i < count; i++) {
3783 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3789 /* create DAI component name */
3790 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3791 if (dai->name == NULL) {
3798 dai->driver = &dai_drv[i];
3799 if (dai->driver->id)
3800 dai->id = dai->driver->id;
3803 dai->dapm.dev = dev;
3804 if (!dai->driver->ops)
3805 dai->driver->ops = &null_dai_ops;
3807 mutex_lock(&client_mutex);
3809 list_for_each_entry(codec, &codec_list, list) {
3810 if (codec->dev == dev) {
3812 "ASoC: Mapped DAI %s to CODEC %s\n",
3813 dai->name, codec->name);
3820 dai->dapm.idle_bias_off = 1;
3822 list_add(&dai->list, &dai_list);
3824 mutex_unlock(&client_mutex);
3826 dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name);
3832 for (i--; i >= 0; i--)
3833 snd_soc_unregister_dai(dev);
3839 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3841 * @dai: Array of DAIs to unregister
3842 * @count: Number of DAIs
3844 static void snd_soc_unregister_dais(struct device *dev, size_t count)
3848 for (i = 0; i < count; i++)
3849 snd_soc_unregister_dai(dev);
3853 * snd_soc_add_platform - Add a platform to the ASoC core
3854 * @dev: The parent device for the platform
3855 * @platform: The platform to add
3856 * @platform_driver: The driver for the platform
3858 int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3859 const struct snd_soc_platform_driver *platform_drv)
3861 /* create platform component name */
3862 platform->name = fmt_single_name(dev, &platform->id);
3863 if (platform->name == NULL)
3866 platform->dev = dev;
3867 platform->driver = platform_drv;
3868 platform->dapm.dev = dev;
3869 platform->dapm.platform = platform;
3870 platform->dapm.stream_event = platform_drv->stream_event;
3871 mutex_init(&platform->mutex);
3873 mutex_lock(&client_mutex);
3874 list_add(&platform->list, &platform_list);
3875 mutex_unlock(&client_mutex);
3877 dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name);
3881 EXPORT_SYMBOL_GPL(snd_soc_add_platform);
3884 * snd_soc_register_platform - Register a platform with the ASoC core
3886 * @platform: platform to register
3888 int snd_soc_register_platform(struct device *dev,
3889 const struct snd_soc_platform_driver *platform_drv)
3891 struct snd_soc_platform *platform;
3894 dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
3896 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3897 if (platform == NULL)
3900 ret = snd_soc_add_platform(dev, platform, platform_drv);
3906 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3909 * snd_soc_remove_platform - Remove a platform from the ASoC core
3910 * @platform: the platform to remove
3912 void snd_soc_remove_platform(struct snd_soc_platform *platform)
3914 mutex_lock(&client_mutex);
3915 list_del(&platform->list);
3916 mutex_unlock(&client_mutex);
3918 dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
3920 kfree(platform->name);
3922 EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
3924 struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
3926 struct snd_soc_platform *platform;
3928 list_for_each_entry(platform, &platform_list, list) {
3929 if (dev == platform->dev)
3935 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
3938 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3940 * @platform: platform to unregister
3942 void snd_soc_unregister_platform(struct device *dev)
3944 struct snd_soc_platform *platform;
3946 platform = snd_soc_lookup_platform(dev);
3950 snd_soc_remove_platform(platform);
3953 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3955 static u64 codec_format_map[] = {
3956 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3957 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3958 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3959 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3960 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3961 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3962 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3963 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3964 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3965 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3966 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3967 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3968 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3969 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3970 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3971 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3974 /* Fix up the DAI formats for endianness: codecs don't actually see
3975 * the endianness of the data but we're using the CPU format
3976 * definitions which do need to include endianness so we ensure that
3977 * codec DAIs always have both big and little endian variants set.
3979 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3983 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3984 if (stream->formats & codec_format_map[i])
3985 stream->formats |= codec_format_map[i];
3989 * snd_soc_register_codec - Register a codec with the ASoC core
3991 * @codec: codec to register
3993 int snd_soc_register_codec(struct device *dev,
3994 const struct snd_soc_codec_driver *codec_drv,
3995 struct snd_soc_dai_driver *dai_drv,
3999 struct snd_soc_codec *codec;
4002 dev_dbg(dev, "codec register %s\n", dev_name(dev));
4004 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
4008 /* create CODEC component name */
4009 codec->name = fmt_single_name(dev, &codec->id);
4010 if (codec->name == NULL) {
4015 if (codec_drv->compress_type)
4016 codec->compress_type = codec_drv->compress_type;
4018 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
4020 codec->write = codec_drv->write;
4021 codec->read = codec_drv->read;
4022 codec->volatile_register = codec_drv->volatile_register;
4023 codec->readable_register = codec_drv->readable_register;
4024 codec->writable_register = codec_drv->writable_register;
4025 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
4026 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
4027 codec->dapm.dev = dev;
4028 codec->dapm.codec = codec;
4029 codec->dapm.seq_notifier = codec_drv->seq_notifier;
4030 codec->dapm.stream_event = codec_drv->stream_event;
4032 codec->driver = codec_drv;
4033 codec->num_dai = num_dai;
4034 mutex_init(&codec->mutex);
4036 /* allocate CODEC register cache */
4037 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
4038 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
4039 codec->reg_size = reg_size;
4040 /* it is necessary to make a copy of the default register cache
4041 * because in the case of using a compression type that requires
4042 * the default register cache to be marked as the
4043 * kernel might have freed the array by the time we initialize
4046 if (codec_drv->reg_cache_default) {
4047 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
4048 reg_size, GFP_KERNEL);
4049 if (!codec->reg_def_copy) {
4051 goto fail_codec_name;
4056 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
4057 if (!codec->volatile_register)
4058 codec->volatile_register = snd_soc_default_volatile_register;
4059 if (!codec->readable_register)
4060 codec->readable_register = snd_soc_default_readable_register;
4061 if (!codec->writable_register)
4062 codec->writable_register = snd_soc_default_writable_register;
4065 for (i = 0; i < num_dai; i++) {
4066 fixup_codec_formats(&dai_drv[i].playback);
4067 fixup_codec_formats(&dai_drv[i].capture);
4070 mutex_lock(&client_mutex);
4071 list_add(&codec->list, &codec_list);
4072 mutex_unlock(&client_mutex);
4074 /* register any DAIs */
4075 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4077 dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4078 goto fail_codec_name;
4081 dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name);
4085 mutex_lock(&client_mutex);
4086 list_del(&codec->list);
4087 mutex_unlock(&client_mutex);
4094 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
4097 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4099 * @codec: codec to unregister
4101 void snd_soc_unregister_codec(struct device *dev)
4103 struct snd_soc_codec *codec;
4105 list_for_each_entry(codec, &codec_list, list) {
4106 if (dev == codec->dev)
4112 snd_soc_unregister_dais(dev, codec->num_dai);
4114 mutex_lock(&client_mutex);
4115 list_del(&codec->list);
4116 mutex_unlock(&client_mutex);
4118 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
4120 snd_soc_cache_exit(codec);
4121 kfree(codec->reg_def_copy);
4125 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4129 * snd_soc_register_component - Register a component with the ASoC core
4132 int snd_soc_register_component(struct device *dev,
4133 const struct snd_soc_component_driver *cmpnt_drv,
4134 struct snd_soc_dai_driver *dai_drv,
4137 struct snd_soc_component *cmpnt;
4140 dev_dbg(dev, "component register %s\n", dev_name(dev));
4142 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4144 dev_err(dev, "ASoC: Failed to allocate memory\n");
4148 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4150 dev_err(dev, "ASoC: Failed to simplifying name\n");
4155 cmpnt->driver = cmpnt_drv;
4156 cmpnt->num_dai = num_dai;
4159 * snd_soc_register_dai() uses fmt_single_name(), and
4160 * snd_soc_register_dais() uses fmt_multiple_name()
4161 * for dai->name which is used for name based matching
4164 ret = snd_soc_register_dai(dev, dai_drv);
4166 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4168 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4169 goto error_component_name;
4172 mutex_lock(&client_mutex);
4173 list_add(&cmpnt->list, &component_list);
4174 mutex_unlock(&client_mutex);
4176 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4180 error_component_name:
4185 EXPORT_SYMBOL_GPL(snd_soc_register_component);
4188 * snd_soc_unregister_component - Unregister a component from the ASoC core
4191 void snd_soc_unregister_component(struct device *dev)
4193 struct snd_soc_component *cmpnt;
4195 list_for_each_entry(cmpnt, &component_list, list) {
4196 if (dev == cmpnt->dev)
4202 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4204 mutex_lock(&client_mutex);
4205 list_del(&cmpnt->list);
4206 mutex_unlock(&client_mutex);
4208 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4211 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4213 /* Retrieve a card's name from device tree */
4214 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4215 const char *propname)
4217 struct device_node *np = card->dev->of_node;
4220 ret = of_property_read_string_index(np, propname, 0, &card->name);
4222 * EINVAL means the property does not exist. This is fine providing
4223 * card->name was previously set, which is checked later in
4224 * snd_soc_register_card.
4226 if (ret < 0 && ret != -EINVAL) {
4228 "ASoC: Property '%s' could not be read: %d\n",
4235 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4237 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4238 const char *propname)
4240 struct device_node *np = card->dev->of_node;
4242 struct snd_soc_dapm_route *routes;
4245 num_routes = of_property_count_strings(np, propname);
4246 if (num_routes < 0 || num_routes & 1) {
4248 "ASoC: Property '%s' does not exist or its length is not even\n",
4254 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
4259 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
4263 "ASoC: Could not allocate DAPM route table\n");
4267 for (i = 0; i < num_routes; i++) {
4268 ret = of_property_read_string_index(np, propname,
4269 2 * i, &routes[i].sink);
4272 "ASoC: Property '%s' index %d could not be read: %d\n",
4273 propname, 2 * i, ret);
4276 ret = of_property_read_string_index(np, propname,
4277 (2 * i) + 1, &routes[i].source);
4280 "ASoC: Property '%s' index %d could not be read: %d\n",
4281 propname, (2 * i) + 1, ret);
4286 card->num_dapm_routes = num_routes;
4287 card->dapm_routes = routes;
4291 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4293 unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4298 unsigned int format = 0;
4304 } of_fmt_table[] = {
4305 { "i2s", SND_SOC_DAIFMT_I2S },
4306 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
4307 { "left_j", SND_SOC_DAIFMT_LEFT_J },
4308 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
4309 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
4310 { "ac97", SND_SOC_DAIFMT_AC97 },
4311 { "pdm", SND_SOC_DAIFMT_PDM},
4312 { "msb", SND_SOC_DAIFMT_MSB },
4313 { "lsb", SND_SOC_DAIFMT_LSB },
4320 * check "[prefix]format = xxx"
4321 * SND_SOC_DAIFMT_FORMAT_MASK area
4323 snprintf(prop, sizeof(prop), "%sformat", prefix);
4324 ret = of_property_read_string(np, prop, &str);
4326 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
4327 if (strcmp(str, of_fmt_table[i].name) == 0) {
4328 format |= of_fmt_table[i].val;
4335 * check "[prefix]continuous-clock"
4336 * SND_SOC_DAIFMT_CLOCK_MASK area
4338 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
4339 if (of_get_property(np, prop, NULL))
4340 format |= SND_SOC_DAIFMT_CONT;
4342 format |= SND_SOC_DAIFMT_GATED;
4345 * check "[prefix]bitclock-inversion"
4346 * check "[prefix]frame-inversion"
4347 * SND_SOC_DAIFMT_INV_MASK area
4349 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
4350 bit = !!of_get_property(np, prop, NULL);
4352 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
4353 frame = !!of_get_property(np, prop, NULL);
4355 switch ((bit << 4) + frame) {
4357 format |= SND_SOC_DAIFMT_IB_IF;
4360 format |= SND_SOC_DAIFMT_IB_NF;
4363 format |= SND_SOC_DAIFMT_NB_IF;
4366 /* SND_SOC_DAIFMT_NB_NF is default */
4371 * check "[prefix]bitclock-master"
4372 * check "[prefix]frame-master"
4373 * SND_SOC_DAIFMT_MASTER_MASK area
4375 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
4376 bit = !!of_get_property(np, prop, NULL);
4378 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
4379 frame = !!of_get_property(np, prop, NULL);
4381 switch ((bit << 4) + frame) {
4383 format |= SND_SOC_DAIFMT_CBM_CFM;
4386 format |= SND_SOC_DAIFMT_CBM_CFS;
4389 format |= SND_SOC_DAIFMT_CBS_CFM;
4392 format |= SND_SOC_DAIFMT_CBS_CFS;
4398 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4400 static int __init snd_soc_init(void)
4402 #ifdef CONFIG_DEBUG_FS
4403 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
4404 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
4405 pr_warn("ASoC: Failed to create debugfs directory\n");
4406 snd_soc_debugfs_root = NULL;
4409 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
4411 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4413 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
4415 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4417 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
4418 &platform_list_fops))
4419 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4422 snd_soc_util_init();
4424 return platform_driver_register(&soc_driver);
4426 module_init(snd_soc_init);
4428 static void __exit snd_soc_exit(void)
4430 snd_soc_util_exit();
4432 #ifdef CONFIG_DEBUG_FS
4433 debugfs_remove_recursive(snd_soc_debugfs_root);
4435 platform_driver_unregister(&soc_driver);
4437 module_exit(snd_soc_exit);
4439 /* Module information */
4440 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4441 MODULE_DESCRIPTION("ALSA SoC Core");
4442 MODULE_LICENSE("GPL");
4443 MODULE_ALIAS("platform:soc-audio");