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 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
52 #ifdef CONFIG_DEBUG_FS
53 struct dentry
*snd_soc_debugfs_root
;
54 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
57 static DEFINE_MUTEX(client_mutex
);
58 static LIST_HEAD(dai_list
);
59 static LIST_HEAD(platform_list
);
60 static LIST_HEAD(codec_list
);
61 static LIST_HEAD(component_list
);
64 * This is a timeout to do a DAPM powerdown after a stream is closed().
65 * It can be used to eliminate pops between different playback streams, e.g.
66 * between two audio tracks.
68 static int pmdown_time
= 5000;
69 module_param(pmdown_time
, int, 0);
70 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
72 /* returns the minimum number of bytes needed to represent
73 * a particular given value */
74 static int min_bytes_needed(unsigned long val
)
79 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
82 c
= (sizeof val
* 8) - c
;
90 /* fill buf which is 'len' bytes with a formatted
91 * string of the form 'reg: value\n' */
92 static int format_register_str(struct snd_soc_codec
*codec
,
93 unsigned int reg
, char *buf
, size_t len
)
95 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
96 int regsize
= codec
->driver
->reg_word_size
* 2;
99 char regbuf
[regsize
+ 1];
101 /* since tmpbuf is allocated on the stack, warn the callers if they
102 * try to abuse this function */
105 /* +2 for ': ' and + 1 for '\n' */
106 if (wordsize
+ regsize
+ 2 + 1 != len
)
109 ret
= snd_soc_read(codec
, reg
);
111 memset(regbuf
, 'X', regsize
);
112 regbuf
[regsize
] = '\0';
114 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
117 /* prepare the buffer */
118 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
119 /* copy it back to the caller without the '\0' */
120 memcpy(buf
, tmpbuf
, len
);
125 /* codec register dump */
126 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
127 size_t count
, loff_t pos
)
130 int wordsize
, regsize
;
135 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
136 regsize
= codec
->driver
->reg_word_size
* 2;
138 len
= wordsize
+ regsize
+ 2 + 1;
140 if (!codec
->driver
->reg_cache_size
)
143 if (codec
->driver
->reg_cache_step
)
144 step
= codec
->driver
->reg_cache_step
;
146 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
147 if (!snd_soc_codec_readable_register(codec
, i
))
149 if (codec
->driver
->display_register
) {
150 count
+= codec
->driver
->display_register(codec
, buf
+ count
,
151 PAGE_SIZE
- count
, i
);
153 /* only support larger than PAGE_SIZE bytes debugfs
154 * entries for the default case */
156 if (total
+ len
>= count
- 1)
158 format_register_str(codec
, i
, buf
+ total
, len
);
165 total
= min(total
, count
- 1);
170 static ssize_t
codec_reg_show(struct device
*dev
,
171 struct device_attribute
*attr
, char *buf
)
173 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
175 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
178 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
180 static ssize_t
pmdown_time_show(struct device
*dev
,
181 struct device_attribute
*attr
, char *buf
)
183 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
185 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
188 static ssize_t
pmdown_time_set(struct device
*dev
,
189 struct device_attribute
*attr
,
190 const char *buf
, size_t count
)
192 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
195 ret
= kstrtol(buf
, 10, &rtd
->pmdown_time
);
202 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
204 #ifdef CONFIG_DEBUG_FS
205 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
206 size_t count
, loff_t
*ppos
)
209 struct snd_soc_codec
*codec
= file
->private_data
;
212 if (*ppos
< 0 || !count
)
215 buf
= kmalloc(count
, GFP_KERNEL
);
219 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
221 if (copy_to_user(user_buf
, buf
, ret
)) {
232 static ssize_t
codec_reg_write_file(struct file
*file
,
233 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
238 unsigned long reg
, value
;
239 struct snd_soc_codec
*codec
= file
->private_data
;
242 buf_size
= min(count
, (sizeof(buf
)-1));
243 if (copy_from_user(buf
, user_buf
, buf_size
))
247 while (*start
== ' ')
249 reg
= simple_strtoul(start
, &start
, 16);
250 while (*start
== ' ')
252 ret
= kstrtoul(start
, 16, &value
);
256 /* Userspace has been fiddling around behind the kernel's back */
257 add_taint(TAINT_USER
, LOCKDEP_NOW_UNRELIABLE
);
259 snd_soc_write(codec
, reg
, value
);
263 static const struct file_operations codec_reg_fops
= {
265 .read
= codec_reg_read_file
,
266 .write
= codec_reg_write_file
,
267 .llseek
= default_llseek
,
270 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
272 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
274 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
276 if (!codec
->debugfs_codec_root
) {
278 "ASoC: Failed to create codec debugfs directory\n");
282 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
284 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
287 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
288 codec
->debugfs_codec_root
,
289 codec
, &codec_reg_fops
);
290 if (!codec
->debugfs_reg
)
292 "ASoC: Failed to create codec register debugfs file\n");
294 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
297 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
299 debugfs_remove_recursive(codec
->debugfs_codec_root
);
302 static void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
304 struct dentry
*debugfs_card_root
= platform
->card
->debugfs_card_root
;
306 platform
->debugfs_platform_root
= debugfs_create_dir(platform
->name
,
308 if (!platform
->debugfs_platform_root
) {
309 dev_warn(platform
->dev
,
310 "ASoC: Failed to create platform debugfs directory\n");
314 snd_soc_dapm_debugfs_init(&platform
->dapm
,
315 platform
->debugfs_platform_root
);
318 static void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
320 debugfs_remove_recursive(platform
->debugfs_platform_root
);
323 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
324 size_t count
, loff_t
*ppos
)
326 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
327 ssize_t len
, ret
= 0;
328 struct snd_soc_codec
*codec
;
333 list_for_each_entry(codec
, &codec_list
, list
) {
334 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
338 if (ret
> PAGE_SIZE
) {
345 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
352 static const struct file_operations codec_list_fops
= {
353 .read
= codec_list_read_file
,
354 .llseek
= default_llseek
,/* read accesses f_pos */
357 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
358 size_t count
, loff_t
*ppos
)
360 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
361 ssize_t len
, ret
= 0;
362 struct snd_soc_dai
*dai
;
367 list_for_each_entry(dai
, &dai_list
, list
) {
368 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
371 if (ret
> PAGE_SIZE
) {
377 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
384 static const struct file_operations dai_list_fops
= {
385 .read
= dai_list_read_file
,
386 .llseek
= default_llseek
,/* read accesses f_pos */
389 static ssize_t
platform_list_read_file(struct file
*file
,
390 char __user
*user_buf
,
391 size_t count
, loff_t
*ppos
)
393 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
394 ssize_t len
, ret
= 0;
395 struct snd_soc_platform
*platform
;
400 list_for_each_entry(platform
, &platform_list
, list
) {
401 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
405 if (ret
> PAGE_SIZE
) {
411 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
418 static const struct file_operations platform_list_fops
= {
419 .read
= platform_list_read_file
,
420 .llseek
= default_llseek
,/* read accesses f_pos */
423 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
425 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
426 snd_soc_debugfs_root
);
427 if (!card
->debugfs_card_root
) {
429 "ASoC: Failed to create card debugfs directory\n");
433 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
434 card
->debugfs_card_root
,
436 if (!card
->debugfs_pop_time
)
438 "ASoC: Failed to create pop time debugfs file\n");
441 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
443 debugfs_remove_recursive(card
->debugfs_card_root
);
448 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
452 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
456 static inline void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
460 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
464 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
468 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
473 struct snd_pcm_substream
*snd_soc_get_dai_substream(struct snd_soc_card
*card
,
474 const char *dai_link
, int stream
)
478 for (i
= 0; i
< card
->num_links
; i
++) {
479 if (card
->rtd
[i
].dai_link
->no_pcm
&&
480 !strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
481 return card
->rtd
[i
].pcm
->streams
[stream
].substream
;
483 dev_dbg(card
->dev
, "ASoC: failed to find dai link %s\n", dai_link
);
486 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream
);
488 struct snd_soc_pcm_runtime
*snd_soc_get_pcm_runtime(struct snd_soc_card
*card
,
489 const char *dai_link
)
493 for (i
= 0; i
< card
->num_links
; i
++) {
494 if (!strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
495 return &card
->rtd
[i
];
497 dev_dbg(card
->dev
, "ASoC: failed to find rtd %s\n", dai_link
);
500 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime
);
502 #ifdef CONFIG_SND_SOC_AC97_BUS
503 /* unregister ac97 codec */
504 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
506 if (codec
->ac97
->dev
.bus
)
507 device_unregister(&codec
->ac97
->dev
);
511 /* stop no dev release warning */
512 static void soc_ac97_device_release(struct device
*dev
){}
514 /* register ac97 codec to bus */
515 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
519 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
520 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
521 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
523 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
524 codec
->card
->snd_card
->number
, 0, codec
->name
);
525 err
= device_register(&codec
->ac97
->dev
);
527 dev_err(codec
->dev
, "ASoC: Can't register ac97 bus\n");
528 codec
->ac97
->dev
.bus
= NULL
;
535 #ifdef CONFIG_PM_SLEEP
536 /* powers down audio subsystem for suspend */
537 int snd_soc_suspend(struct device
*dev
)
539 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
540 struct snd_soc_codec
*codec
;
543 /* If the initialization of this soc device failed, there is no codec
544 * associated with it. Just bail out in this case.
546 if (list_empty(&card
->codec_dev_list
))
549 /* Due to the resume being scheduled into a workqueue we could
550 * suspend before that's finished - wait for it to complete.
552 snd_power_lock(card
->snd_card
);
553 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
554 snd_power_unlock(card
->snd_card
);
556 /* we're going to block userspace touching us until resume completes */
557 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
559 /* mute any active DACs */
560 for (i
= 0; i
< card
->num_rtd
; i
++) {
561 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
562 struct snd_soc_dai_driver
*drv
= dai
->driver
;
564 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
567 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
568 drv
->ops
->digital_mute(dai
, 1);
571 /* suspend all pcms */
572 for (i
= 0; i
< card
->num_rtd
; i
++) {
573 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
576 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
579 if (card
->suspend_pre
)
580 card
->suspend_pre(card
);
582 for (i
= 0; i
< card
->num_rtd
; i
++) {
583 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
584 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
586 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
589 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
590 cpu_dai
->driver
->suspend(cpu_dai
);
591 if (platform
->driver
->suspend
&& !platform
->suspended
) {
592 platform
->driver
->suspend(cpu_dai
);
593 platform
->suspended
= 1;
597 /* close any waiting streams and save state */
598 for (i
= 0; i
< card
->num_rtd
; i
++) {
599 flush_delayed_work(&card
->rtd
[i
].delayed_work
);
600 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
603 for (i
= 0; i
< card
->num_rtd
; i
++) {
605 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
608 snd_soc_dapm_stream_event(&card
->rtd
[i
],
609 SNDRV_PCM_STREAM_PLAYBACK
,
610 SND_SOC_DAPM_STREAM_SUSPEND
);
612 snd_soc_dapm_stream_event(&card
->rtd
[i
],
613 SNDRV_PCM_STREAM_CAPTURE
,
614 SND_SOC_DAPM_STREAM_SUSPEND
);
617 /* Recheck all analogue paths too */
618 dapm_mark_io_dirty(&card
->dapm
);
619 snd_soc_dapm_sync(&card
->dapm
);
621 /* suspend all CODECs */
622 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
623 /* If there are paths active then the CODEC will be held with
624 * bias _ON and should not be suspended. */
625 if (!codec
->suspended
&& codec
->driver
->suspend
) {
626 switch (codec
->dapm
.bias_level
) {
627 case SND_SOC_BIAS_STANDBY
:
629 * If the CODEC is capable of idle
630 * bias off then being in STANDBY
631 * means it's doing something,
632 * otherwise fall through.
634 if (codec
->dapm
.idle_bias_off
) {
636 "ASoC: idle_bias_off CODEC on over suspend\n");
639 case SND_SOC_BIAS_OFF
:
640 codec
->driver
->suspend(codec
);
641 codec
->suspended
= 1;
642 codec
->cache_sync
= 1;
643 if (codec
->using_regmap
)
644 regcache_mark_dirty(codec
->control_data
);
648 "ASoC: CODEC is on over suspend\n");
654 for (i
= 0; i
< card
->num_rtd
; i
++) {
655 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
657 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
660 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
661 cpu_dai
->driver
->suspend(cpu_dai
);
664 if (card
->suspend_post
)
665 card
->suspend_post(card
);
669 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
671 /* deferred resume work, so resume can complete before we finished
672 * setting our codec back up, which can be very slow on I2C
674 static void soc_resume_deferred(struct work_struct
*work
)
676 struct snd_soc_card
*card
=
677 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
678 struct snd_soc_codec
*codec
;
681 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
682 * so userspace apps are blocked from touching us
685 dev_dbg(card
->dev
, "ASoC: starting resume work\n");
687 /* Bring us up into D2 so that DAPM starts enabling things */
688 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
690 if (card
->resume_pre
)
691 card
->resume_pre(card
);
693 /* resume AC97 DAIs */
694 for (i
= 0; i
< card
->num_rtd
; i
++) {
695 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
697 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
700 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
701 cpu_dai
->driver
->resume(cpu_dai
);
704 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
705 /* If the CODEC was idle over suspend then it will have been
706 * left with bias OFF or STANDBY and suspended so we must now
707 * resume. Otherwise the suspend was suppressed.
709 if (codec
->driver
->resume
&& codec
->suspended
) {
710 switch (codec
->dapm
.bias_level
) {
711 case SND_SOC_BIAS_STANDBY
:
712 case SND_SOC_BIAS_OFF
:
713 codec
->driver
->resume(codec
);
714 codec
->suspended
= 0;
718 "ASoC: CODEC was on over suspend\n");
724 for (i
= 0; i
< card
->num_rtd
; i
++) {
726 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
729 snd_soc_dapm_stream_event(&card
->rtd
[i
],
730 SNDRV_PCM_STREAM_PLAYBACK
,
731 SND_SOC_DAPM_STREAM_RESUME
);
733 snd_soc_dapm_stream_event(&card
->rtd
[i
],
734 SNDRV_PCM_STREAM_CAPTURE
,
735 SND_SOC_DAPM_STREAM_RESUME
);
738 /* unmute any active DACs */
739 for (i
= 0; i
< card
->num_rtd
; i
++) {
740 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
741 struct snd_soc_dai_driver
*drv
= dai
->driver
;
743 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
746 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
747 drv
->ops
->digital_mute(dai
, 0);
750 for (i
= 0; i
< card
->num_rtd
; i
++) {
751 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
752 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
754 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
757 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
758 cpu_dai
->driver
->resume(cpu_dai
);
759 if (platform
->driver
->resume
&& platform
->suspended
) {
760 platform
->driver
->resume(cpu_dai
);
761 platform
->suspended
= 0;
765 if (card
->resume_post
)
766 card
->resume_post(card
);
768 dev_dbg(card
->dev
, "ASoC: resume work completed\n");
770 /* userspace can access us now we are back as we were before */
771 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
773 /* Recheck all analogue paths too */
774 dapm_mark_io_dirty(&card
->dapm
);
775 snd_soc_dapm_sync(&card
->dapm
);
778 /* powers up audio subsystem after a suspend */
779 int snd_soc_resume(struct device
*dev
)
781 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
782 int i
, ac97_control
= 0;
784 /* If the initialization of this soc device failed, there is no codec
785 * associated with it. Just bail out in this case.
787 if (list_empty(&card
->codec_dev_list
))
790 /* AC97 devices might have other drivers hanging off them so
791 * need to resume immediately. Other drivers don't have that
792 * problem and may take a substantial amount of time to resume
793 * due to I/O costs and anti-pop so handle them out of line.
795 for (i
= 0; i
< card
->num_rtd
; i
++) {
796 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
797 ac97_control
|= cpu_dai
->driver
->ac97_control
;
800 dev_dbg(dev
, "ASoC: Resuming AC97 immediately\n");
801 soc_resume_deferred(&card
->deferred_resume_work
);
803 dev_dbg(dev
, "ASoC: Scheduling resume work\n");
804 if (!schedule_work(&card
->deferred_resume_work
))
805 dev_err(dev
, "ASoC: resume work item may be lost\n");
810 EXPORT_SYMBOL_GPL(snd_soc_resume
);
812 #define snd_soc_suspend NULL
813 #define snd_soc_resume NULL
816 static const struct snd_soc_dai_ops null_dai_ops
= {
819 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
821 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
822 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
823 struct snd_soc_codec
*codec
;
824 struct snd_soc_platform
*platform
;
825 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
826 const char *platform_name
;
828 dev_dbg(card
->dev
, "ASoC: binding %s at idx %d\n", dai_link
->name
, num
);
830 /* Find CPU DAI from registered DAIs*/
831 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
832 if (dai_link
->cpu_of_node
&&
833 (cpu_dai
->dev
->of_node
!= dai_link
->cpu_of_node
))
835 if (dai_link
->cpu_name
&&
836 strcmp(dev_name(cpu_dai
->dev
), dai_link
->cpu_name
))
838 if (dai_link
->cpu_dai_name
&&
839 strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
))
842 rtd
->cpu_dai
= cpu_dai
;
846 dev_err(card
->dev
, "ASoC: CPU DAI %s not registered\n",
847 dai_link
->cpu_dai_name
);
848 return -EPROBE_DEFER
;
851 /* Find CODEC from registered CODECs */
852 list_for_each_entry(codec
, &codec_list
, list
) {
853 if (dai_link
->codec_of_node
) {
854 if (codec
->dev
->of_node
!= dai_link
->codec_of_node
)
857 if (strcmp(codec
->name
, dai_link
->codec_name
))
864 * CODEC found, so find CODEC DAI from registered DAIs from
867 list_for_each_entry(codec_dai
, &dai_list
, list
) {
868 if (codec
->dev
== codec_dai
->dev
&&
869 !strcmp(codec_dai
->name
,
870 dai_link
->codec_dai_name
)) {
872 rtd
->codec_dai
= codec_dai
;
876 if (!rtd
->codec_dai
) {
877 dev_err(card
->dev
, "ASoC: CODEC DAI %s not registered\n",
878 dai_link
->codec_dai_name
);
879 return -EPROBE_DEFER
;
884 dev_err(card
->dev
, "ASoC: CODEC %s not registered\n",
885 dai_link
->codec_name
);
886 return -EPROBE_DEFER
;
889 /* if there's no platform we match on the empty platform */
890 platform_name
= dai_link
->platform_name
;
891 if (!platform_name
&& !dai_link
->platform_of_node
)
892 platform_name
= "snd-soc-dummy";
894 /* find one from the set of registered platforms */
895 list_for_each_entry(platform
, &platform_list
, list
) {
896 if (dai_link
->platform_of_node
) {
897 if (platform
->dev
->of_node
!=
898 dai_link
->platform_of_node
)
901 if (strcmp(platform
->name
, platform_name
))
905 rtd
->platform
= platform
;
907 if (!rtd
->platform
) {
908 dev_err(card
->dev
, "ASoC: platform %s not registered\n",
909 dai_link
->platform_name
);
910 return -EPROBE_DEFER
;
918 static int soc_remove_platform(struct snd_soc_platform
*platform
)
922 if (platform
->driver
->remove
) {
923 ret
= platform
->driver
->remove(platform
);
925 dev_err(platform
->dev
, "ASoC: failed to remove %d\n",
929 /* Make sure all DAPM widgets are freed */
930 snd_soc_dapm_free(&platform
->dapm
);
932 soc_cleanup_platform_debugfs(platform
);
933 platform
->probed
= 0;
934 list_del(&platform
->card_list
);
935 module_put(platform
->dev
->driver
->owner
);
940 static void soc_remove_codec(struct snd_soc_codec
*codec
)
944 if (codec
->driver
->remove
) {
945 err
= codec
->driver
->remove(codec
);
947 dev_err(codec
->dev
, "ASoC: failed to remove %d\n", err
);
950 /* Make sure all DAPM widgets are freed */
951 snd_soc_dapm_free(&codec
->dapm
);
953 soc_cleanup_codec_debugfs(codec
);
955 list_del(&codec
->card_list
);
956 module_put(codec
->dev
->driver
->owner
);
959 static void soc_remove_link_dais(struct snd_soc_card
*card
, int num
, int order
)
961 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
962 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
965 /* unregister the rtd device */
966 if (rtd
->dev_registered
) {
967 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
968 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
969 device_unregister(rtd
->dev
);
970 rtd
->dev_registered
= 0;
973 /* remove the CODEC DAI */
974 if (codec_dai
&& codec_dai
->probed
&&
975 codec_dai
->driver
->remove_order
== order
) {
976 if (codec_dai
->driver
->remove
) {
977 err
= codec_dai
->driver
->remove(codec_dai
);
979 dev_err(codec_dai
->dev
,
980 "ASoC: failed to remove %s: %d\n",
981 codec_dai
->name
, err
);
983 codec_dai
->probed
= 0;
984 list_del(&codec_dai
->card_list
);
987 /* remove the cpu_dai */
988 if (cpu_dai
&& cpu_dai
->probed
&&
989 cpu_dai
->driver
->remove_order
== order
) {
990 if (cpu_dai
->driver
->remove
) {
991 err
= cpu_dai
->driver
->remove(cpu_dai
);
993 dev_err(cpu_dai
->dev
,
994 "ASoC: failed to remove %s: %d\n",
998 list_del(&cpu_dai
->card_list
);
1000 if (!cpu_dai
->codec
) {
1001 snd_soc_dapm_free(&cpu_dai
->dapm
);
1002 module_put(cpu_dai
->dev
->driver
->owner
);
1007 static void soc_remove_link_components(struct snd_soc_card
*card
, int num
,
1010 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1011 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1012 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1013 struct snd_soc_platform
*platform
= rtd
->platform
;
1014 struct snd_soc_codec
*codec
;
1016 /* remove the platform */
1017 if (platform
&& platform
->probed
&&
1018 platform
->driver
->remove_order
== order
) {
1019 soc_remove_platform(platform
);
1022 /* remove the CODEC-side CODEC */
1024 codec
= codec_dai
->codec
;
1025 if (codec
&& codec
->probed
&&
1026 codec
->driver
->remove_order
== order
)
1027 soc_remove_codec(codec
);
1030 /* remove any CPU-side CODEC */
1032 codec
= cpu_dai
->codec
;
1033 if (codec
&& codec
->probed
&&
1034 codec
->driver
->remove_order
== order
)
1035 soc_remove_codec(codec
);
1039 static void soc_remove_dai_links(struct snd_soc_card
*card
)
1043 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1045 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1046 soc_remove_link_dais(card
, dai
, order
);
1049 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1051 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1052 soc_remove_link_components(card
, dai
, order
);
1058 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1059 struct snd_soc_codec
*codec
)
1063 if (card
->codec_conf
== NULL
)
1066 for (i
= 0; i
< card
->num_configs
; i
++) {
1067 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1068 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
1069 codec
->name_prefix
= map
->name_prefix
;
1075 static int soc_probe_codec(struct snd_soc_card
*card
,
1076 struct snd_soc_codec
*codec
)
1079 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
1080 struct snd_soc_dai
*dai
;
1083 codec
->dapm
.card
= card
;
1084 soc_set_name_prefix(card
, codec
);
1086 if (!try_module_get(codec
->dev
->driver
->owner
))
1089 soc_init_codec_debugfs(codec
);
1091 if (driver
->dapm_widgets
)
1092 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
1093 driver
->num_dapm_widgets
);
1095 /* Create DAPM widgets for each DAI stream */
1096 list_for_each_entry(dai
, &dai_list
, list
) {
1097 if (dai
->dev
!= codec
->dev
)
1100 snd_soc_dapm_new_dai_widgets(&codec
->dapm
, dai
);
1103 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
1105 if (driver
->probe
) {
1106 ret
= driver
->probe(codec
);
1109 "ASoC: failed to probe CODEC %d\n", ret
);
1112 WARN(codec
->dapm
.idle_bias_off
&&
1113 codec
->dapm
.bias_level
!= SND_SOC_BIAS_OFF
,
1114 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1118 /* If the driver didn't set I/O up try regmap */
1119 if (!codec
->write
&& dev_get_regmap(codec
->dev
, NULL
))
1120 snd_soc_codec_set_cache_io(codec
, 0, 0, SND_SOC_REGMAP
);
1122 if (driver
->controls
)
1123 snd_soc_add_codec_controls(codec
, driver
->controls
,
1124 driver
->num_controls
);
1125 if (driver
->dapm_routes
)
1126 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1127 driver
->num_dapm_routes
);
1129 /* mark codec as probed and add to card codec list */
1131 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1132 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1137 soc_cleanup_codec_debugfs(codec
);
1138 module_put(codec
->dev
->driver
->owner
);
1143 static int soc_probe_platform(struct snd_soc_card
*card
,
1144 struct snd_soc_platform
*platform
)
1147 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1148 struct snd_soc_dai
*dai
;
1150 platform
->card
= card
;
1151 platform
->dapm
.card
= card
;
1153 if (!try_module_get(platform
->dev
->driver
->owner
))
1156 soc_init_platform_debugfs(platform
);
1158 if (driver
->dapm_widgets
)
1159 snd_soc_dapm_new_controls(&platform
->dapm
,
1160 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1162 /* Create DAPM widgets for each DAI stream */
1163 list_for_each_entry(dai
, &dai_list
, list
) {
1164 if (dai
->dev
!= platform
->dev
)
1167 snd_soc_dapm_new_dai_widgets(&platform
->dapm
, dai
);
1170 platform
->dapm
.idle_bias_off
= 1;
1172 if (driver
->probe
) {
1173 ret
= driver
->probe(platform
);
1175 dev_err(platform
->dev
,
1176 "ASoC: failed to probe platform %d\n", ret
);
1181 if (driver
->controls
)
1182 snd_soc_add_platform_controls(platform
, driver
->controls
,
1183 driver
->num_controls
);
1184 if (driver
->dapm_routes
)
1185 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1186 driver
->num_dapm_routes
);
1188 /* mark platform as probed and add to card platform list */
1189 platform
->probed
= 1;
1190 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1191 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1196 soc_cleanup_platform_debugfs(platform
);
1197 module_put(platform
->dev
->driver
->owner
);
1202 static void rtd_release(struct device
*dev
)
1207 static int soc_post_component_init(struct snd_soc_card
*card
,
1208 struct snd_soc_codec
*codec
,
1209 int num
, int dailess
)
1211 struct snd_soc_dai_link
*dai_link
= NULL
;
1212 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1213 struct snd_soc_pcm_runtime
*rtd
;
1214 const char *temp
, *name
;
1218 dai_link
= &card
->dai_link
[num
];
1219 rtd
= &card
->rtd
[num
];
1220 name
= dai_link
->name
;
1222 aux_dev
= &card
->aux_dev
[num
];
1223 rtd
= &card
->rtd_aux
[num
];
1224 name
= aux_dev
->name
;
1228 /* Make sure all DAPM widgets are instantiated */
1229 snd_soc_dapm_new_widgets(&codec
->dapm
);
1231 /* machine controls, routes and widgets are not prefixed */
1232 temp
= codec
->name_prefix
;
1233 codec
->name_prefix
= NULL
;
1235 /* do machine specific initialization */
1236 if (!dailess
&& dai_link
->init
)
1237 ret
= dai_link
->init(rtd
);
1238 else if (dailess
&& aux_dev
->init
)
1239 ret
= aux_dev
->init(&codec
->dapm
);
1241 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n", name
, ret
);
1244 codec
->name_prefix
= temp
;
1246 /* register the rtd device */
1249 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1252 device_initialize(rtd
->dev
);
1253 rtd
->dev
->parent
= card
->dev
;
1254 rtd
->dev
->release
= rtd_release
;
1255 rtd
->dev
->init_name
= name
;
1256 dev_set_drvdata(rtd
->dev
, rtd
);
1257 mutex_init(&rtd
->pcm_mutex
);
1258 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1259 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1260 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1261 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1262 ret
= device_add(rtd
->dev
);
1264 /* calling put_device() here to free the rtd->dev */
1265 put_device(rtd
->dev
);
1267 "ASoC: failed to register runtime device: %d\n", ret
);
1270 rtd
->dev_registered
= 1;
1272 /* add DAPM sysfs entries for this codec */
1273 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1276 "ASoC: failed to add codec dapm sysfs entries: %d\n", ret
);
1278 /* add codec sysfs entries */
1279 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1282 "ASoC: failed to add codec sysfs files: %d\n", ret
);
1284 #ifdef CONFIG_DEBUG_FS
1285 /* add DPCM sysfs entries */
1286 if (!dailess
&& !dai_link
->dynamic
)
1289 ret
= soc_dpcm_debugfs_add(rtd
);
1291 dev_err(rtd
->dev
, "ASoC: failed to add dpcm sysfs entries: %d\n", ret
);
1298 static int soc_probe_link_components(struct snd_soc_card
*card
, int num
,
1301 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1302 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1303 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1304 struct snd_soc_platform
*platform
= rtd
->platform
;
1307 /* probe the CPU-side component, if it is a CODEC */
1308 if (cpu_dai
->codec
&&
1309 !cpu_dai
->codec
->probed
&&
1310 cpu_dai
->codec
->driver
->probe_order
== order
) {
1311 ret
= soc_probe_codec(card
, cpu_dai
->codec
);
1316 /* probe the CODEC-side component */
1317 if (!codec_dai
->codec
->probed
&&
1318 codec_dai
->codec
->driver
->probe_order
== order
) {
1319 ret
= soc_probe_codec(card
, codec_dai
->codec
);
1324 /* probe the platform */
1325 if (!platform
->probed
&&
1326 platform
->driver
->probe_order
== order
) {
1327 ret
= soc_probe_platform(card
, platform
);
1335 static int soc_probe_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1337 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1338 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1339 struct snd_soc_codec
*codec
= rtd
->codec
;
1340 struct snd_soc_platform
*platform
= rtd
->platform
;
1341 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1342 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1343 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1346 dev_dbg(card
->dev
, "ASoC: probe %s dai link %d late %d\n",
1347 card
->name
, num
, order
);
1349 /* config components */
1350 cpu_dai
->platform
= platform
;
1351 codec_dai
->card
= card
;
1352 cpu_dai
->card
= card
;
1354 /* set default power off timeout */
1355 rtd
->pmdown_time
= pmdown_time
;
1357 /* probe the cpu_dai */
1358 if (!cpu_dai
->probed
&&
1359 cpu_dai
->driver
->probe_order
== order
) {
1360 if (!cpu_dai
->codec
) {
1361 cpu_dai
->dapm
.card
= card
;
1362 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1365 list_add(&cpu_dai
->dapm
.list
, &card
->dapm_list
);
1366 snd_soc_dapm_new_dai_widgets(&cpu_dai
->dapm
, cpu_dai
);
1369 if (cpu_dai
->driver
->probe
) {
1370 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1372 dev_err(cpu_dai
->dev
,
1373 "ASoC: failed to probe CPU DAI %s: %d\n",
1374 cpu_dai
->name
, ret
);
1375 module_put(cpu_dai
->dev
->driver
->owner
);
1379 cpu_dai
->probed
= 1;
1380 /* mark cpu_dai as probed and add to card dai list */
1381 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1384 /* probe the CODEC DAI */
1385 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1386 if (codec_dai
->driver
->probe
) {
1387 ret
= codec_dai
->driver
->probe(codec_dai
);
1389 dev_err(codec_dai
->dev
,
1390 "ASoC: failed to probe CODEC DAI %s: %d\n",
1391 codec_dai
->name
, ret
);
1396 /* mark codec_dai as probed and add to card dai list */
1397 codec_dai
->probed
= 1;
1398 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1401 /* complete DAI probe during last probe */
1402 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1405 ret
= soc_post_component_init(card
, codec
, num
, 0);
1409 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1411 dev_warn(rtd
->dev
, "ASoC: failed to add pmdown_time sysfs: %d\n",
1414 if (cpu_dai
->driver
->compress_dai
) {
1415 /*create compress_device"*/
1416 ret
= soc_new_compress(rtd
, num
);
1418 dev_err(card
->dev
, "ASoC: can't create compress %s\n",
1419 dai_link
->stream_name
);
1424 if (!dai_link
->params
) {
1425 /* create the pcm */
1426 ret
= soc_new_pcm(rtd
, num
);
1428 dev_err(card
->dev
, "ASoC: can't create pcm %s :%d\n",
1429 dai_link
->stream_name
, ret
);
1433 /* link the DAI widgets */
1434 play_w
= codec_dai
->playback_widget
;
1435 capture_w
= cpu_dai
->capture_widget
;
1436 if (play_w
&& capture_w
) {
1437 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1440 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1441 play_w
->name
, capture_w
->name
, ret
);
1446 play_w
= cpu_dai
->playback_widget
;
1447 capture_w
= codec_dai
->capture_widget
;
1448 if (play_w
&& capture_w
) {
1449 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1452 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1453 play_w
->name
, capture_w
->name
, ret
);
1460 /* add platform data for AC97 devices */
1461 if (rtd
->codec_dai
->driver
->ac97_control
)
1462 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1467 #ifdef CONFIG_SND_SOC_AC97_BUS
1468 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1472 /* Only instantiate AC97 if not already done by the adaptor
1473 * for the generic AC97 subsystem.
1475 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1477 * It is possible that the AC97 device is already registered to
1478 * the device subsystem. This happens when the device is created
1479 * via snd_ac97_mixer(). Currently only SoC codec that does so
1480 * is the generic AC97 glue but others migh emerge.
1482 * In those cases we don't try to register the device again.
1484 if (!rtd
->codec
->ac97_created
)
1487 ret
= soc_ac97_dev_register(rtd
->codec
);
1489 dev_err(rtd
->codec
->dev
,
1490 "ASoC: AC97 device register failed: %d\n", ret
);
1494 rtd
->codec
->ac97_registered
= 1;
1499 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1501 if (codec
->ac97_registered
) {
1502 soc_ac97_dev_unregister(codec
);
1503 codec
->ac97_registered
= 0;
1508 static int soc_check_aux_dev(struct snd_soc_card
*card
, int num
)
1510 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1511 struct snd_soc_codec
*codec
;
1513 /* find CODEC from registered CODECs*/
1514 list_for_each_entry(codec
, &codec_list
, list
) {
1515 if (!strcmp(codec
->name
, aux_dev
->codec_name
))
1519 dev_err(card
->dev
, "ASoC: %s not registered\n", aux_dev
->codec_name
);
1521 return -EPROBE_DEFER
;
1524 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1526 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1527 struct snd_soc_codec
*codec
;
1530 /* find CODEC from registered CODECs*/
1531 list_for_each_entry(codec
, &codec_list
, list
) {
1532 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1533 if (codec
->probed
) {
1535 "ASoC: codec already probed");
1542 /* codec not found */
1543 dev_err(card
->dev
, "ASoC: codec %s not found", aux_dev
->codec_name
);
1544 return -EPROBE_DEFER
;
1547 ret
= soc_probe_codec(card
, codec
);
1551 ret
= soc_post_component_init(card
, codec
, num
, 1);
1557 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1559 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1560 struct snd_soc_codec
*codec
= rtd
->codec
;
1562 /* unregister the rtd device */
1563 if (rtd
->dev_registered
) {
1564 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1565 device_unregister(rtd
->dev
);
1566 rtd
->dev_registered
= 0;
1569 if (codec
&& codec
->probed
)
1570 soc_remove_codec(codec
);
1573 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1574 enum snd_soc_compress_type compress_type
)
1578 if (codec
->cache_init
)
1581 /* override the compress_type if necessary */
1582 if (compress_type
&& codec
->compress_type
!= compress_type
)
1583 codec
->compress_type
= compress_type
;
1584 ret
= snd_soc_cache_init(codec
);
1587 "ASoC: Failed to set cache compression type: %d\n",
1591 codec
->cache_init
= 1;
1595 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1597 struct snd_soc_codec
*codec
;
1598 struct snd_soc_codec_conf
*codec_conf
;
1599 enum snd_soc_compress_type compress_type
;
1600 struct snd_soc_dai_link
*dai_link
;
1601 int ret
, i
, order
, dai_fmt
;
1603 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1606 for (i
= 0; i
< card
->num_links
; i
++) {
1607 ret
= soc_bind_dai_link(card
, i
);
1612 /* check aux_devs too */
1613 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1614 ret
= soc_check_aux_dev(card
, i
);
1619 /* initialize the register cache for each available codec */
1620 list_for_each_entry(codec
, &codec_list
, list
) {
1621 if (codec
->cache_init
)
1623 /* by default we don't override the compress_type */
1625 /* check to see if we need to override the compress_type */
1626 for (i
= 0; i
< card
->num_configs
; ++i
) {
1627 codec_conf
= &card
->codec_conf
[i
];
1628 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1629 compress_type
= codec_conf
->compress_type
;
1630 if (compress_type
&& compress_type
1631 != codec
->compress_type
)
1635 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1640 /* card bind complete so register a sound card */
1641 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1642 card
->owner
, 0, &card
->snd_card
);
1645 "ASoC: can't create sound card for card %s: %d\n",
1649 card
->snd_card
->dev
= card
->dev
;
1651 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1652 card
->dapm
.dev
= card
->dev
;
1653 card
->dapm
.card
= card
;
1654 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1656 #ifdef CONFIG_DEBUG_FS
1657 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1660 #ifdef CONFIG_PM_SLEEP
1661 /* deferred resume work */
1662 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1665 if (card
->dapm_widgets
)
1666 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1667 card
->num_dapm_widgets
);
1669 /* initialise the sound card only once */
1671 ret
= card
->probe(card
);
1673 goto card_probe_error
;
1676 /* probe all components used by DAI links on this card */
1677 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1679 for (i
= 0; i
< card
->num_links
; i
++) {
1680 ret
= soc_probe_link_components(card
, i
, order
);
1683 "ASoC: failed to instantiate card %d\n",
1690 /* probe all DAI links on this card */
1691 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1693 for (i
= 0; i
< card
->num_links
; i
++) {
1694 ret
= soc_probe_link_dais(card
, i
, order
);
1697 "ASoC: failed to instantiate card %d\n",
1704 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1705 ret
= soc_probe_aux_dev(card
, i
);
1708 "ASoC: failed to add auxiliary devices %d\n",
1710 goto probe_aux_dev_err
;
1714 snd_soc_dapm_link_dai_widgets(card
);
1717 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1719 if (card
->dapm_routes
)
1720 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1721 card
->num_dapm_routes
);
1723 snd_soc_dapm_new_widgets(&card
->dapm
);
1725 for (i
= 0; i
< card
->num_links
; i
++) {
1726 dai_link
= &card
->dai_link
[i
];
1727 dai_fmt
= dai_link
->dai_fmt
;
1730 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1732 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1733 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1734 "ASoC: Failed to set DAI format: %d\n",
1738 /* If this is a regular CPU link there will be a platform */
1740 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1741 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1743 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1744 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1745 "ASoC: Failed to set DAI format: %d\n",
1747 } else if (dai_fmt
) {
1748 /* Flip the polarity for the "CPU" end */
1749 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1750 switch (dai_link
->dai_fmt
&
1751 SND_SOC_DAIFMT_MASTER_MASK
) {
1752 case SND_SOC_DAIFMT_CBM_CFM
:
1753 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1755 case SND_SOC_DAIFMT_CBM_CFS
:
1756 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1758 case SND_SOC_DAIFMT_CBS_CFM
:
1759 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1761 case SND_SOC_DAIFMT_CBS_CFS
:
1762 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1766 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1768 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1769 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1770 "ASoC: Failed to set DAI format: %d\n",
1775 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1777 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1778 "%s", card
->long_name
? card
->long_name
: card
->name
);
1779 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1780 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1781 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1782 switch (card
->snd_card
->driver
[i
]) {
1788 if (!isalnum(card
->snd_card
->driver
[i
]))
1789 card
->snd_card
->driver
[i
] = '_';
1794 if (card
->late_probe
) {
1795 ret
= card
->late_probe(card
);
1797 dev_err(card
->dev
, "ASoC: %s late_probe() failed: %d\n",
1799 goto probe_aux_dev_err
;
1803 snd_soc_dapm_new_widgets(&card
->dapm
);
1805 if (card
->fully_routed
)
1806 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1807 snd_soc_dapm_auto_nc_codec_pins(codec
);
1809 ret
= snd_card_register(card
->snd_card
);
1811 dev_err(card
->dev
, "ASoC: failed to register soundcard %d\n",
1813 goto probe_aux_dev_err
;
1816 #ifdef CONFIG_SND_SOC_AC97_BUS
1817 /* register any AC97 codecs */
1818 for (i
= 0; i
< card
->num_rtd
; i
++) {
1819 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1822 "ASoC: failed to register AC97: %d\n", ret
);
1824 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1825 goto probe_aux_dev_err
;
1830 card
->instantiated
= 1;
1831 snd_soc_dapm_sync(&card
->dapm
);
1832 mutex_unlock(&card
->mutex
);
1837 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1838 soc_remove_aux_dev(card
, i
);
1841 soc_remove_dai_links(card
);
1847 snd_card_free(card
->snd_card
);
1850 mutex_unlock(&card
->mutex
);
1855 /* probes a new socdev */
1856 static int soc_probe(struct platform_device
*pdev
)
1858 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1861 * no card, so machine driver should be registering card
1862 * we should not be here in that case so ret error
1867 dev_warn(&pdev
->dev
,
1868 "ASoC: machine %s should use snd_soc_register_card()\n",
1871 /* Bodge while we unpick instantiation */
1872 card
->dev
= &pdev
->dev
;
1874 return snd_soc_register_card(card
);
1877 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1881 /* make sure any delayed work runs */
1882 for (i
= 0; i
< card
->num_rtd
; i
++) {
1883 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1884 flush_delayed_work(&rtd
->delayed_work
);
1887 /* remove auxiliary devices */
1888 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1889 soc_remove_aux_dev(card
, i
);
1891 /* remove and free each DAI */
1892 soc_remove_dai_links(card
);
1894 soc_cleanup_card_debugfs(card
);
1896 /* remove the card */
1900 snd_soc_dapm_free(&card
->dapm
);
1902 snd_card_free(card
->snd_card
);
1907 /* removes a socdev */
1908 static int soc_remove(struct platform_device
*pdev
)
1910 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1912 snd_soc_unregister_card(card
);
1916 int snd_soc_poweroff(struct device
*dev
)
1918 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1921 if (!card
->instantiated
)
1924 /* Flush out pmdown_time work - we actually do want to run it
1925 * now, we're shutting down so no imminent restart. */
1926 for (i
= 0; i
< card
->num_rtd
; i
++) {
1927 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1928 flush_delayed_work(&rtd
->delayed_work
);
1931 snd_soc_dapm_shutdown(card
);
1935 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1937 const struct dev_pm_ops snd_soc_pm_ops
= {
1938 .suspend
= snd_soc_suspend
,
1939 .resume
= snd_soc_resume
,
1940 .freeze
= snd_soc_suspend
,
1941 .thaw
= snd_soc_resume
,
1942 .poweroff
= snd_soc_poweroff
,
1943 .restore
= snd_soc_resume
,
1945 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1947 /* ASoC platform driver */
1948 static struct platform_driver soc_driver
= {
1950 .name
= "soc-audio",
1951 .owner
= THIS_MODULE
,
1952 .pm
= &snd_soc_pm_ops
,
1955 .remove
= soc_remove
,
1959 * snd_soc_codec_volatile_register: Report if a register is volatile.
1961 * @codec: CODEC to query.
1962 * @reg: Register to query.
1964 * Boolean function indiciating if a CODEC register is volatile.
1966 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1969 if (codec
->volatile_register
)
1970 return codec
->volatile_register(codec
, reg
);
1974 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1977 * snd_soc_codec_readable_register: Report if a register is readable.
1979 * @codec: CODEC to query.
1980 * @reg: Register to query.
1982 * Boolean function indicating if a CODEC register is readable.
1984 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1987 if (codec
->readable_register
)
1988 return codec
->readable_register(codec
, reg
);
1992 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1995 * snd_soc_codec_writable_register: Report if a register is writable.
1997 * @codec: CODEC to query.
1998 * @reg: Register to query.
2000 * Boolean function indicating if a CODEC register is writable.
2002 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
2005 if (codec
->writable_register
)
2006 return codec
->writable_register(codec
, reg
);
2010 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
2012 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
2017 if (!platform
->driver
->read
) {
2018 dev_err(platform
->dev
, "ASoC: platform has no read back\n");
2022 ret
= platform
->driver
->read(platform
, reg
);
2023 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
2024 trace_snd_soc_preg_read(platform
, reg
, ret
);
2028 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
2030 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
2031 unsigned int reg
, unsigned int val
)
2033 if (!platform
->driver
->write
) {
2034 dev_err(platform
->dev
, "ASoC: platform has no write back\n");
2038 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
2039 trace_snd_soc_preg_write(platform
, reg
, val
);
2040 return platform
->driver
->write(platform
, reg
, val
);
2042 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
2045 * snd_soc_new_ac97_codec - initailise AC97 device
2046 * @codec: audio codec
2047 * @ops: AC97 bus operations
2048 * @num: AC97 codec number
2050 * Initialises AC97 codec resources for use by ad-hoc devices only.
2052 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
2053 struct snd_ac97_bus_ops
*ops
, int num
)
2055 mutex_lock(&codec
->mutex
);
2057 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
2058 if (codec
->ac97
== NULL
) {
2059 mutex_unlock(&codec
->mutex
);
2063 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
2064 if (codec
->ac97
->bus
== NULL
) {
2067 mutex_unlock(&codec
->mutex
);
2071 codec
->ac97
->bus
->ops
= ops
;
2072 codec
->ac97
->num
= num
;
2075 * Mark the AC97 device to be created by us. This way we ensure that the
2076 * device will be registered with the device subsystem later on.
2078 codec
->ac97_created
= 1;
2080 mutex_unlock(&codec
->mutex
);
2083 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
2085 struct snd_ac97_bus_ops
*soc_ac97_ops
;
2086 EXPORT_SYMBOL_GPL(soc_ac97_ops
);
2088 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops
*ops
)
2090 if (ops
== soc_ac97_ops
)
2093 if (soc_ac97_ops
&& ops
)
2100 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops
);
2103 * snd_soc_free_ac97_codec - free AC97 codec device
2104 * @codec: audio codec
2106 * Frees AC97 codec device resources.
2108 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
2110 mutex_lock(&codec
->mutex
);
2111 #ifdef CONFIG_SND_SOC_AC97_BUS
2112 soc_unregister_ac97_dai_link(codec
);
2114 kfree(codec
->ac97
->bus
);
2117 codec
->ac97_created
= 0;
2118 mutex_unlock(&codec
->mutex
);
2120 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
2122 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
2126 ret
= codec
->read(codec
, reg
);
2127 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
2128 trace_snd_soc_reg_read(codec
, reg
, ret
);
2132 EXPORT_SYMBOL_GPL(snd_soc_read
);
2134 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
2135 unsigned int reg
, unsigned int val
)
2137 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
2138 trace_snd_soc_reg_write(codec
, reg
, val
);
2139 return codec
->write(codec
, reg
, val
);
2141 EXPORT_SYMBOL_GPL(snd_soc_write
);
2143 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
2144 unsigned int reg
, const void *data
, size_t len
)
2146 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
2148 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
2151 * snd_soc_update_bits - update codec register bits
2152 * @codec: audio codec
2153 * @reg: codec register
2154 * @mask: register mask
2157 * Writes new register value.
2159 * Returns 1 for change, 0 for no change, or negative error code.
2161 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2162 unsigned int mask
, unsigned int value
)
2165 unsigned int old
, new;
2168 if (codec
->using_regmap
) {
2169 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
2170 mask
, value
, &change
);
2172 ret
= snd_soc_read(codec
, reg
);
2177 new = (old
& ~mask
) | (value
& mask
);
2178 change
= old
!= new;
2180 ret
= snd_soc_write(codec
, reg
, new);
2188 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
2191 * snd_soc_update_bits_locked - update codec register bits
2192 * @codec: audio codec
2193 * @reg: codec register
2194 * @mask: register mask
2197 * Writes new register value, and takes the codec mutex.
2199 * Returns 1 for change else 0.
2201 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
2202 unsigned short reg
, unsigned int mask
,
2207 mutex_lock(&codec
->mutex
);
2208 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
2209 mutex_unlock(&codec
->mutex
);
2213 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
2216 * snd_soc_test_bits - test register for change
2217 * @codec: audio codec
2218 * @reg: codec register
2219 * @mask: register mask
2222 * Tests a register with a new value and checks if the new value is
2223 * different from the old value.
2225 * Returns 1 for change else 0.
2227 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2228 unsigned int mask
, unsigned int value
)
2231 unsigned int old
, new;
2233 old
= snd_soc_read(codec
, reg
);
2234 new = (old
& ~mask
) | value
;
2235 change
= old
!= new;
2239 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
2242 * snd_soc_cnew - create new control
2243 * @_template: control template
2244 * @data: control private data
2245 * @long_name: control long name
2246 * @prefix: control name prefix
2248 * Create a new mixer control from a template control.
2250 * Returns 0 for success, else error.
2252 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2253 void *data
, const char *long_name
,
2256 struct snd_kcontrol_new
template;
2257 struct snd_kcontrol
*kcontrol
;
2260 memcpy(&template, _template
, sizeof(template));
2264 long_name
= template.name
;
2267 name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, long_name
);
2271 template.name
= name
;
2273 template.name
= long_name
;
2276 kcontrol
= snd_ctl_new1(&template, data
);
2282 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2284 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2285 const struct snd_kcontrol_new
*controls
, int num_controls
,
2286 const char *prefix
, void *data
)
2290 for (i
= 0; i
< num_controls
; i
++) {
2291 const struct snd_kcontrol_new
*control
= &controls
[i
];
2292 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2293 control
->name
, prefix
));
2295 dev_err(dev
, "ASoC: Failed to add %s: %d\n",
2296 control
->name
, err
);
2305 * snd_soc_add_codec_controls - add an array of controls to a codec.
2306 * Convenience function to add a list of controls. Many codecs were
2307 * duplicating this code.
2309 * @codec: codec to add controls to
2310 * @controls: array of controls to add
2311 * @num_controls: number of elements in the array
2313 * Return 0 for success, else error.
2315 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2316 const struct snd_kcontrol_new
*controls
, int num_controls
)
2318 struct snd_card
*card
= codec
->card
->snd_card
;
2320 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2321 codec
->name_prefix
, codec
);
2323 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2326 * snd_soc_add_platform_controls - add an array of controls to a platform.
2327 * Convenience function to add a list of controls.
2329 * @platform: platform to add controls to
2330 * @controls: array of controls to add
2331 * @num_controls: number of elements in the array
2333 * Return 0 for success, else error.
2335 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2336 const struct snd_kcontrol_new
*controls
, int num_controls
)
2338 struct snd_card
*card
= platform
->card
->snd_card
;
2340 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2343 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2346 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2347 * Convenience function to add a list of controls.
2349 * @soc_card: SoC card to add controls to
2350 * @controls: array of controls to add
2351 * @num_controls: number of elements in the array
2353 * Return 0 for success, else error.
2355 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2356 const struct snd_kcontrol_new
*controls
, int num_controls
)
2358 struct snd_card
*card
= soc_card
->snd_card
;
2360 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2363 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2366 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2367 * Convienience function to add a list of controls.
2369 * @dai: DAI to add controls to
2370 * @controls: array of controls to add
2371 * @num_controls: number of elements in the array
2373 * Return 0 for success, else error.
2375 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2376 const struct snd_kcontrol_new
*controls
, int num_controls
)
2378 struct snd_card
*card
= dai
->card
->snd_card
;
2380 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2383 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2386 * snd_soc_info_enum_double - enumerated double mixer info callback
2387 * @kcontrol: mixer control
2388 * @uinfo: control element information
2390 * Callback to provide information about a double enumerated
2393 * Returns 0 for success.
2395 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2396 struct snd_ctl_elem_info
*uinfo
)
2398 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2400 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2401 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2402 uinfo
->value
.enumerated
.items
= e
->max
;
2404 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2405 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2406 strcpy(uinfo
->value
.enumerated
.name
,
2407 e
->texts
[uinfo
->value
.enumerated
.item
]);
2410 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2413 * snd_soc_get_enum_double - enumerated double mixer get callback
2414 * @kcontrol: mixer control
2415 * @ucontrol: control element information
2417 * Callback to get the value of a double enumerated mixer.
2419 * Returns 0 for success.
2421 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2422 struct snd_ctl_elem_value
*ucontrol
)
2424 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2425 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2428 val
= snd_soc_read(codec
, e
->reg
);
2429 ucontrol
->value
.enumerated
.item
[0]
2430 = (val
>> e
->shift_l
) & e
->mask
;
2431 if (e
->shift_l
!= e
->shift_r
)
2432 ucontrol
->value
.enumerated
.item
[1] =
2433 (val
>> e
->shift_r
) & e
->mask
;
2437 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2440 * snd_soc_put_enum_double - enumerated double mixer put callback
2441 * @kcontrol: mixer control
2442 * @ucontrol: control element information
2444 * Callback to set the value of a double enumerated mixer.
2446 * Returns 0 for success.
2448 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2449 struct snd_ctl_elem_value
*ucontrol
)
2451 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2452 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2456 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2458 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2459 mask
= e
->mask
<< e
->shift_l
;
2460 if (e
->shift_l
!= e
->shift_r
) {
2461 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2463 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2464 mask
|= e
->mask
<< e
->shift_r
;
2467 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2469 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2472 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2473 * @kcontrol: mixer control
2474 * @ucontrol: control element information
2476 * Callback to get the value of a double semi enumerated mixer.
2478 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2479 * used for handling bitfield coded enumeration for example.
2481 * Returns 0 for success.
2483 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2484 struct snd_ctl_elem_value
*ucontrol
)
2486 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2487 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2488 unsigned int reg_val
, val
, mux
;
2490 reg_val
= snd_soc_read(codec
, e
->reg
);
2491 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2492 for (mux
= 0; mux
< e
->max
; mux
++) {
2493 if (val
== e
->values
[mux
])
2496 ucontrol
->value
.enumerated
.item
[0] = mux
;
2497 if (e
->shift_l
!= e
->shift_r
) {
2498 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2499 for (mux
= 0; mux
< e
->max
; mux
++) {
2500 if (val
== e
->values
[mux
])
2503 ucontrol
->value
.enumerated
.item
[1] = mux
;
2508 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2511 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2512 * @kcontrol: mixer control
2513 * @ucontrol: control element information
2515 * Callback to set the value of a double semi enumerated mixer.
2517 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2518 * used for handling bitfield coded enumeration for example.
2520 * Returns 0 for success.
2522 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2523 struct snd_ctl_elem_value
*ucontrol
)
2525 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2526 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2530 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2532 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2533 mask
= e
->mask
<< e
->shift_l
;
2534 if (e
->shift_l
!= e
->shift_r
) {
2535 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2537 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2538 mask
|= e
->mask
<< e
->shift_r
;
2541 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2543 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2546 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2547 * @kcontrol: mixer control
2548 * @uinfo: control element information
2550 * Callback to provide information about an external enumerated
2553 * Returns 0 for success.
2555 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2556 struct snd_ctl_elem_info
*uinfo
)
2558 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2560 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2562 uinfo
->value
.enumerated
.items
= e
->max
;
2564 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2565 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2566 strcpy(uinfo
->value
.enumerated
.name
,
2567 e
->texts
[uinfo
->value
.enumerated
.item
]);
2570 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2573 * snd_soc_info_volsw_ext - external single mixer info callback
2574 * @kcontrol: mixer control
2575 * @uinfo: control element information
2577 * Callback to provide information about a single external mixer control.
2579 * Returns 0 for success.
2581 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2582 struct snd_ctl_elem_info
*uinfo
)
2584 int max
= kcontrol
->private_value
;
2586 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2587 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2589 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2592 uinfo
->value
.integer
.min
= 0;
2593 uinfo
->value
.integer
.max
= max
;
2596 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2599 * snd_soc_info_volsw - single mixer info callback
2600 * @kcontrol: mixer control
2601 * @uinfo: control element information
2603 * Callback to provide information about a single mixer control, or a double
2604 * mixer control that spans 2 registers.
2606 * Returns 0 for success.
2608 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2609 struct snd_ctl_elem_info
*uinfo
)
2611 struct soc_mixer_control
*mc
=
2612 (struct soc_mixer_control
*)kcontrol
->private_value
;
2615 if (!mc
->platform_max
)
2616 mc
->platform_max
= mc
->max
;
2617 platform_max
= mc
->platform_max
;
2619 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2620 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2622 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2624 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2625 uinfo
->value
.integer
.min
= 0;
2626 uinfo
->value
.integer
.max
= platform_max
;
2629 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2632 * snd_soc_get_volsw - single mixer get callback
2633 * @kcontrol: mixer control
2634 * @ucontrol: control element information
2636 * Callback to get the value of a single mixer control, or a double mixer
2637 * control that spans 2 registers.
2639 * Returns 0 for success.
2641 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2642 struct snd_ctl_elem_value
*ucontrol
)
2644 struct soc_mixer_control
*mc
=
2645 (struct soc_mixer_control
*)kcontrol
->private_value
;
2646 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2647 unsigned int reg
= mc
->reg
;
2648 unsigned int reg2
= mc
->rreg
;
2649 unsigned int shift
= mc
->shift
;
2650 unsigned int rshift
= mc
->rshift
;
2652 unsigned int mask
= (1 << fls(max
)) - 1;
2653 unsigned int invert
= mc
->invert
;
2655 ucontrol
->value
.integer
.value
[0] =
2656 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2658 ucontrol
->value
.integer
.value
[0] =
2659 max
- ucontrol
->value
.integer
.value
[0];
2661 if (snd_soc_volsw_is_stereo(mc
)) {
2663 ucontrol
->value
.integer
.value
[1] =
2664 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2666 ucontrol
->value
.integer
.value
[1] =
2667 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2669 ucontrol
->value
.integer
.value
[1] =
2670 max
- ucontrol
->value
.integer
.value
[1];
2675 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2678 * snd_soc_put_volsw - single mixer put callback
2679 * @kcontrol: mixer control
2680 * @ucontrol: control element information
2682 * Callback to set the value of a single mixer control, or a double mixer
2683 * control that spans 2 registers.
2685 * Returns 0 for success.
2687 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2688 struct snd_ctl_elem_value
*ucontrol
)
2690 struct soc_mixer_control
*mc
=
2691 (struct soc_mixer_control
*)kcontrol
->private_value
;
2692 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2693 unsigned int reg
= mc
->reg
;
2694 unsigned int reg2
= mc
->rreg
;
2695 unsigned int shift
= mc
->shift
;
2696 unsigned int rshift
= mc
->rshift
;
2698 unsigned int mask
= (1 << fls(max
)) - 1;
2699 unsigned int invert
= mc
->invert
;
2702 unsigned int val2
= 0;
2703 unsigned int val
, val_mask
;
2705 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2708 val_mask
= mask
<< shift
;
2710 if (snd_soc_volsw_is_stereo(mc
)) {
2711 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2715 val_mask
|= mask
<< rshift
;
2716 val
|= val2
<< rshift
;
2718 val2
= val2
<< shift
;
2722 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2727 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2731 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2734 * snd_soc_get_volsw_sx - single mixer get callback
2735 * @kcontrol: mixer control
2736 * @ucontrol: control element information
2738 * Callback to get the value of a single mixer control, or a double mixer
2739 * control that spans 2 registers.
2741 * Returns 0 for success.
2743 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2744 struct snd_ctl_elem_value
*ucontrol
)
2746 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2747 struct soc_mixer_control
*mc
=
2748 (struct soc_mixer_control
*)kcontrol
->private_value
;
2750 unsigned int reg
= mc
->reg
;
2751 unsigned int reg2
= mc
->rreg
;
2752 unsigned int shift
= mc
->shift
;
2753 unsigned int rshift
= mc
->rshift
;
2756 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2758 ucontrol
->value
.integer
.value
[0] =
2759 ((snd_soc_read(codec
, reg
) >> shift
) - min
) & mask
;
2761 if (snd_soc_volsw_is_stereo(mc
))
2762 ucontrol
->value
.integer
.value
[1] =
2763 ((snd_soc_read(codec
, reg2
) >> rshift
) - min
) & mask
;
2767 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2770 * snd_soc_put_volsw_sx - double mixer set callback
2771 * @kcontrol: mixer control
2772 * @uinfo: control element information
2774 * Callback to set the value of a double mixer control that spans 2 registers.
2776 * Returns 0 for success.
2778 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2779 struct snd_ctl_elem_value
*ucontrol
)
2781 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2782 struct soc_mixer_control
*mc
=
2783 (struct soc_mixer_control
*)kcontrol
->private_value
;
2785 unsigned int reg
= mc
->reg
;
2786 unsigned int reg2
= mc
->rreg
;
2787 unsigned int shift
= mc
->shift
;
2788 unsigned int rshift
= mc
->rshift
;
2791 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2793 unsigned short val
, val_mask
, val2
= 0;
2795 val_mask
= mask
<< shift
;
2796 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2799 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2803 if (snd_soc_volsw_is_stereo(mc
)) {
2804 val_mask
= mask
<< rshift
;
2805 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2806 val2
= val2
<< rshift
;
2808 if (snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
))
2813 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2816 * snd_soc_info_volsw_s8 - signed mixer info callback
2817 * @kcontrol: mixer control
2818 * @uinfo: control element information
2820 * Callback to provide information about a signed mixer control.
2822 * Returns 0 for success.
2824 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2825 struct snd_ctl_elem_info
*uinfo
)
2827 struct soc_mixer_control
*mc
=
2828 (struct soc_mixer_control
*)kcontrol
->private_value
;
2832 if (!mc
->platform_max
)
2833 mc
->platform_max
= mc
->max
;
2834 platform_max
= mc
->platform_max
;
2836 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2838 uinfo
->value
.integer
.min
= 0;
2839 uinfo
->value
.integer
.max
= platform_max
- min
;
2842 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2845 * snd_soc_get_volsw_s8 - signed mixer get callback
2846 * @kcontrol: mixer control
2847 * @ucontrol: control element information
2849 * Callback to get the value of a signed mixer control.
2851 * Returns 0 for success.
2853 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2854 struct snd_ctl_elem_value
*ucontrol
)
2856 struct soc_mixer_control
*mc
=
2857 (struct soc_mixer_control
*)kcontrol
->private_value
;
2858 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2859 unsigned int reg
= mc
->reg
;
2861 int val
= snd_soc_read(codec
, reg
);
2863 ucontrol
->value
.integer
.value
[0] =
2864 ((signed char)(val
& 0xff))-min
;
2865 ucontrol
->value
.integer
.value
[1] =
2866 ((signed char)((val
>> 8) & 0xff))-min
;
2869 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2872 * snd_soc_put_volsw_sgn - signed mixer put callback
2873 * @kcontrol: mixer control
2874 * @ucontrol: control element information
2876 * Callback to set the value of a signed mixer control.
2878 * Returns 0 for success.
2880 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2881 struct snd_ctl_elem_value
*ucontrol
)
2883 struct soc_mixer_control
*mc
=
2884 (struct soc_mixer_control
*)kcontrol
->private_value
;
2885 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2886 unsigned int reg
= mc
->reg
;
2890 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2891 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2893 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2895 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2898 * snd_soc_info_volsw_range - single mixer info callback with range.
2899 * @kcontrol: mixer control
2900 * @uinfo: control element information
2902 * Callback to provide information, within a range, about a single
2905 * returns 0 for success.
2907 int snd_soc_info_volsw_range(struct snd_kcontrol
*kcontrol
,
2908 struct snd_ctl_elem_info
*uinfo
)
2910 struct soc_mixer_control
*mc
=
2911 (struct soc_mixer_control
*)kcontrol
->private_value
;
2915 if (!mc
->platform_max
)
2916 mc
->platform_max
= mc
->max
;
2917 platform_max
= mc
->platform_max
;
2919 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2920 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2921 uinfo
->value
.integer
.min
= 0;
2922 uinfo
->value
.integer
.max
= platform_max
- min
;
2926 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range
);
2929 * snd_soc_put_volsw_range - single mixer put value callback with range.
2930 * @kcontrol: mixer control
2931 * @ucontrol: control element information
2933 * Callback to set the value, within a range, for a single mixer control.
2935 * Returns 0 for success.
2937 int snd_soc_put_volsw_range(struct snd_kcontrol
*kcontrol
,
2938 struct snd_ctl_elem_value
*ucontrol
)
2940 struct soc_mixer_control
*mc
=
2941 (struct soc_mixer_control
*)kcontrol
->private_value
;
2942 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2943 unsigned int reg
= mc
->reg
;
2944 unsigned int rreg
= mc
->rreg
;
2945 unsigned int shift
= mc
->shift
;
2948 unsigned int mask
= (1 << fls(max
)) - 1;
2949 unsigned int invert
= mc
->invert
;
2950 unsigned int val
, val_mask
;
2953 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2956 val_mask
= mask
<< shift
;
2959 ret
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2963 if (snd_soc_volsw_is_stereo(mc
)) {
2964 val
= ((ucontrol
->value
.integer
.value
[1] + min
) & mask
);
2967 val_mask
= mask
<< shift
;
2970 ret
= snd_soc_update_bits_locked(codec
, rreg
, val_mask
, val
);
2975 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range
);
2978 * snd_soc_get_volsw_range - single mixer get callback with range
2979 * @kcontrol: mixer control
2980 * @ucontrol: control element information
2982 * Callback to get the value, within a range, of a single mixer control.
2984 * Returns 0 for success.
2986 int snd_soc_get_volsw_range(struct snd_kcontrol
*kcontrol
,
2987 struct snd_ctl_elem_value
*ucontrol
)
2989 struct soc_mixer_control
*mc
=
2990 (struct soc_mixer_control
*)kcontrol
->private_value
;
2991 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2992 unsigned int reg
= mc
->reg
;
2993 unsigned int rreg
= mc
->rreg
;
2994 unsigned int shift
= mc
->shift
;
2997 unsigned int mask
= (1 << fls(max
)) - 1;
2998 unsigned int invert
= mc
->invert
;
3000 ucontrol
->value
.integer
.value
[0] =
3001 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
3003 ucontrol
->value
.integer
.value
[0] =
3004 max
- ucontrol
->value
.integer
.value
[0];
3005 ucontrol
->value
.integer
.value
[0] =
3006 ucontrol
->value
.integer
.value
[0] - min
;
3008 if (snd_soc_volsw_is_stereo(mc
)) {
3009 ucontrol
->value
.integer
.value
[1] =
3010 (snd_soc_read(codec
, rreg
) >> shift
) & mask
;
3012 ucontrol
->value
.integer
.value
[1] =
3013 max
- ucontrol
->value
.integer
.value
[1];
3014 ucontrol
->value
.integer
.value
[1] =
3015 ucontrol
->value
.integer
.value
[1] - min
;
3020 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range
);
3023 * snd_soc_limit_volume - Set new limit to an existing volume control.
3025 * @codec: where to look for the control
3026 * @name: Name of the control
3027 * @max: new maximum limit
3029 * Return 0 for success, else error.
3031 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
3032 const char *name
, int max
)
3034 struct snd_card
*card
= codec
->card
->snd_card
;
3035 struct snd_kcontrol
*kctl
;
3036 struct soc_mixer_control
*mc
;
3040 /* Sanity check for name and max */
3041 if (unlikely(!name
|| max
<= 0))
3044 list_for_each_entry(kctl
, &card
->controls
, list
) {
3045 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
3051 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
3052 if (max
<= mc
->max
) {
3053 mc
->platform_max
= max
;
3059 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
3061 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
3062 struct snd_ctl_elem_info
*uinfo
)
3064 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3065 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3067 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3068 uinfo
->count
= params
->num_regs
* codec
->val_bytes
;
3072 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
3074 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
3075 struct snd_ctl_elem_value
*ucontrol
)
3077 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3078 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3081 if (codec
->using_regmap
)
3082 ret
= regmap_raw_read(codec
->control_data
, params
->base
,
3083 ucontrol
->value
.bytes
.data
,
3084 params
->num_regs
* codec
->val_bytes
);
3088 /* Hide any masked bytes to ensure consistent data reporting */
3089 if (ret
== 0 && params
->mask
) {
3090 switch (codec
->val_bytes
) {
3092 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
3095 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
3099 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
3109 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
3111 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
3112 struct snd_ctl_elem_value
*ucontrol
)
3114 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3115 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3120 if (!codec
->using_regmap
)
3123 len
= params
->num_regs
* codec
->val_bytes
;
3125 data
= kmemdup(ucontrol
->value
.bytes
.data
, len
, GFP_KERNEL
| GFP_DMA
);
3130 * If we've got a mask then we need to preserve the register
3131 * bits. We shouldn't modify the incoming data so take a
3135 ret
= regmap_read(codec
->control_data
, params
->base
, &val
);
3139 val
&= params
->mask
;
3141 switch (codec
->val_bytes
) {
3143 ((u8
*)data
)[0] &= ~params
->mask
;
3144 ((u8
*)data
)[0] |= val
;
3147 ((u16
*)data
)[0] &= cpu_to_be16(~params
->mask
);
3148 ((u16
*)data
)[0] |= cpu_to_be16(val
);
3151 ((u32
*)data
)[0] &= cpu_to_be32(~params
->mask
);
3152 ((u32
*)data
)[0] |= cpu_to_be32(val
);
3160 ret
= regmap_raw_write(codec
->control_data
, params
->base
,
3168 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
3171 * snd_soc_info_xr_sx - signed multi register info callback
3172 * @kcontrol: mreg control
3173 * @uinfo: control element information
3175 * Callback to provide information of a control that can
3176 * span multiple codec registers which together
3177 * forms a single signed value in a MSB/LSB manner.
3179 * Returns 0 for success.
3181 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
3182 struct snd_ctl_elem_info
*uinfo
)
3184 struct soc_mreg_control
*mc
=
3185 (struct soc_mreg_control
*)kcontrol
->private_value
;
3186 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3188 uinfo
->value
.integer
.min
= mc
->min
;
3189 uinfo
->value
.integer
.max
= mc
->max
;
3193 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
3196 * snd_soc_get_xr_sx - signed multi register get callback
3197 * @kcontrol: mreg control
3198 * @ucontrol: control element information
3200 * Callback to get the value of a control that can span
3201 * multiple codec registers which together forms a single
3202 * signed value in a MSB/LSB manner. The control supports
3203 * specifying total no of bits used to allow for bitfields
3204 * across the multiple codec registers.
3206 * Returns 0 for success.
3208 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
3209 struct snd_ctl_elem_value
*ucontrol
)
3211 struct soc_mreg_control
*mc
=
3212 (struct soc_mreg_control
*)kcontrol
->private_value
;
3213 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3214 unsigned int regbase
= mc
->regbase
;
3215 unsigned int regcount
= mc
->regcount
;
3216 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3217 unsigned int regwmask
= (1<<regwshift
)-1;
3218 unsigned int invert
= mc
->invert
;
3219 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3223 unsigned long regval
;
3226 for (i
= 0; i
< regcount
; i
++) {
3227 regval
= snd_soc_read(codec
, regbase
+i
) & regwmask
;
3228 val
|= regval
<< (regwshift
*(regcount
-i
-1));
3231 if (min
< 0 && val
> max
)
3235 ucontrol
->value
.integer
.value
[0] = val
;
3239 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3242 * snd_soc_put_xr_sx - signed multi register get callback
3243 * @kcontrol: mreg control
3244 * @ucontrol: control element information
3246 * Callback to set the value of a control that can span
3247 * multiple codec registers which together forms a single
3248 * signed value in a MSB/LSB manner. The control supports
3249 * specifying total no of bits used to allow for bitfields
3250 * across the multiple codec registers.
3252 * Returns 0 for success.
3254 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3255 struct snd_ctl_elem_value
*ucontrol
)
3257 struct soc_mreg_control
*mc
=
3258 (struct soc_mreg_control
*)kcontrol
->private_value
;
3259 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3260 unsigned int regbase
= mc
->regbase
;
3261 unsigned int regcount
= mc
->regcount
;
3262 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3263 unsigned int regwmask
= (1<<regwshift
)-1;
3264 unsigned int invert
= mc
->invert
;
3265 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3267 long val
= ucontrol
->value
.integer
.value
[0];
3268 unsigned int i
, regval
, regmask
;
3274 for (i
= 0; i
< regcount
; i
++) {
3275 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3276 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3277 err
= snd_soc_update_bits_locked(codec
, regbase
+i
,
3285 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3288 * snd_soc_get_strobe - strobe get callback
3289 * @kcontrol: mixer control
3290 * @ucontrol: control element information
3292 * Callback get the value of a strobe mixer control.
3294 * Returns 0 for success.
3296 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3297 struct snd_ctl_elem_value
*ucontrol
)
3299 struct soc_mixer_control
*mc
=
3300 (struct soc_mixer_control
*)kcontrol
->private_value
;
3301 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3302 unsigned int reg
= mc
->reg
;
3303 unsigned int shift
= mc
->shift
;
3304 unsigned int mask
= 1 << shift
;
3305 unsigned int invert
= mc
->invert
!= 0;
3306 unsigned int val
= snd_soc_read(codec
, reg
) & mask
;
3308 if (shift
!= 0 && val
!= 0)
3310 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3314 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3317 * snd_soc_put_strobe - strobe put callback
3318 * @kcontrol: mixer control
3319 * @ucontrol: control element information
3321 * Callback strobe a register bit to high then low (or the inverse)
3322 * in one pass of a single mixer enum control.
3324 * Returns 1 for success.
3326 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3327 struct snd_ctl_elem_value
*ucontrol
)
3329 struct soc_mixer_control
*mc
=
3330 (struct soc_mixer_control
*)kcontrol
->private_value
;
3331 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3332 unsigned int reg
= mc
->reg
;
3333 unsigned int shift
= mc
->shift
;
3334 unsigned int mask
= 1 << shift
;
3335 unsigned int invert
= mc
->invert
!= 0;
3336 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3337 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3338 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3341 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val1
);
3345 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val2
);
3348 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3351 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3353 * @clk_id: DAI specific clock ID
3354 * @freq: new clock frequency in Hz
3355 * @dir: new clock direction - input/output.
3357 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3359 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3360 unsigned int freq
, int dir
)
3362 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3363 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3364 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3365 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3370 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3373 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3375 * @clk_id: DAI specific clock ID
3376 * @source: Source for the clock
3377 * @freq: new clock frequency in Hz
3378 * @dir: new clock direction - input/output.
3380 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3382 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3383 int source
, unsigned int freq
, int dir
)
3385 if (codec
->driver
->set_sysclk
)
3386 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3391 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3394 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3396 * @div_id: DAI specific clock divider ID
3397 * @div: new clock divisor.
3399 * Configures the clock dividers. This is used to derive the best DAI bit and
3400 * frame clocks from the system or master clock. It's best to set the DAI bit
3401 * and frame clocks as low as possible to save system power.
3403 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3404 int div_id
, int div
)
3406 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3407 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3411 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3414 * snd_soc_dai_set_pll - configure DAI PLL.
3416 * @pll_id: DAI specific PLL ID
3417 * @source: DAI specific source for the PLL
3418 * @freq_in: PLL input clock frequency in Hz
3419 * @freq_out: requested PLL output clock frequency in Hz
3421 * Configures and enables PLL to generate output clock based on input clock.
3423 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3424 unsigned int freq_in
, unsigned int freq_out
)
3426 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3427 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3429 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3430 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3435 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3438 * snd_soc_codec_set_pll - configure codec PLL.
3440 * @pll_id: DAI specific PLL ID
3441 * @source: DAI specific source for the PLL
3442 * @freq_in: PLL input clock frequency in Hz
3443 * @freq_out: requested PLL output clock frequency in Hz
3445 * Configures and enables PLL to generate output clock based on input clock.
3447 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3448 unsigned int freq_in
, unsigned int freq_out
)
3450 if (codec
->driver
->set_pll
)
3451 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3456 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3459 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3461 * @fmt: SND_SOC_DAIFMT_ format value.
3463 * Configures the DAI hardware format and clocking.
3465 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3467 if (dai
->driver
== NULL
)
3469 if (dai
->driver
->ops
->set_fmt
== NULL
)
3471 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3473 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3476 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3478 * @tx_mask: bitmask representing active TX slots.
3479 * @rx_mask: bitmask representing active RX slots.
3480 * @slots: Number of slots in use.
3481 * @slot_width: Width in bits for each slot.
3483 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3486 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3487 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3489 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3490 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3495 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3498 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3500 * @tx_num: how many TX channels
3501 * @tx_slot: pointer to an array which imply the TX slot number channel
3503 * @rx_num: how many RX channels
3504 * @rx_slot: pointer to an array which imply the RX slot number channel
3507 * configure the relationship between channel number and TDM slot number.
3509 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3510 unsigned int tx_num
, unsigned int *tx_slot
,
3511 unsigned int rx_num
, unsigned int *rx_slot
)
3513 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3514 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3519 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3522 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3524 * @tristate: tristate enable
3526 * Tristates the DAI so that others can use it.
3528 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3530 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3531 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3535 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3538 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3540 * @mute: mute enable
3541 * @direction: stream to mute
3543 * Mutes the DAI DAC.
3545 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
,
3551 if (dai
->driver
->ops
->mute_stream
)
3552 return dai
->driver
->ops
->mute_stream(dai
, mute
, direction
);
3553 else if (direction
== SNDRV_PCM_STREAM_PLAYBACK
&&
3554 dai
->driver
->ops
->digital_mute
)
3555 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3559 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3562 * snd_soc_register_card - Register a card with the ASoC core
3564 * @card: Card to register
3567 int snd_soc_register_card(struct snd_soc_card
*card
)
3571 if (!card
->name
|| !card
->dev
)
3574 for (i
= 0; i
< card
->num_links
; i
++) {
3575 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3578 * Codec must be specified by 1 of name or OF node,
3579 * not both or neither.
3581 if (!!link
->codec_name
== !!link
->codec_of_node
) {
3583 "ASoC: Neither/both codec name/of_node are set for %s\n",
3587 /* Codec DAI name must be specified */
3588 if (!link
->codec_dai_name
) {
3590 "ASoC: codec_dai_name not set for %s\n",
3596 * Platform may be specified by either name or OF node, but
3597 * can be left unspecified, and a dummy platform will be used.
3599 if (link
->platform_name
&& link
->platform_of_node
) {
3601 "ASoC: Both platform name/of_node are set for %s\n",
3607 * CPU device may be specified by either name or OF node, but
3608 * can be left unspecified, and will be matched based on DAI
3611 if (link
->cpu_name
&& link
->cpu_of_node
) {
3613 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3618 * At least one of CPU DAI name or CPU device name/node must be
3621 if (!link
->cpu_dai_name
&&
3622 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3624 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3630 dev_set_drvdata(card
->dev
, card
);
3632 snd_soc_initialize_card_lists(card
);
3634 soc_init_card_debugfs(card
);
3636 card
->rtd
= devm_kzalloc(card
->dev
,
3637 sizeof(struct snd_soc_pcm_runtime
) *
3638 (card
->num_links
+ card
->num_aux_devs
),
3640 if (card
->rtd
== NULL
)
3643 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3645 for (i
= 0; i
< card
->num_links
; i
++)
3646 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3648 INIT_LIST_HEAD(&card
->list
);
3649 INIT_LIST_HEAD(&card
->dapm_dirty
);
3650 card
->instantiated
= 0;
3651 mutex_init(&card
->mutex
);
3652 mutex_init(&card
->dapm_mutex
);
3654 ret
= snd_soc_instantiate_card(card
);
3656 soc_cleanup_card_debugfs(card
);
3660 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3663 * snd_soc_unregister_card - Unregister a card with the ASoC core
3665 * @card: Card to unregister
3668 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3670 if (card
->instantiated
)
3671 soc_cleanup_card_resources(card
);
3672 dev_dbg(card
->dev
, "ASoC: Unregistered card '%s'\n", card
->name
);
3676 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3679 * Simplify DAI link configuration by removing ".-1" from device names
3680 * and sanitizing names.
3682 static char *fmt_single_name(struct device
*dev
, int *id
)
3684 char *found
, name
[NAME_SIZE
];
3687 if (dev_name(dev
) == NULL
)
3690 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3692 /* are we a "%s.%d" name (platform and SPI components) */
3693 found
= strstr(name
, dev
->driver
->name
);
3696 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3698 /* discard ID from name if ID == -1 */
3700 found
[strlen(dev
->driver
->name
)] = '\0';
3704 /* I2C component devices are named "bus-addr" */
3705 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3706 char tmp
[NAME_SIZE
];
3708 /* create unique ID number from I2C addr and bus */
3709 *id
= ((id1
& 0xffff) << 16) + id2
;
3711 /* sanitize component name for DAI link creation */
3712 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3713 strlcpy(name
, tmp
, NAME_SIZE
);
3718 return kstrdup(name
, GFP_KERNEL
);
3722 * Simplify DAI link naming for single devices with multiple DAIs by removing
3723 * any ".-1" and using the DAI name (instead of device name).
3725 static inline char *fmt_multiple_name(struct device
*dev
,
3726 struct snd_soc_dai_driver
*dai_drv
)
3728 if (dai_drv
->name
== NULL
) {
3730 "ASoC: error - multiple DAI %s registered with no name\n",
3735 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3739 * snd_soc_register_dai - Register a DAI with the ASoC core
3741 * @dai: DAI to register
3743 static int snd_soc_register_dai(struct device
*dev
,
3744 struct snd_soc_dai_driver
*dai_drv
)
3746 struct snd_soc_codec
*codec
;
3747 struct snd_soc_dai
*dai
;
3749 dev_dbg(dev
, "ASoC: dai register %s\n", dev_name(dev
));
3751 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3755 /* create DAI component name */
3756 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3757 if (dai
->name
== NULL
) {
3763 dai
->driver
= dai_drv
;
3764 dai
->dapm
.dev
= dev
;
3765 if (!dai
->driver
->ops
)
3766 dai
->driver
->ops
= &null_dai_ops
;
3768 mutex_lock(&client_mutex
);
3770 list_for_each_entry(codec
, &codec_list
, list
) {
3771 if (codec
->dev
== dev
) {
3772 dev_dbg(dev
, "ASoC: Mapped DAI %s to CODEC %s\n",
3773 dai
->name
, codec
->name
);
3780 dai
->dapm
.idle_bias_off
= 1;
3782 list_add(&dai
->list
, &dai_list
);
3784 mutex_unlock(&client_mutex
);
3786 dev_dbg(dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3792 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3794 * @dai: DAI to unregister
3796 static void snd_soc_unregister_dai(struct device
*dev
)
3798 struct snd_soc_dai
*dai
;
3800 list_for_each_entry(dai
, &dai_list
, list
) {
3801 if (dev
== dai
->dev
)
3807 mutex_lock(&client_mutex
);
3808 list_del(&dai
->list
);
3809 mutex_unlock(&client_mutex
);
3811 dev_dbg(dev
, "ASoC: Unregistered DAI '%s'\n", dai
->name
);
3817 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3819 * @dai: Array of DAIs to register
3820 * @count: Number of DAIs
3822 static int snd_soc_register_dais(struct device
*dev
,
3823 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3825 struct snd_soc_codec
*codec
;
3826 struct snd_soc_dai
*dai
;
3829 dev_dbg(dev
, "ASoC: dai register %s #%Zu\n", dev_name(dev
), count
);
3831 for (i
= 0; i
< count
; i
++) {
3833 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3839 /* create DAI component name */
3840 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3841 if (dai
->name
== NULL
) {
3848 dai
->driver
= &dai_drv
[i
];
3849 if (dai
->driver
->id
)
3850 dai
->id
= dai
->driver
->id
;
3853 dai
->dapm
.dev
= dev
;
3854 if (!dai
->driver
->ops
)
3855 dai
->driver
->ops
= &null_dai_ops
;
3857 mutex_lock(&client_mutex
);
3859 list_for_each_entry(codec
, &codec_list
, list
) {
3860 if (codec
->dev
== dev
) {
3862 "ASoC: Mapped DAI %s to CODEC %s\n",
3863 dai
->name
, codec
->name
);
3870 dai
->dapm
.idle_bias_off
= 1;
3872 list_add(&dai
->list
, &dai_list
);
3874 mutex_unlock(&client_mutex
);
3876 dev_dbg(dai
->dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3882 for (i
--; i
>= 0; i
--)
3883 snd_soc_unregister_dai(dev
);
3889 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3891 * @dai: Array of DAIs to unregister
3892 * @count: Number of DAIs
3894 static void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3898 for (i
= 0; i
< count
; i
++)
3899 snd_soc_unregister_dai(dev
);
3903 * snd_soc_add_platform - Add a platform to the ASoC core
3904 * @dev: The parent device for the platform
3905 * @platform: The platform to add
3906 * @platform_driver: The driver for the platform
3908 int snd_soc_add_platform(struct device
*dev
, struct snd_soc_platform
*platform
,
3909 const struct snd_soc_platform_driver
*platform_drv
)
3911 /* create platform component name */
3912 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3913 if (platform
->name
== NULL
) {
3918 platform
->dev
= dev
;
3919 platform
->driver
= platform_drv
;
3920 platform
->dapm
.dev
= dev
;
3921 platform
->dapm
.platform
= platform
;
3922 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3923 mutex_init(&platform
->mutex
);
3925 mutex_lock(&client_mutex
);
3926 list_add(&platform
->list
, &platform_list
);
3927 mutex_unlock(&client_mutex
);
3929 dev_dbg(dev
, "ASoC: Registered platform '%s'\n", platform
->name
);
3933 EXPORT_SYMBOL_GPL(snd_soc_add_platform
);
3936 * snd_soc_register_platform - Register a platform with the ASoC core
3938 * @platform: platform to register
3940 int snd_soc_register_platform(struct device
*dev
,
3941 const struct snd_soc_platform_driver
*platform_drv
)
3943 struct snd_soc_platform
*platform
;
3946 dev_dbg(dev
, "ASoC: platform register %s\n", dev_name(dev
));
3948 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3949 if (platform
== NULL
)
3952 ret
= snd_soc_add_platform(dev
, platform
, platform_drv
);
3958 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3961 * snd_soc_remove_platform - Remove a platform from the ASoC core
3962 * @platform: the platform to remove
3964 void snd_soc_remove_platform(struct snd_soc_platform
*platform
)
3966 mutex_lock(&client_mutex
);
3967 list_del(&platform
->list
);
3968 mutex_unlock(&client_mutex
);
3970 dev_dbg(platform
->dev
, "ASoC: Unregistered platform '%s'\n",
3972 kfree(platform
->name
);
3974 EXPORT_SYMBOL_GPL(snd_soc_remove_platform
);
3976 struct snd_soc_platform
*snd_soc_lookup_platform(struct device
*dev
)
3978 struct snd_soc_platform
*platform
;
3980 list_for_each_entry(platform
, &platform_list
, list
) {
3981 if (dev
== platform
->dev
)
3987 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform
);
3990 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3992 * @platform: platform to unregister
3994 void snd_soc_unregister_platform(struct device
*dev
)
3996 struct snd_soc_platform
*platform
;
3998 platform
= snd_soc_lookup_platform(dev
);
4002 snd_soc_remove_platform(platform
);
4005 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
4007 static u64 codec_format_map
[] = {
4008 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
4009 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
4010 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
4011 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
4012 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
4013 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
4014 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4015 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4016 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
4017 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
4018 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
4019 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
4020 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
4021 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
4022 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
4023 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
4026 /* Fix up the DAI formats for endianness: codecs don't actually see
4027 * the endianness of the data but we're using the CPU format
4028 * definitions which do need to include endianness so we ensure that
4029 * codec DAIs always have both big and little endian variants set.
4031 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
4035 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
4036 if (stream
->formats
& codec_format_map
[i
])
4037 stream
->formats
|= codec_format_map
[i
];
4041 * snd_soc_register_codec - Register a codec with the ASoC core
4043 * @codec: codec to register
4045 int snd_soc_register_codec(struct device
*dev
,
4046 const struct snd_soc_codec_driver
*codec_drv
,
4047 struct snd_soc_dai_driver
*dai_drv
,
4051 struct snd_soc_codec
*codec
;
4054 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
4056 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
4060 /* create CODEC component name */
4061 codec
->name
= fmt_single_name(dev
, &codec
->id
);
4062 if (codec
->name
== NULL
) {
4067 if (codec_drv
->compress_type
)
4068 codec
->compress_type
= codec_drv
->compress_type
;
4070 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
4072 codec
->write
= codec_drv
->write
;
4073 codec
->read
= codec_drv
->read
;
4074 codec
->volatile_register
= codec_drv
->volatile_register
;
4075 codec
->readable_register
= codec_drv
->readable_register
;
4076 codec
->writable_register
= codec_drv
->writable_register
;
4077 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
4078 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
4079 codec
->dapm
.dev
= dev
;
4080 codec
->dapm
.codec
= codec
;
4081 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
4082 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
4084 codec
->driver
= codec_drv
;
4085 codec
->num_dai
= num_dai
;
4086 mutex_init(&codec
->mutex
);
4088 /* allocate CODEC register cache */
4089 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
4090 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
4091 codec
->reg_size
= reg_size
;
4092 /* it is necessary to make a copy of the default register cache
4093 * because in the case of using a compression type that requires
4094 * the default register cache to be marked as the
4095 * kernel might have freed the array by the time we initialize
4098 if (codec_drv
->reg_cache_default
) {
4099 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
4100 reg_size
, GFP_KERNEL
);
4101 if (!codec
->reg_def_copy
) {
4103 goto fail_codec_name
;
4108 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
4109 if (!codec
->volatile_register
)
4110 codec
->volatile_register
= snd_soc_default_volatile_register
;
4111 if (!codec
->readable_register
)
4112 codec
->readable_register
= snd_soc_default_readable_register
;
4113 if (!codec
->writable_register
)
4114 codec
->writable_register
= snd_soc_default_writable_register
;
4117 for (i
= 0; i
< num_dai
; i
++) {
4118 fixup_codec_formats(&dai_drv
[i
].playback
);
4119 fixup_codec_formats(&dai_drv
[i
].capture
);
4122 mutex_lock(&client_mutex
);
4123 list_add(&codec
->list
, &codec_list
);
4124 mutex_unlock(&client_mutex
);
4126 /* register any DAIs */
4127 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
4129 dev_err(codec
->dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4130 goto fail_codec_name
;
4133 dev_dbg(codec
->dev
, "ASoC: Registered codec '%s'\n", codec
->name
);
4137 mutex_lock(&client_mutex
);
4138 list_del(&codec
->list
);
4139 mutex_unlock(&client_mutex
);
4146 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
4149 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4151 * @codec: codec to unregister
4153 void snd_soc_unregister_codec(struct device
*dev
)
4155 struct snd_soc_codec
*codec
;
4157 list_for_each_entry(codec
, &codec_list
, list
) {
4158 if (dev
== codec
->dev
)
4164 snd_soc_unregister_dais(dev
, codec
->num_dai
);
4166 mutex_lock(&client_mutex
);
4167 list_del(&codec
->list
);
4168 mutex_unlock(&client_mutex
);
4170 dev_dbg(codec
->dev
, "ASoC: Unregistered codec '%s'\n", codec
->name
);
4172 snd_soc_cache_exit(codec
);
4173 kfree(codec
->reg_def_copy
);
4177 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
4181 * snd_soc_register_component - Register a component with the ASoC core
4184 int snd_soc_register_component(struct device
*dev
,
4185 const struct snd_soc_component_driver
*cmpnt_drv
,
4186 struct snd_soc_dai_driver
*dai_drv
,
4189 struct snd_soc_component
*cmpnt
;
4192 dev_dbg(dev
, "component register %s\n", dev_name(dev
));
4194 cmpnt
= devm_kzalloc(dev
, sizeof(*cmpnt
), GFP_KERNEL
);
4196 dev_err(dev
, "ASoC: Failed to allocate memory\n");
4200 cmpnt
->name
= fmt_single_name(dev
, &cmpnt
->id
);
4202 dev_err(dev
, "ASoC: Failed to simplifying name\n");
4207 cmpnt
->driver
= cmpnt_drv
;
4208 cmpnt
->num_dai
= num_dai
;
4211 * snd_soc_register_dai() uses fmt_single_name(), and
4212 * snd_soc_register_dais() uses fmt_multiple_name()
4213 * for dai->name which is used for name based matching
4216 ret
= snd_soc_register_dai(dev
, dai_drv
);
4218 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
4220 dev_err(dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4221 goto error_component_name
;
4224 mutex_lock(&client_mutex
);
4225 list_add(&cmpnt
->list
, &component_list
);
4226 mutex_unlock(&client_mutex
);
4228 dev_dbg(cmpnt
->dev
, "ASoC: Registered component '%s'\n", cmpnt
->name
);
4232 error_component_name
:
4237 EXPORT_SYMBOL_GPL(snd_soc_register_component
);
4240 * snd_soc_unregister_component - Unregister a component from the ASoC core
4243 void snd_soc_unregister_component(struct device
*dev
)
4245 struct snd_soc_component
*cmpnt
;
4247 list_for_each_entry(cmpnt
, &component_list
, list
) {
4248 if (dev
== cmpnt
->dev
)
4254 snd_soc_unregister_dais(dev
, cmpnt
->num_dai
);
4256 mutex_lock(&client_mutex
);
4257 list_del(&cmpnt
->list
);
4258 mutex_unlock(&client_mutex
);
4260 dev_dbg(dev
, "ASoC: Unregistered component '%s'\n", cmpnt
->name
);
4263 EXPORT_SYMBOL_GPL(snd_soc_unregister_component
);
4265 /* Retrieve a card's name from device tree */
4266 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
4267 const char *propname
)
4269 struct device_node
*np
= card
->dev
->of_node
;
4272 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
4274 * EINVAL means the property does not exist. This is fine providing
4275 * card->name was previously set, which is checked later in
4276 * snd_soc_register_card.
4278 if (ret
< 0 && ret
!= -EINVAL
) {
4280 "ASoC: Property '%s' could not be read: %d\n",
4287 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
4289 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
4290 const char *propname
)
4292 struct device_node
*np
= card
->dev
->of_node
;
4294 struct snd_soc_dapm_route
*routes
;
4297 num_routes
= of_property_count_strings(np
, propname
);
4298 if (num_routes
< 0 || num_routes
& 1) {
4300 "ASoC: Property '%s' does not exist or its length is not even\n",
4306 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4311 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
4315 "ASoC: Could not allocate DAPM route table\n");
4319 for (i
= 0; i
< num_routes
; i
++) {
4320 ret
= of_property_read_string_index(np
, propname
,
4321 2 * i
, &routes
[i
].sink
);
4324 "ASoC: Property '%s' index %d could not be read: %d\n",
4325 propname
, 2 * i
, ret
);
4328 ret
= of_property_read_string_index(np
, propname
,
4329 (2 * i
) + 1, &routes
[i
].source
);
4332 "ASoC: Property '%s' index %d could not be read: %d\n",
4333 propname
, (2 * i
) + 1, ret
);
4338 card
->num_dapm_routes
= num_routes
;
4339 card
->dapm_routes
= routes
;
4343 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
4345 unsigned int snd_soc_of_parse_daifmt(struct device_node
*np
,
4350 unsigned int format
= 0;
4356 } of_fmt_table
[] = {
4357 { "i2s", SND_SOC_DAIFMT_I2S
},
4358 { "right_j", SND_SOC_DAIFMT_RIGHT_J
},
4359 { "left_j", SND_SOC_DAIFMT_LEFT_J
},
4360 { "dsp_a", SND_SOC_DAIFMT_DSP_A
},
4361 { "dsp_b", SND_SOC_DAIFMT_DSP_B
},
4362 { "ac97", SND_SOC_DAIFMT_AC97
},
4363 { "pdm", SND_SOC_DAIFMT_PDM
},
4364 { "msb", SND_SOC_DAIFMT_MSB
},
4365 { "lsb", SND_SOC_DAIFMT_LSB
},
4372 * check "[prefix]format = xxx"
4373 * SND_SOC_DAIFMT_FORMAT_MASK area
4375 snprintf(prop
, sizeof(prop
), "%sformat", prefix
);
4376 ret
= of_property_read_string(np
, prop
, &str
);
4378 for (i
= 0; i
< ARRAY_SIZE(of_fmt_table
); i
++) {
4379 if (strcmp(str
, of_fmt_table
[i
].name
) == 0) {
4380 format
|= of_fmt_table
[i
].val
;
4387 * check "[prefix]continuous-clock"
4388 * SND_SOC_DAIFMT_CLOCK_MASK area
4390 snprintf(prop
, sizeof(prop
), "%scontinuous-clock", prefix
);
4391 if (of_get_property(np
, prop
, NULL
))
4392 format
|= SND_SOC_DAIFMT_CONT
;
4394 format
|= SND_SOC_DAIFMT_GATED
;
4397 * check "[prefix]bitclock-inversion"
4398 * check "[prefix]frame-inversion"
4399 * SND_SOC_DAIFMT_INV_MASK area
4401 snprintf(prop
, sizeof(prop
), "%sbitclock-inversion", prefix
);
4402 bit
= !!of_get_property(np
, prop
, NULL
);
4404 snprintf(prop
, sizeof(prop
), "%sframe-inversion", prefix
);
4405 frame
= !!of_get_property(np
, prop
, NULL
);
4407 switch ((bit
<< 4) + frame
) {
4409 format
|= SND_SOC_DAIFMT_IB_IF
;
4412 format
|= SND_SOC_DAIFMT_IB_NF
;
4415 format
|= SND_SOC_DAIFMT_NB_IF
;
4418 /* SND_SOC_DAIFMT_NB_NF is default */
4423 * check "[prefix]bitclock-master"
4424 * check "[prefix]frame-master"
4425 * SND_SOC_DAIFMT_MASTER_MASK area
4427 snprintf(prop
, sizeof(prop
), "%sbitclock-master", prefix
);
4428 bit
= !!of_get_property(np
, prop
, NULL
);
4430 snprintf(prop
, sizeof(prop
), "%sframe-master", prefix
);
4431 frame
= !!of_get_property(np
, prop
, NULL
);
4433 switch ((bit
<< 4) + frame
) {
4435 format
|= SND_SOC_DAIFMT_CBM_CFM
;
4438 format
|= SND_SOC_DAIFMT_CBM_CFS
;
4441 format
|= SND_SOC_DAIFMT_CBS_CFM
;
4444 format
|= SND_SOC_DAIFMT_CBS_CFS
;
4450 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt
);
4452 static int __init
snd_soc_init(void)
4454 #ifdef CONFIG_DEBUG_FS
4455 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
4456 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
4457 pr_warn("ASoC: Failed to create debugfs directory\n");
4458 snd_soc_debugfs_root
= NULL
;
4461 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
4463 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4465 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
4467 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4469 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
4470 &platform_list_fops
))
4471 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4474 snd_soc_util_init();
4476 return platform_driver_register(&soc_driver
);
4478 module_init(snd_soc_init
);
4480 static void __exit
snd_soc_exit(void)
4482 snd_soc_util_exit();
4484 #ifdef CONFIG_DEBUG_FS
4485 debugfs_remove_recursive(snd_soc_debugfs_root
);
4487 platform_driver_unregister(&soc_driver
);
4489 module_exit(snd_soc_exit
);
4491 /* Module information */
4492 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4493 MODULE_DESCRIPTION("ALSA SoC Core");
4494 MODULE_LICENSE("GPL");
4495 MODULE_ALIAS("platform:soc-audio");