2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 * o Add hw rules to enforce rates, etc.
20 * o More testing with other codecs/machines.
21 * o Add more codecs and platforms to ensure good API coverage.
22 * o Support TDM on PCM and I2S
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
30 #include <linux/bitops.h>
31 #include <linux/debugfs.h>
32 #include <linux/platform_device.h>
33 #include <linux/ctype.h>
34 #include <linux/slab.h>
36 #include <sound/ac97_codec.h>
37 #include <sound/core.h>
38 #include <sound/jack.h>
39 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/soc.h>
42 #include <sound/initval.h>
44 #define CREATE_TRACE_POINTS
45 #include <trace/events/asoc.h>
49 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
51 #ifdef CONFIG_DEBUG_FS
52 struct dentry
*snd_soc_debugfs_root
;
53 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
56 static DEFINE_MUTEX(client_mutex
);
57 static LIST_HEAD(card_list
);
58 static LIST_HEAD(dai_list
);
59 static LIST_HEAD(platform_list
);
60 static LIST_HEAD(codec_list
);
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
67 static int pmdown_time
= 5000;
68 module_param(pmdown_time
, int, 0);
69 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
71 /* returns the minimum number of bytes needed to represent
72 * a particular given value */
73 static int min_bytes_needed(unsigned long val
)
78 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
81 c
= (sizeof val
* 8) - c
;
89 /* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91 static int format_register_str(struct snd_soc_codec
*codec
,
92 unsigned int reg
, char *buf
, size_t len
)
94 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
95 int regsize
= codec
->driver
->reg_word_size
* 2;
98 char regbuf
[regsize
+ 1];
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize
+ regsize
+ 2 + 1 != len
)
108 ret
= snd_soc_read(codec
, reg
);
110 memset(regbuf
, 'X', regsize
);
111 regbuf
[regsize
] = '\0';
113 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
116 /* prepare the buffer */
117 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf
, tmpbuf
, len
);
124 /* codec register dump */
125 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
126 size_t count
, loff_t pos
)
129 int wordsize
, regsize
;
134 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
135 regsize
= codec
->driver
->reg_word_size
* 2;
137 len
= wordsize
+ regsize
+ 2 + 1;
139 if (!codec
->driver
->reg_cache_size
)
142 if (codec
->driver
->reg_cache_step
)
143 step
= codec
->driver
->reg_cache_step
;
145 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
146 if (!snd_soc_codec_readable_register(codec
, i
))
148 if (codec
->driver
->display_register
) {
149 count
+= codec
->driver
->display_register(codec
, buf
+ count
,
150 PAGE_SIZE
- count
, i
);
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
155 if (total
+ len
>= count
- 1)
157 format_register_str(codec
, i
, buf
+ total
, len
);
164 total
= min(total
, count
- 1);
169 static ssize_t
codec_reg_show(struct device
*dev
,
170 struct device_attribute
*attr
, char *buf
)
172 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
174 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
177 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
179 static ssize_t
pmdown_time_show(struct device
*dev
,
180 struct device_attribute
*attr
, char *buf
)
182 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
184 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
187 static ssize_t
pmdown_time_set(struct device
*dev
,
188 struct device_attribute
*attr
,
189 const char *buf
, size_t count
)
191 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
194 ret
= strict_strtol(buf
, 10, &rtd
->pmdown_time
);
201 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
203 #ifdef CONFIG_DEBUG_FS
204 static int codec_reg_open_file(struct inode
*inode
, struct file
*file
)
206 file
->private_data
= inode
->i_private
;
210 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
211 size_t count
, loff_t
*ppos
)
214 struct snd_soc_codec
*codec
= file
->private_data
;
217 if (*ppos
< 0 || !count
)
220 buf
= kmalloc(count
, GFP_KERNEL
);
224 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
226 if (copy_to_user(user_buf
, buf
, ret
)) {
237 static ssize_t
codec_reg_write_file(struct file
*file
,
238 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
243 unsigned long reg
, value
;
244 struct snd_soc_codec
*codec
= file
->private_data
;
246 buf_size
= min(count
, (sizeof(buf
)-1));
247 if (copy_from_user(buf
, user_buf
, buf_size
))
251 while (*start
== ' ')
253 reg
= simple_strtoul(start
, &start
, 16);
254 while (*start
== ' ')
256 if (strict_strtoul(start
, 16, &value
))
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER
);
262 snd_soc_write(codec
, reg
, value
);
266 static const struct file_operations codec_reg_fops
= {
267 .open
= codec_reg_open_file
,
268 .read
= codec_reg_read_file
,
269 .write
= codec_reg_write_file
,
270 .llseek
= default_llseek
,
273 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
275 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
277 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
279 if (!codec
->debugfs_codec_root
) {
280 dev_warn(codec
->dev
, "Failed to create codec debugfs directory\n");
284 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
286 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
289 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
290 codec
->debugfs_codec_root
,
291 codec
, &codec_reg_fops
);
292 if (!codec
->debugfs_reg
)
293 dev_warn(codec
->dev
, "Failed to create codec register debugfs file\n");
295 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
298 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
300 debugfs_remove_recursive(codec
->debugfs_codec_root
);
303 static void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
305 struct dentry
*debugfs_card_root
= platform
->card
->debugfs_card_root
;
307 platform
->debugfs_platform_root
= debugfs_create_dir(platform
->name
,
309 if (!platform
->debugfs_platform_root
) {
310 dev_warn(platform
->dev
,
311 "Failed to create platform debugfs directory\n");
315 snd_soc_dapm_debugfs_init(&platform
->dapm
,
316 platform
->debugfs_platform_root
);
319 static void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
321 debugfs_remove_recursive(platform
->debugfs_platform_root
);
324 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
325 size_t count
, loff_t
*ppos
)
327 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
328 ssize_t len
, ret
= 0;
329 struct snd_soc_codec
*codec
;
334 list_for_each_entry(codec
, &codec_list
, list
) {
335 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
339 if (ret
> PAGE_SIZE
) {
346 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
353 static const struct file_operations codec_list_fops
= {
354 .read
= codec_list_read_file
,
355 .llseek
= default_llseek
,/* read accesses f_pos */
358 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
359 size_t count
, loff_t
*ppos
)
361 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
362 ssize_t len
, ret
= 0;
363 struct snd_soc_dai
*dai
;
368 list_for_each_entry(dai
, &dai_list
, list
) {
369 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
372 if (ret
> PAGE_SIZE
) {
378 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
385 static const struct file_operations dai_list_fops
= {
386 .read
= dai_list_read_file
,
387 .llseek
= default_llseek
,/* read accesses f_pos */
390 static ssize_t
platform_list_read_file(struct file
*file
,
391 char __user
*user_buf
,
392 size_t count
, loff_t
*ppos
)
394 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
395 ssize_t len
, ret
= 0;
396 struct snd_soc_platform
*platform
;
401 list_for_each_entry(platform
, &platform_list
, list
) {
402 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
406 if (ret
> PAGE_SIZE
) {
412 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
419 static const struct file_operations platform_list_fops
= {
420 .read
= platform_list_read_file
,
421 .llseek
= default_llseek
,/* read accesses f_pos */
424 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
426 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
427 snd_soc_debugfs_root
);
428 if (!card
->debugfs_card_root
) {
430 "ASoC: Failed to create card debugfs directory\n");
434 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
435 card
->debugfs_card_root
,
437 if (!card
->debugfs_pop_time
)
439 "Failed to create pop time debugfs file\n");
442 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
444 debugfs_remove_recursive(card
->debugfs_card_root
);
449 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
453 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
457 static inline void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
461 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
465 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
469 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
474 #ifdef CONFIG_SND_SOC_AC97_BUS
475 /* unregister ac97 codec */
476 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
478 if (codec
->ac97
->dev
.bus
)
479 device_unregister(&codec
->ac97
->dev
);
483 /* stop no dev release warning */
484 static void soc_ac97_device_release(struct device
*dev
){}
486 /* register ac97 codec to bus */
487 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
491 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
492 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
493 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
495 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
496 codec
->card
->snd_card
->number
, 0, codec
->name
);
497 err
= device_register(&codec
->ac97
->dev
);
499 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
500 codec
->ac97
->dev
.bus
= NULL
;
507 #ifdef CONFIG_PM_SLEEP
508 /* powers down audio subsystem for suspend */
509 int snd_soc_suspend(struct device
*dev
)
511 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
512 struct snd_soc_codec
*codec
;
515 /* If the initialization of this soc device failed, there is no codec
516 * associated with it. Just bail out in this case.
518 if (list_empty(&card
->codec_dev_list
))
521 /* Due to the resume being scheduled into a workqueue we could
522 * suspend before that's finished - wait for it to complete.
524 snd_power_lock(card
->snd_card
);
525 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
526 snd_power_unlock(card
->snd_card
);
528 /* we're going to block userspace touching us until resume completes */
529 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
531 /* mute any active DACs */
532 for (i
= 0; i
< card
->num_rtd
; i
++) {
533 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
534 struct snd_soc_dai_driver
*drv
= dai
->driver
;
536 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
539 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
540 drv
->ops
->digital_mute(dai
, 1);
543 /* suspend all pcms */
544 for (i
= 0; i
< card
->num_rtd
; i
++) {
545 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
548 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
551 if (card
->suspend_pre
)
552 card
->suspend_pre(card
);
554 for (i
= 0; i
< card
->num_rtd
; i
++) {
555 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
556 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
558 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
561 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
562 cpu_dai
->driver
->suspend(cpu_dai
);
563 if (platform
->driver
->suspend
&& !platform
->suspended
) {
564 platform
->driver
->suspend(cpu_dai
);
565 platform
->suspended
= 1;
569 /* close any waiting streams and save state */
570 for (i
= 0; i
< card
->num_rtd
; i
++) {
571 flush_delayed_work_sync(&card
->rtd
[i
].delayed_work
);
572 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
575 for (i
= 0; i
< card
->num_rtd
; i
++) {
576 struct snd_soc_dai
*codec_dai
= card
->rtd
[i
].codec_dai
;
578 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
581 snd_soc_dapm_stream_event(&card
->rtd
[i
],
582 SNDRV_PCM_STREAM_PLAYBACK
,
584 SND_SOC_DAPM_STREAM_SUSPEND
);
586 snd_soc_dapm_stream_event(&card
->rtd
[i
],
587 SNDRV_PCM_STREAM_CAPTURE
,
589 SND_SOC_DAPM_STREAM_SUSPEND
);
592 /* suspend all CODECs */
593 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
594 /* If there are paths active then the CODEC will be held with
595 * bias _ON and should not be suspended. */
596 if (!codec
->suspended
&& codec
->driver
->suspend
) {
597 switch (codec
->dapm
.bias_level
) {
598 case SND_SOC_BIAS_STANDBY
:
600 * If the CODEC is capable of idle
601 * bias off then being in STANDBY
602 * means it's doing something,
603 * otherwise fall through.
605 if (codec
->dapm
.idle_bias_off
) {
607 "idle_bias_off CODEC on over suspend\n");
610 case SND_SOC_BIAS_OFF
:
611 codec
->driver
->suspend(codec
);
612 codec
->suspended
= 1;
613 codec
->cache_sync
= 1;
616 dev_dbg(codec
->dev
, "CODEC is on over suspend\n");
622 for (i
= 0; i
< card
->num_rtd
; i
++) {
623 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
625 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
628 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
629 cpu_dai
->driver
->suspend(cpu_dai
);
632 if (card
->suspend_post
)
633 card
->suspend_post(card
);
637 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
639 /* deferred resume work, so resume can complete before we finished
640 * setting our codec back up, which can be very slow on I2C
642 static void soc_resume_deferred(struct work_struct
*work
)
644 struct snd_soc_card
*card
=
645 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
646 struct snd_soc_codec
*codec
;
649 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
650 * so userspace apps are blocked from touching us
653 dev_dbg(card
->dev
, "starting resume work\n");
655 /* Bring us up into D2 so that DAPM starts enabling things */
656 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
658 if (card
->resume_pre
)
659 card
->resume_pre(card
);
661 /* resume AC97 DAIs */
662 for (i
= 0; i
< card
->num_rtd
; i
++) {
663 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
665 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
668 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
669 cpu_dai
->driver
->resume(cpu_dai
);
672 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
673 /* If the CODEC was idle over suspend then it will have been
674 * left with bias OFF or STANDBY and suspended so we must now
675 * resume. Otherwise the suspend was suppressed.
677 if (codec
->driver
->resume
&& codec
->suspended
) {
678 switch (codec
->dapm
.bias_level
) {
679 case SND_SOC_BIAS_STANDBY
:
680 case SND_SOC_BIAS_OFF
:
681 codec
->driver
->resume(codec
);
682 codec
->suspended
= 0;
685 dev_dbg(codec
->dev
, "CODEC was on over suspend\n");
691 for (i
= 0; i
< card
->num_rtd
; i
++) {
692 struct snd_soc_dai
*codec_dai
= card
->rtd
[i
].codec_dai
;
694 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
697 snd_soc_dapm_stream_event(&card
->rtd
[i
],
698 SNDRV_PCM_STREAM_PLAYBACK
, codec_dai
,
699 SND_SOC_DAPM_STREAM_RESUME
);
701 snd_soc_dapm_stream_event(&card
->rtd
[i
],
702 SNDRV_PCM_STREAM_CAPTURE
, codec_dai
,
703 SND_SOC_DAPM_STREAM_RESUME
);
706 /* unmute any active DACs */
707 for (i
= 0; i
< card
->num_rtd
; i
++) {
708 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
709 struct snd_soc_dai_driver
*drv
= dai
->driver
;
711 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
714 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
715 drv
->ops
->digital_mute(dai
, 0);
718 for (i
= 0; i
< card
->num_rtd
; i
++) {
719 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
720 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
722 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
725 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
726 cpu_dai
->driver
->resume(cpu_dai
);
727 if (platform
->driver
->resume
&& platform
->suspended
) {
728 platform
->driver
->resume(cpu_dai
);
729 platform
->suspended
= 0;
733 if (card
->resume_post
)
734 card
->resume_post(card
);
736 dev_dbg(card
->dev
, "resume work completed\n");
738 /* userspace can access us now we are back as we were before */
739 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
742 /* powers up audio subsystem after a suspend */
743 int snd_soc_resume(struct device
*dev
)
745 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
746 int i
, ac97_control
= 0;
748 /* If the initialization of this soc device failed, there is no codec
749 * associated with it. Just bail out in this case.
751 if (list_empty(&card
->codec_dev_list
))
754 /* AC97 devices might have other drivers hanging off them so
755 * need to resume immediately. Other drivers don't have that
756 * problem and may take a substantial amount of time to resume
757 * due to I/O costs and anti-pop so handle them out of line.
759 for (i
= 0; i
< card
->num_rtd
; i
++) {
760 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
761 ac97_control
|= cpu_dai
->driver
->ac97_control
;
764 dev_dbg(dev
, "Resuming AC97 immediately\n");
765 soc_resume_deferred(&card
->deferred_resume_work
);
767 dev_dbg(dev
, "Scheduling resume work\n");
768 if (!schedule_work(&card
->deferred_resume_work
))
769 dev_err(dev
, "resume work item may be lost\n");
774 EXPORT_SYMBOL_GPL(snd_soc_resume
);
776 #define snd_soc_suspend NULL
777 #define snd_soc_resume NULL
780 static const struct snd_soc_dai_ops null_dai_ops
= {
783 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
785 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
786 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
787 struct snd_soc_codec
*codec
;
788 struct snd_soc_platform
*platform
;
789 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
790 const char *platform_name
;
794 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
796 /* do we already have the CPU DAI for this link ? */
800 /* no, then find CPU DAI from registered DAIs*/
801 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
802 if (dai_link
->cpu_dai_of_node
) {
803 if (cpu_dai
->dev
->of_node
!= dai_link
->cpu_dai_of_node
)
806 if (strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
))
810 rtd
->cpu_dai
= cpu_dai
;
813 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
814 dai_link
->cpu_dai_name
);
817 /* do we already have the CODEC for this link ? */
822 /* no, then find CODEC from registered CODECs*/
823 list_for_each_entry(codec
, &codec_list
, list
) {
824 if (dai_link
->codec_of_node
) {
825 if (codec
->dev
->of_node
!= dai_link
->codec_of_node
)
828 if (strcmp(codec
->name
, dai_link
->codec_name
))
835 * CODEC found, so find CODEC DAI from registered DAIs from
838 list_for_each_entry(codec_dai
, &dai_list
, list
) {
839 if (codec
->dev
== codec_dai
->dev
&&
840 !strcmp(codec_dai
->name
,
841 dai_link
->codec_dai_name
)) {
843 rtd
->codec_dai
= codec_dai
;
847 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
848 dai_link
->codec_dai_name
);
852 dev_dbg(card
->dev
, "CODEC %s not registered\n",
853 dai_link
->codec_name
);
856 /* do we need a platform? */
860 /* if there's no platform we match on the empty platform */
861 platform_name
= dai_link
->platform_name
;
862 if (!platform_name
&& !dai_link
->platform_of_node
)
863 platform_name
= "snd-soc-dummy";
865 /* no, then find one from the set of registered platforms */
866 list_for_each_entry(platform
, &platform_list
, list
) {
867 if (dai_link
->platform_of_node
) {
868 if (platform
->dev
->of_node
!=
869 dai_link
->platform_of_node
)
872 if (strcmp(platform
->name
, platform_name
))
876 rtd
->platform
= platform
;
880 dev_dbg(card
->dev
, "platform %s not registered\n",
881 dai_link
->platform_name
);
885 /* mark rtd as complete if we found all 4 of our client devices */
886 if (rtd
->codec
&& rtd
->codec_dai
&& rtd
->platform
&& rtd
->cpu_dai
) {
893 static void soc_remove_codec(struct snd_soc_codec
*codec
)
897 if (codec
->driver
->remove
) {
898 err
= codec
->driver
->remove(codec
);
901 "asoc: failed to remove %s: %d\n",
905 /* Make sure all DAPM widgets are freed */
906 snd_soc_dapm_free(&codec
->dapm
);
908 soc_cleanup_codec_debugfs(codec
);
910 list_del(&codec
->card_list
);
911 module_put(codec
->dev
->driver
->owner
);
914 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
916 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
917 struct snd_soc_codec
*codec
= rtd
->codec
;
918 struct snd_soc_platform
*platform
= rtd
->platform
;
919 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
922 /* unregister the rtd device */
923 if (rtd
->dev_registered
) {
924 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
925 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
926 device_unregister(rtd
->dev
);
927 rtd
->dev_registered
= 0;
930 /* remove the CODEC DAI */
931 if (codec_dai
&& codec_dai
->probed
&&
932 codec_dai
->driver
->remove_order
== order
) {
933 if (codec_dai
->driver
->remove
) {
934 err
= codec_dai
->driver
->remove(codec_dai
);
936 pr_err("asoc: failed to remove %s: %d\n",
937 codec_dai
->name
, err
);
939 codec_dai
->probed
= 0;
940 list_del(&codec_dai
->card_list
);
943 /* remove the platform */
944 if (platform
&& platform
->probed
&&
945 platform
->driver
->remove_order
== order
) {
946 if (platform
->driver
->remove
) {
947 err
= platform
->driver
->remove(platform
);
949 pr_err("asoc: failed to remove %s: %d\n",
950 platform
->name
, err
);
953 /* Make sure all DAPM widgets are freed */
954 snd_soc_dapm_free(&platform
->dapm
);
956 soc_cleanup_platform_debugfs(platform
);
957 platform
->probed
= 0;
958 list_del(&platform
->card_list
);
959 module_put(platform
->dev
->driver
->owner
);
962 /* remove the CODEC */
963 if (codec
&& codec
->probed
&&
964 codec
->driver
->remove_order
== order
)
965 soc_remove_codec(codec
);
967 /* remove the cpu_dai */
968 if (cpu_dai
&& cpu_dai
->probed
&&
969 cpu_dai
->driver
->remove_order
== order
) {
970 if (cpu_dai
->driver
->remove
) {
971 err
= cpu_dai
->driver
->remove(cpu_dai
);
973 pr_err("asoc: failed to remove %s: %d\n",
977 list_del(&cpu_dai
->card_list
);
978 module_put(cpu_dai
->dev
->driver
->owner
);
982 static void soc_remove_dai_links(struct snd_soc_card
*card
)
986 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
988 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
989 soc_remove_dai_link(card
, dai
, order
);
994 static void soc_set_name_prefix(struct snd_soc_card
*card
,
995 struct snd_soc_codec
*codec
)
999 if (card
->codec_conf
== NULL
)
1002 for (i
= 0; i
< card
->num_configs
; i
++) {
1003 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1004 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
1005 codec
->name_prefix
= map
->name_prefix
;
1011 static int soc_probe_codec(struct snd_soc_card
*card
,
1012 struct snd_soc_codec
*codec
)
1015 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
1016 struct snd_soc_dai
*dai
;
1019 codec
->dapm
.card
= card
;
1020 soc_set_name_prefix(card
, codec
);
1022 if (!try_module_get(codec
->dev
->driver
->owner
))
1025 soc_init_codec_debugfs(codec
);
1027 if (driver
->dapm_widgets
)
1028 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
1029 driver
->num_dapm_widgets
);
1031 /* Create DAPM widgets for each DAI stream */
1032 list_for_each_entry(dai
, &dai_list
, list
) {
1033 if (dai
->dev
!= codec
->dev
)
1036 snd_soc_dapm_new_dai_widgets(&codec
->dapm
, dai
);
1039 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
1041 if (driver
->probe
) {
1042 ret
= driver
->probe(codec
);
1045 "asoc: failed to probe CODEC %s: %d\n",
1051 if (driver
->controls
)
1052 snd_soc_add_codec_controls(codec
, driver
->controls
,
1053 driver
->num_controls
);
1054 if (driver
->dapm_routes
)
1055 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1056 driver
->num_dapm_routes
);
1058 /* mark codec as probed and add to card codec list */
1060 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1061 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1066 soc_cleanup_codec_debugfs(codec
);
1067 module_put(codec
->dev
->driver
->owner
);
1072 static int soc_probe_platform(struct snd_soc_card
*card
,
1073 struct snd_soc_platform
*platform
)
1076 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1078 platform
->card
= card
;
1079 platform
->dapm
.card
= card
;
1081 if (!try_module_get(platform
->dev
->driver
->owner
))
1084 soc_init_platform_debugfs(platform
);
1086 if (driver
->dapm_widgets
)
1087 snd_soc_dapm_new_controls(&platform
->dapm
,
1088 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1090 if (driver
->probe
) {
1091 ret
= driver
->probe(platform
);
1093 dev_err(platform
->dev
,
1094 "asoc: failed to probe platform %s: %d\n",
1095 platform
->name
, ret
);
1100 if (driver
->controls
)
1101 snd_soc_add_platform_controls(platform
, driver
->controls
,
1102 driver
->num_controls
);
1103 if (driver
->dapm_routes
)
1104 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1105 driver
->num_dapm_routes
);
1107 /* mark platform as probed and add to card platform list */
1108 platform
->probed
= 1;
1109 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1110 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1115 soc_cleanup_platform_debugfs(platform
);
1116 module_put(platform
->dev
->driver
->owner
);
1121 static void rtd_release(struct device
*dev
)
1126 static int soc_post_component_init(struct snd_soc_card
*card
,
1127 struct snd_soc_codec
*codec
,
1128 int num
, int dailess
)
1130 struct snd_soc_dai_link
*dai_link
= NULL
;
1131 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1132 struct snd_soc_pcm_runtime
*rtd
;
1133 const char *temp
, *name
;
1137 dai_link
= &card
->dai_link
[num
];
1138 rtd
= &card
->rtd
[num
];
1139 name
= dai_link
->name
;
1141 aux_dev
= &card
->aux_dev
[num
];
1142 rtd
= &card
->rtd_aux
[num
];
1143 name
= aux_dev
->name
;
1147 /* Make sure all DAPM widgets are instantiated */
1148 snd_soc_dapm_new_widgets(&codec
->dapm
);
1150 /* machine controls, routes and widgets are not prefixed */
1151 temp
= codec
->name_prefix
;
1152 codec
->name_prefix
= NULL
;
1154 /* do machine specific initialization */
1155 if (!dailess
&& dai_link
->init
)
1156 ret
= dai_link
->init(rtd
);
1157 else if (dailess
&& aux_dev
->init
)
1158 ret
= aux_dev
->init(&codec
->dapm
);
1160 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1163 codec
->name_prefix
= temp
;
1165 /* register the rtd device */
1168 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1171 device_initialize(rtd
->dev
);
1172 rtd
->dev
->parent
= card
->dev
;
1173 rtd
->dev
->release
= rtd_release
;
1174 rtd
->dev
->init_name
= name
;
1175 dev_set_drvdata(rtd
->dev
, rtd
);
1176 mutex_init(&rtd
->pcm_mutex
);
1177 ret
= device_add(rtd
->dev
);
1180 "asoc: failed to register runtime device: %d\n", ret
);
1183 rtd
->dev_registered
= 1;
1185 /* add DAPM sysfs entries for this codec */
1186 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1189 "asoc: failed to add codec dapm sysfs entries: %d\n",
1192 /* add codec sysfs entries */
1193 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1196 "asoc: failed to add codec sysfs files: %d\n", ret
);
1201 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1203 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1204 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1205 struct snd_soc_codec
*codec
= rtd
->codec
;
1206 struct snd_soc_platform
*platform
= rtd
->platform
;
1207 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
1210 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1211 card
->name
, num
, order
);
1213 /* config components */
1214 codec_dai
->codec
= codec
;
1215 cpu_dai
->platform
= platform
;
1216 codec_dai
->card
= card
;
1217 cpu_dai
->card
= card
;
1219 /* set default power off timeout */
1220 rtd
->pmdown_time
= pmdown_time
;
1222 /* probe the cpu_dai */
1223 if (!cpu_dai
->probed
&&
1224 cpu_dai
->driver
->probe_order
== order
) {
1225 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1228 if (cpu_dai
->driver
->probe
) {
1229 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1231 pr_err("asoc: failed to probe CPU DAI %s: %d\n",
1232 cpu_dai
->name
, ret
);
1233 module_put(cpu_dai
->dev
->driver
->owner
);
1237 cpu_dai
->probed
= 1;
1238 /* mark cpu_dai as probed and add to card dai list */
1239 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1242 /* probe the CODEC */
1243 if (!codec
->probed
&&
1244 codec
->driver
->probe_order
== order
) {
1245 ret
= soc_probe_codec(card
, codec
);
1250 /* probe the platform */
1251 if (!platform
->probed
&&
1252 platform
->driver
->probe_order
== order
) {
1253 ret
= soc_probe_platform(card
, platform
);
1258 /* probe the CODEC DAI */
1259 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1260 if (codec_dai
->driver
->probe
) {
1261 ret
= codec_dai
->driver
->probe(codec_dai
);
1263 pr_err("asoc: failed to probe CODEC DAI %s: %d\n",
1264 codec_dai
->name
, ret
);
1269 /* mark codec_dai as probed and add to card dai list */
1270 codec_dai
->probed
= 1;
1271 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1274 /* complete DAI probe during last probe */
1275 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1278 ret
= soc_post_component_init(card
, codec
, num
, 0);
1282 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1284 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret
);
1286 /* create the pcm */
1287 ret
= soc_new_pcm(rtd
, num
);
1289 pr_err("asoc: can't create pcm %s :%d\n",
1290 dai_link
->stream_name
, ret
);
1294 /* add platform data for AC97 devices */
1295 if (rtd
->codec_dai
->driver
->ac97_control
)
1296 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1301 #ifdef CONFIG_SND_SOC_AC97_BUS
1302 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1306 /* Only instantiate AC97 if not already done by the adaptor
1307 * for the generic AC97 subsystem.
1309 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1311 * It is possible that the AC97 device is already registered to
1312 * the device subsystem. This happens when the device is created
1313 * via snd_ac97_mixer(). Currently only SoC codec that does so
1314 * is the generic AC97 glue but others migh emerge.
1316 * In those cases we don't try to register the device again.
1318 if (!rtd
->codec
->ac97_created
)
1321 ret
= soc_ac97_dev_register(rtd
->codec
);
1323 pr_err("asoc: AC97 device register failed:%d\n", ret
);
1327 rtd
->codec
->ac97_registered
= 1;
1332 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1334 if (codec
->ac97_registered
) {
1335 soc_ac97_dev_unregister(codec
);
1336 codec
->ac97_registered
= 0;
1341 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1343 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1344 struct snd_soc_codec
*codec
;
1347 /* find CODEC from registered CODECs*/
1348 list_for_each_entry(codec
, &codec_list
, list
) {
1349 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1350 if (codec
->probed
) {
1352 "asoc: codec already probed");
1359 /* codec not found */
1360 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1364 ret
= soc_probe_codec(card
, codec
);
1368 ret
= soc_post_component_init(card
, codec
, num
, 1);
1374 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1376 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1377 struct snd_soc_codec
*codec
= rtd
->codec
;
1379 /* unregister the rtd device */
1380 if (rtd
->dev_registered
) {
1381 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1382 device_del(rtd
->dev
);
1383 rtd
->dev_registered
= 0;
1386 if (codec
&& codec
->probed
)
1387 soc_remove_codec(codec
);
1390 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1391 enum snd_soc_compress_type compress_type
)
1395 if (codec
->cache_init
)
1398 /* override the compress_type if necessary */
1399 if (compress_type
&& codec
->compress_type
!= compress_type
)
1400 codec
->compress_type
= compress_type
;
1401 ret
= snd_soc_cache_init(codec
);
1403 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1407 codec
->cache_init
= 1;
1411 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
1413 struct snd_soc_codec
*codec
;
1414 struct snd_soc_codec_conf
*codec_conf
;
1415 enum snd_soc_compress_type compress_type
;
1416 struct snd_soc_dai_link
*dai_link
;
1419 mutex_lock(&card
->mutex
);
1421 if (card
->instantiated
) {
1422 mutex_unlock(&card
->mutex
);
1427 for (i
= 0; i
< card
->num_links
; i
++)
1428 soc_bind_dai_link(card
, i
);
1430 /* bind completed ? */
1431 if (card
->num_rtd
!= card
->num_links
) {
1432 mutex_unlock(&card
->mutex
);
1436 /* initialize the register cache for each available codec */
1437 list_for_each_entry(codec
, &codec_list
, list
) {
1438 if (codec
->cache_init
)
1440 /* by default we don't override the compress_type */
1442 /* check to see if we need to override the compress_type */
1443 for (i
= 0; i
< card
->num_configs
; ++i
) {
1444 codec_conf
= &card
->codec_conf
[i
];
1445 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1446 compress_type
= codec_conf
->compress_type
;
1447 if (compress_type
&& compress_type
1448 != codec
->compress_type
)
1452 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1454 mutex_unlock(&card
->mutex
);
1459 /* card bind complete so register a sound card */
1460 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1461 card
->owner
, 0, &card
->snd_card
);
1463 pr_err("asoc: can't create sound card for card %s: %d\n",
1465 mutex_unlock(&card
->mutex
);
1468 card
->snd_card
->dev
= card
->dev
;
1470 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1471 card
->dapm
.dev
= card
->dev
;
1472 card
->dapm
.card
= card
;
1473 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1475 #ifdef CONFIG_DEBUG_FS
1476 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1479 #ifdef CONFIG_PM_SLEEP
1480 /* deferred resume work */
1481 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1484 if (card
->dapm_widgets
)
1485 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1486 card
->num_dapm_widgets
);
1488 /* initialise the sound card only once */
1490 ret
= card
->probe(card
);
1492 goto card_probe_error
;
1495 /* early DAI link probe */
1496 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1498 for (i
= 0; i
< card
->num_links
; i
++) {
1499 ret
= soc_probe_dai_link(card
, i
, order
);
1501 pr_err("asoc: failed to instantiate card %s: %d\n",
1508 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1509 ret
= soc_probe_aux_dev(card
, i
);
1511 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1513 goto probe_aux_dev_err
;
1517 snd_soc_dapm_link_dai_widgets(card
);
1520 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1522 if (card
->dapm_routes
)
1523 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1524 card
->num_dapm_routes
);
1526 snd_soc_dapm_new_widgets(&card
->dapm
);
1528 for (i
= 0; i
< card
->num_links
; i
++) {
1529 dai_link
= &card
->dai_link
[i
];
1531 if (dai_link
->dai_fmt
) {
1532 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1535 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1536 "Failed to set DAI format: %d\n",
1539 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1542 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1543 "Failed to set DAI format: %d\n",
1548 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1550 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1551 "%s", card
->long_name
? card
->long_name
: card
->name
);
1552 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1553 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1554 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1555 switch (card
->snd_card
->driver
[i
]) {
1561 if (!isalnum(card
->snd_card
->driver
[i
]))
1562 card
->snd_card
->driver
[i
] = '_';
1567 if (card
->late_probe
) {
1568 ret
= card
->late_probe(card
);
1570 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1572 goto probe_aux_dev_err
;
1576 snd_soc_dapm_new_widgets(&card
->dapm
);
1578 if (card
->fully_routed
)
1579 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1580 snd_soc_dapm_auto_nc_codec_pins(codec
);
1582 ret
= snd_card_register(card
->snd_card
);
1584 pr_err("asoc: failed to register soundcard for %s: %d\n",
1586 goto probe_aux_dev_err
;
1589 #ifdef CONFIG_SND_SOC_AC97_BUS
1590 /* register any AC97 codecs */
1591 for (i
= 0; i
< card
->num_rtd
; i
++) {
1592 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1594 pr_err("asoc: failed to register AC97 %s: %d\n",
1597 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1598 goto probe_aux_dev_err
;
1603 card
->instantiated
= 1;
1604 snd_soc_dapm_sync(&card
->dapm
);
1605 mutex_unlock(&card
->mutex
);
1609 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1610 soc_remove_aux_dev(card
, i
);
1613 soc_remove_dai_links(card
);
1619 snd_card_free(card
->snd_card
);
1621 mutex_unlock(&card
->mutex
);
1625 * Attempt to initialise any uninitialised cards. Must be called with
1628 static void snd_soc_instantiate_cards(void)
1630 struct snd_soc_card
*card
;
1631 list_for_each_entry(card
, &card_list
, list
)
1632 snd_soc_instantiate_card(card
);
1635 /* probes a new socdev */
1636 static int soc_probe(struct platform_device
*pdev
)
1638 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1642 * no card, so machine driver should be registering card
1643 * we should not be here in that case so ret error
1648 dev_warn(&pdev
->dev
,
1649 "ASoC machine %s should use snd_soc_register_card()\n",
1652 /* Bodge while we unpick instantiation */
1653 card
->dev
= &pdev
->dev
;
1655 ret
= snd_soc_register_card(card
);
1657 dev_err(&pdev
->dev
, "Failed to register card\n");
1664 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1668 /* make sure any delayed work runs */
1669 for (i
= 0; i
< card
->num_rtd
; i
++) {
1670 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1671 flush_delayed_work_sync(&rtd
->delayed_work
);
1674 /* remove auxiliary devices */
1675 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1676 soc_remove_aux_dev(card
, i
);
1678 /* remove and free each DAI */
1679 soc_remove_dai_links(card
);
1681 soc_cleanup_card_debugfs(card
);
1683 /* remove the card */
1687 snd_soc_dapm_free(&card
->dapm
);
1690 snd_card_free(card
->snd_card
);
1695 /* removes a socdev */
1696 static int soc_remove(struct platform_device
*pdev
)
1698 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1700 snd_soc_unregister_card(card
);
1704 int snd_soc_poweroff(struct device
*dev
)
1706 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1709 if (!card
->instantiated
)
1712 /* Flush out pmdown_time work - we actually do want to run it
1713 * now, we're shutting down so no imminent restart. */
1714 for (i
= 0; i
< card
->num_rtd
; i
++) {
1715 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1716 flush_delayed_work_sync(&rtd
->delayed_work
);
1719 snd_soc_dapm_shutdown(card
);
1723 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1725 const struct dev_pm_ops snd_soc_pm_ops
= {
1726 .suspend
= snd_soc_suspend
,
1727 .resume
= snd_soc_resume
,
1728 .freeze
= snd_soc_suspend
,
1729 .thaw
= snd_soc_resume
,
1730 .poweroff
= snd_soc_poweroff
,
1731 .restore
= snd_soc_resume
,
1733 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1735 /* ASoC platform driver */
1736 static struct platform_driver soc_driver
= {
1738 .name
= "soc-audio",
1739 .owner
= THIS_MODULE
,
1740 .pm
= &snd_soc_pm_ops
,
1743 .remove
= soc_remove
,
1747 * snd_soc_codec_volatile_register: Report if a register is volatile.
1749 * @codec: CODEC to query.
1750 * @reg: Register to query.
1752 * Boolean function indiciating if a CODEC register is volatile.
1754 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1757 if (codec
->volatile_register
)
1758 return codec
->volatile_register(codec
, reg
);
1762 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1765 * snd_soc_codec_readable_register: Report if a register is readable.
1767 * @codec: CODEC to query.
1768 * @reg: Register to query.
1770 * Boolean function indicating if a CODEC register is readable.
1772 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1775 if (codec
->readable_register
)
1776 return codec
->readable_register(codec
, reg
);
1780 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1783 * snd_soc_codec_writable_register: Report if a register is writable.
1785 * @codec: CODEC to query.
1786 * @reg: Register to query.
1788 * Boolean function indicating if a CODEC register is writable.
1790 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1793 if (codec
->writable_register
)
1794 return codec
->writable_register(codec
, reg
);
1798 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1800 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1805 if (!platform
->driver
->read
) {
1806 dev_err(platform
->dev
, "platform has no read back\n");
1810 ret
= platform
->driver
->read(platform
, reg
);
1811 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1812 trace_snd_soc_preg_read(platform
, reg
, ret
);
1816 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1818 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1819 unsigned int reg
, unsigned int val
)
1821 if (!platform
->driver
->write
) {
1822 dev_err(platform
->dev
, "platform has no write back\n");
1826 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1827 trace_snd_soc_preg_write(platform
, reg
, val
);
1828 return platform
->driver
->write(platform
, reg
, val
);
1830 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1833 * snd_soc_new_ac97_codec - initailise AC97 device
1834 * @codec: audio codec
1835 * @ops: AC97 bus operations
1836 * @num: AC97 codec number
1838 * Initialises AC97 codec resources for use by ad-hoc devices only.
1840 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1841 struct snd_ac97_bus_ops
*ops
, int num
)
1843 mutex_lock(&codec
->mutex
);
1845 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1846 if (codec
->ac97
== NULL
) {
1847 mutex_unlock(&codec
->mutex
);
1851 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1852 if (codec
->ac97
->bus
== NULL
) {
1855 mutex_unlock(&codec
->mutex
);
1859 codec
->ac97
->bus
->ops
= ops
;
1860 codec
->ac97
->num
= num
;
1863 * Mark the AC97 device to be created by us. This way we ensure that the
1864 * device will be registered with the device subsystem later on.
1866 codec
->ac97_created
= 1;
1868 mutex_unlock(&codec
->mutex
);
1871 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1874 * snd_soc_free_ac97_codec - free AC97 codec device
1875 * @codec: audio codec
1877 * Frees AC97 codec device resources.
1879 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1881 mutex_lock(&codec
->mutex
);
1882 #ifdef CONFIG_SND_SOC_AC97_BUS
1883 soc_unregister_ac97_dai_link(codec
);
1885 kfree(codec
->ac97
->bus
);
1888 codec
->ac97_created
= 0;
1889 mutex_unlock(&codec
->mutex
);
1891 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1893 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1897 ret
= codec
->read(codec
, reg
);
1898 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1899 trace_snd_soc_reg_read(codec
, reg
, ret
);
1903 EXPORT_SYMBOL_GPL(snd_soc_read
);
1905 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
1906 unsigned int reg
, unsigned int val
)
1908 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
1909 trace_snd_soc_reg_write(codec
, reg
, val
);
1910 return codec
->write(codec
, reg
, val
);
1912 EXPORT_SYMBOL_GPL(snd_soc_write
);
1914 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
1915 unsigned int reg
, const void *data
, size_t len
)
1917 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
1919 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
1922 * snd_soc_update_bits - update codec register bits
1923 * @codec: audio codec
1924 * @reg: codec register
1925 * @mask: register mask
1928 * Writes new register value.
1930 * Returns 1 for change, 0 for no change, or negative error code.
1932 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1933 unsigned int mask
, unsigned int value
)
1936 unsigned int old
, new;
1939 if (codec
->using_regmap
) {
1940 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
1941 mask
, value
, &change
);
1943 ret
= snd_soc_read(codec
, reg
);
1948 new = (old
& ~mask
) | (value
& mask
);
1949 change
= old
!= new;
1951 ret
= snd_soc_write(codec
, reg
, new);
1959 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1962 * snd_soc_update_bits_locked - update codec register bits
1963 * @codec: audio codec
1964 * @reg: codec register
1965 * @mask: register mask
1968 * Writes new register value, and takes the codec mutex.
1970 * Returns 1 for change else 0.
1972 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
1973 unsigned short reg
, unsigned int mask
,
1978 mutex_lock(&codec
->mutex
);
1979 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
1980 mutex_unlock(&codec
->mutex
);
1984 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
1987 * snd_soc_test_bits - test register for change
1988 * @codec: audio codec
1989 * @reg: codec register
1990 * @mask: register mask
1993 * Tests a register with a new value and checks if the new value is
1994 * different from the old value.
1996 * Returns 1 for change else 0.
1998 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1999 unsigned int mask
, unsigned int value
)
2002 unsigned int old
, new;
2004 old
= snd_soc_read(codec
, reg
);
2005 new = (old
& ~mask
) | value
;
2006 change
= old
!= new;
2010 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
2013 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
2014 * @substream: the pcm substream
2015 * @hw: the hardware parameters
2017 * Sets the substream runtime hardware parameters.
2019 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
2020 const struct snd_pcm_hardware
*hw
)
2022 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2023 runtime
->hw
.info
= hw
->info
;
2024 runtime
->hw
.formats
= hw
->formats
;
2025 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
2026 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
2027 runtime
->hw
.periods_min
= hw
->periods_min
;
2028 runtime
->hw
.periods_max
= hw
->periods_max
;
2029 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
2030 runtime
->hw
.fifo_size
= hw
->fifo_size
;
2033 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
2036 * snd_soc_cnew - create new control
2037 * @_template: control template
2038 * @data: control private data
2039 * @long_name: control long name
2040 * @prefix: control name prefix
2042 * Create a new mixer control from a template control.
2044 * Returns 0 for success, else error.
2046 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2047 void *data
, const char *long_name
,
2050 struct snd_kcontrol_new
template;
2051 struct snd_kcontrol
*kcontrol
;
2055 memcpy(&template, _template
, sizeof(template));
2059 long_name
= template.name
;
2062 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
2063 name
= kmalloc(name_len
, GFP_KERNEL
);
2067 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
2069 template.name
= name
;
2071 template.name
= long_name
;
2074 kcontrol
= snd_ctl_new1(&template, data
);
2080 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2082 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2083 const struct snd_kcontrol_new
*controls
, int num_controls
,
2084 const char *prefix
, void *data
)
2088 for (i
= 0; i
< num_controls
; i
++) {
2089 const struct snd_kcontrol_new
*control
= &controls
[i
];
2090 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2091 control
->name
, prefix
));
2093 dev_err(dev
, "Failed to add %s: %d\n", control
->name
, err
);
2102 * snd_soc_add_codec_controls - add an array of controls to a codec.
2103 * Convenience function to add a list of controls. Many codecs were
2104 * duplicating this code.
2106 * @codec: codec to add controls to
2107 * @controls: array of controls to add
2108 * @num_controls: number of elements in the array
2110 * Return 0 for success, else error.
2112 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2113 const struct snd_kcontrol_new
*controls
, int num_controls
)
2115 struct snd_card
*card
= codec
->card
->snd_card
;
2117 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2118 codec
->name_prefix
, codec
);
2120 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2123 * snd_soc_add_platform_controls - add an array of controls to a platform.
2124 * Convenience function to add a list of controls.
2126 * @platform: platform to add controls to
2127 * @controls: array of controls to add
2128 * @num_controls: number of elements in the array
2130 * Return 0 for success, else error.
2132 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2133 const struct snd_kcontrol_new
*controls
, int num_controls
)
2135 struct snd_card
*card
= platform
->card
->snd_card
;
2137 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2140 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2143 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2144 * Convenience function to add a list of controls.
2146 * @soc_card: SoC card to add controls to
2147 * @controls: array of controls to add
2148 * @num_controls: number of elements in the array
2150 * Return 0 for success, else error.
2152 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2153 const struct snd_kcontrol_new
*controls
, int num_controls
)
2155 struct snd_card
*card
= soc_card
->snd_card
;
2157 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2160 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2163 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2164 * Convienience function to add a list of controls.
2166 * @dai: DAI to add controls to
2167 * @controls: array of controls to add
2168 * @num_controls: number of elements in the array
2170 * Return 0 for success, else error.
2172 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2173 const struct snd_kcontrol_new
*controls
, int num_controls
)
2175 struct snd_card
*card
= dai
->card
->snd_card
;
2177 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2180 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2183 * snd_soc_info_enum_double - enumerated double mixer info callback
2184 * @kcontrol: mixer control
2185 * @uinfo: control element information
2187 * Callback to provide information about a double enumerated
2190 * Returns 0 for success.
2192 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2193 struct snd_ctl_elem_info
*uinfo
)
2195 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2197 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2198 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2199 uinfo
->value
.enumerated
.items
= e
->max
;
2201 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2202 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2203 strcpy(uinfo
->value
.enumerated
.name
,
2204 e
->texts
[uinfo
->value
.enumerated
.item
]);
2207 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2210 * snd_soc_get_enum_double - enumerated double mixer get callback
2211 * @kcontrol: mixer control
2212 * @ucontrol: control element information
2214 * Callback to get the value of a double enumerated mixer.
2216 * Returns 0 for success.
2218 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2219 struct snd_ctl_elem_value
*ucontrol
)
2221 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2222 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2223 unsigned int val
, bitmask
;
2225 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2227 val
= snd_soc_read(codec
, e
->reg
);
2228 ucontrol
->value
.enumerated
.item
[0]
2229 = (val
>> e
->shift_l
) & (bitmask
- 1);
2230 if (e
->shift_l
!= e
->shift_r
)
2231 ucontrol
->value
.enumerated
.item
[1] =
2232 (val
>> e
->shift_r
) & (bitmask
- 1);
2236 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2239 * snd_soc_put_enum_double - enumerated double mixer put callback
2240 * @kcontrol: mixer control
2241 * @ucontrol: control element information
2243 * Callback to set the value of a double enumerated mixer.
2245 * Returns 0 for success.
2247 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2248 struct snd_ctl_elem_value
*ucontrol
)
2250 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2251 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2253 unsigned int mask
, bitmask
;
2255 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2257 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2259 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2260 mask
= (bitmask
- 1) << e
->shift_l
;
2261 if (e
->shift_l
!= e
->shift_r
) {
2262 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2264 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2265 mask
|= (bitmask
- 1) << e
->shift_r
;
2268 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2270 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2273 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2274 * @kcontrol: mixer control
2275 * @ucontrol: control element information
2277 * Callback to get the value of a double semi enumerated mixer.
2279 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2280 * used for handling bitfield coded enumeration for example.
2282 * Returns 0 for success.
2284 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2285 struct snd_ctl_elem_value
*ucontrol
)
2287 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2288 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2289 unsigned int reg_val
, val
, mux
;
2291 reg_val
= snd_soc_read(codec
, e
->reg
);
2292 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2293 for (mux
= 0; mux
< e
->max
; mux
++) {
2294 if (val
== e
->values
[mux
])
2297 ucontrol
->value
.enumerated
.item
[0] = mux
;
2298 if (e
->shift_l
!= e
->shift_r
) {
2299 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2300 for (mux
= 0; mux
< e
->max
; mux
++) {
2301 if (val
== e
->values
[mux
])
2304 ucontrol
->value
.enumerated
.item
[1] = mux
;
2309 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2312 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2313 * @kcontrol: mixer control
2314 * @ucontrol: control element information
2316 * Callback to set the value of a double semi enumerated mixer.
2318 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2319 * used for handling bitfield coded enumeration for example.
2321 * Returns 0 for success.
2323 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2324 struct snd_ctl_elem_value
*ucontrol
)
2326 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2327 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2331 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2333 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2334 mask
= e
->mask
<< e
->shift_l
;
2335 if (e
->shift_l
!= e
->shift_r
) {
2336 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2338 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2339 mask
|= e
->mask
<< e
->shift_r
;
2342 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2344 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2347 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2348 * @kcontrol: mixer control
2349 * @uinfo: control element information
2351 * Callback to provide information about an external enumerated
2354 * Returns 0 for success.
2356 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2357 struct snd_ctl_elem_info
*uinfo
)
2359 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2361 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2363 uinfo
->value
.enumerated
.items
= e
->max
;
2365 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2366 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2367 strcpy(uinfo
->value
.enumerated
.name
,
2368 e
->texts
[uinfo
->value
.enumerated
.item
]);
2371 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2374 * snd_soc_info_volsw_ext - external single mixer info callback
2375 * @kcontrol: mixer control
2376 * @uinfo: control element information
2378 * Callback to provide information about a single external mixer control.
2380 * Returns 0 for success.
2382 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2383 struct snd_ctl_elem_info
*uinfo
)
2385 int max
= kcontrol
->private_value
;
2387 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2388 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2390 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2393 uinfo
->value
.integer
.min
= 0;
2394 uinfo
->value
.integer
.max
= max
;
2397 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2400 * snd_soc_info_volsw - single mixer info callback
2401 * @kcontrol: mixer control
2402 * @uinfo: control element information
2404 * Callback to provide information about a single mixer control, or a double
2405 * mixer control that spans 2 registers.
2407 * Returns 0 for success.
2409 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2410 struct snd_ctl_elem_info
*uinfo
)
2412 struct soc_mixer_control
*mc
=
2413 (struct soc_mixer_control
*)kcontrol
->private_value
;
2416 if (!mc
->platform_max
)
2417 mc
->platform_max
= mc
->max
;
2418 platform_max
= mc
->platform_max
;
2420 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2421 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2423 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2425 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2426 uinfo
->value
.integer
.min
= 0;
2427 uinfo
->value
.integer
.max
= platform_max
;
2430 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2433 * snd_soc_get_volsw - single mixer get callback
2434 * @kcontrol: mixer control
2435 * @ucontrol: control element information
2437 * Callback to get the value of a single mixer control, or a double mixer
2438 * control that spans 2 registers.
2440 * Returns 0 for success.
2442 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2443 struct snd_ctl_elem_value
*ucontrol
)
2445 struct soc_mixer_control
*mc
=
2446 (struct soc_mixer_control
*)kcontrol
->private_value
;
2447 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2448 unsigned int reg
= mc
->reg
;
2449 unsigned int reg2
= mc
->rreg
;
2450 unsigned int shift
= mc
->shift
;
2451 unsigned int rshift
= mc
->rshift
;
2453 unsigned int mask
= (1 << fls(max
)) - 1;
2454 unsigned int invert
= mc
->invert
;
2456 ucontrol
->value
.integer
.value
[0] =
2457 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2459 ucontrol
->value
.integer
.value
[0] =
2460 max
- ucontrol
->value
.integer
.value
[0];
2462 if (snd_soc_volsw_is_stereo(mc
)) {
2464 ucontrol
->value
.integer
.value
[1] =
2465 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2467 ucontrol
->value
.integer
.value
[1] =
2468 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2470 ucontrol
->value
.integer
.value
[1] =
2471 max
- ucontrol
->value
.integer
.value
[1];
2476 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2479 * snd_soc_put_volsw - single mixer put callback
2480 * @kcontrol: mixer control
2481 * @ucontrol: control element information
2483 * Callback to set the value of a single mixer control, or a double mixer
2484 * control that spans 2 registers.
2486 * Returns 0 for success.
2488 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2489 struct snd_ctl_elem_value
*ucontrol
)
2491 struct soc_mixer_control
*mc
=
2492 (struct soc_mixer_control
*)kcontrol
->private_value
;
2493 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2494 unsigned int reg
= mc
->reg
;
2495 unsigned int reg2
= mc
->rreg
;
2496 unsigned int shift
= mc
->shift
;
2497 unsigned int rshift
= mc
->rshift
;
2499 unsigned int mask
= (1 << fls(max
)) - 1;
2500 unsigned int invert
= mc
->invert
;
2503 unsigned int val2
= 0;
2504 unsigned int val
, val_mask
;
2506 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2509 val_mask
= mask
<< shift
;
2511 if (snd_soc_volsw_is_stereo(mc
)) {
2512 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2516 val_mask
|= mask
<< rshift
;
2517 val
|= val2
<< rshift
;
2519 val2
= val2
<< shift
;
2523 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2528 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2532 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2535 * snd_soc_info_volsw_s8 - signed mixer info callback
2536 * @kcontrol: mixer control
2537 * @uinfo: control element information
2539 * Callback to provide information about a signed mixer control.
2541 * Returns 0 for success.
2543 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2544 struct snd_ctl_elem_info
*uinfo
)
2546 struct soc_mixer_control
*mc
=
2547 (struct soc_mixer_control
*)kcontrol
->private_value
;
2551 if (!mc
->platform_max
)
2552 mc
->platform_max
= mc
->max
;
2553 platform_max
= mc
->platform_max
;
2555 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2557 uinfo
->value
.integer
.min
= 0;
2558 uinfo
->value
.integer
.max
= platform_max
- min
;
2561 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2564 * snd_soc_get_volsw_s8 - signed mixer get callback
2565 * @kcontrol: mixer control
2566 * @ucontrol: control element information
2568 * Callback to get the value of a signed mixer control.
2570 * Returns 0 for success.
2572 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2573 struct snd_ctl_elem_value
*ucontrol
)
2575 struct soc_mixer_control
*mc
=
2576 (struct soc_mixer_control
*)kcontrol
->private_value
;
2577 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2578 unsigned int reg
= mc
->reg
;
2580 int val
= snd_soc_read(codec
, reg
);
2582 ucontrol
->value
.integer
.value
[0] =
2583 ((signed char)(val
& 0xff))-min
;
2584 ucontrol
->value
.integer
.value
[1] =
2585 ((signed char)((val
>> 8) & 0xff))-min
;
2588 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2591 * snd_soc_put_volsw_sgn - signed mixer put callback
2592 * @kcontrol: mixer control
2593 * @ucontrol: control element information
2595 * Callback to set the value of a signed mixer control.
2597 * Returns 0 for success.
2599 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2600 struct snd_ctl_elem_value
*ucontrol
)
2602 struct soc_mixer_control
*mc
=
2603 (struct soc_mixer_control
*)kcontrol
->private_value
;
2604 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2605 unsigned int reg
= mc
->reg
;
2609 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2610 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2612 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2614 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2617 * snd_soc_limit_volume - Set new limit to an existing volume control.
2619 * @codec: where to look for the control
2620 * @name: Name of the control
2621 * @max: new maximum limit
2623 * Return 0 for success, else error.
2625 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2626 const char *name
, int max
)
2628 struct snd_card
*card
= codec
->card
->snd_card
;
2629 struct snd_kcontrol
*kctl
;
2630 struct soc_mixer_control
*mc
;
2634 /* Sanity check for name and max */
2635 if (unlikely(!name
|| max
<= 0))
2638 list_for_each_entry(kctl
, &card
->controls
, list
) {
2639 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2645 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2646 if (max
<= mc
->max
) {
2647 mc
->platform_max
= max
;
2653 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2656 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2657 * mixer info callback
2658 * @kcontrol: mixer control
2659 * @uinfo: control element information
2661 * Returns 0 for success.
2663 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2664 struct snd_ctl_elem_info
*uinfo
)
2666 struct soc_mixer_control
*mc
=
2667 (struct soc_mixer_control
*)kcontrol
->private_value
;
2671 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2673 uinfo
->value
.integer
.min
= 0;
2674 uinfo
->value
.integer
.max
= max
-min
;
2678 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx
);
2681 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2682 * mixer get callback
2683 * @kcontrol: mixer control
2684 * @uinfo: control element information
2686 * Returns 0 for success.
2688 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2689 struct snd_ctl_elem_value
*ucontrol
)
2691 struct soc_mixer_control
*mc
=
2692 (struct soc_mixer_control
*)kcontrol
->private_value
;
2693 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2694 unsigned int mask
= (1<<mc
->shift
)-1;
2696 int val
= snd_soc_read(codec
, mc
->reg
) & mask
;
2697 int valr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2699 ucontrol
->value
.integer
.value
[0] = ((val
& 0xff)-min
) & mask
;
2700 ucontrol
->value
.integer
.value
[1] = ((valr
& 0xff)-min
) & mask
;
2703 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx
);
2706 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2707 * mixer put callback
2708 * @kcontrol: mixer control
2709 * @uinfo: control element information
2711 * Returns 0 for success.
2713 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2714 struct snd_ctl_elem_value
*ucontrol
)
2716 struct soc_mixer_control
*mc
=
2717 (struct soc_mixer_control
*)kcontrol
->private_value
;
2718 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2719 unsigned int mask
= (1<<mc
->shift
)-1;
2722 unsigned int val
, valr
, oval
, ovalr
;
2724 val
= ((ucontrol
->value
.integer
.value
[0]+min
) & 0xff);
2726 valr
= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff);
2729 oval
= snd_soc_read(codec
, mc
->reg
) & mask
;
2730 ovalr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2734 ret
= snd_soc_write(codec
, mc
->reg
, val
);
2738 if (ovalr
!= valr
) {
2739 ret
= snd_soc_write(codec
, mc
->rreg
, valr
);
2746 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx
);
2748 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
2749 struct snd_ctl_elem_info
*uinfo
)
2751 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2752 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2754 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
2755 uinfo
->count
= params
->num_regs
* codec
->val_bytes
;
2759 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
2761 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
2762 struct snd_ctl_elem_value
*ucontrol
)
2764 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2765 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2768 if (codec
->using_regmap
)
2769 ret
= regmap_raw_read(codec
->control_data
, params
->base
,
2770 ucontrol
->value
.bytes
.data
,
2771 params
->num_regs
* codec
->val_bytes
);
2775 /* Hide any masked bytes to ensure consistent data reporting */
2776 if (ret
== 0 && params
->mask
) {
2777 switch (codec
->val_bytes
) {
2779 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
2782 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
2786 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
2796 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
2798 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
2799 struct snd_ctl_elem_value
*ucontrol
)
2801 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2802 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2807 if (!codec
->using_regmap
)
2810 data
= ucontrol
->value
.bytes
.data
;
2811 len
= params
->num_regs
* codec
->val_bytes
;
2814 * If we've got a mask then we need to preserve the register
2815 * bits. We shouldn't modify the incoming data so take a
2819 ret
= regmap_read(codec
->control_data
, params
->base
, &val
);
2823 val
&= params
->mask
;
2825 data
= kmemdup(data
, len
, GFP_KERNEL
);
2829 switch (codec
->val_bytes
) {
2831 ((u8
*)data
)[0] &= ~params
->mask
;
2832 ((u8
*)data
)[0] |= val
;
2835 ((u16
*)data
)[0] &= cpu_to_be16(~params
->mask
);
2836 ((u16
*)data
)[0] |= cpu_to_be16(val
);
2839 ((u32
*)data
)[0] &= cpu_to_be32(~params
->mask
);
2840 ((u32
*)data
)[0] |= cpu_to_be32(val
);
2847 ret
= regmap_raw_write(codec
->control_data
, params
->base
,
2855 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
2858 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2860 * @clk_id: DAI specific clock ID
2861 * @freq: new clock frequency in Hz
2862 * @dir: new clock direction - input/output.
2864 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2866 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2867 unsigned int freq
, int dir
)
2869 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
2870 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
2871 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
2872 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
2877 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2880 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2882 * @clk_id: DAI specific clock ID
2883 * @source: Source for the clock
2884 * @freq: new clock frequency in Hz
2885 * @dir: new clock direction - input/output.
2887 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2889 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
2890 int source
, unsigned int freq
, int dir
)
2892 if (codec
->driver
->set_sysclk
)
2893 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
2898 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
2901 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2903 * @div_id: DAI specific clock divider ID
2904 * @div: new clock divisor.
2906 * Configures the clock dividers. This is used to derive the best DAI bit and
2907 * frame clocks from the system or master clock. It's best to set the DAI bit
2908 * and frame clocks as low as possible to save system power.
2910 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2911 int div_id
, int div
)
2913 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
2914 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
2918 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2921 * snd_soc_dai_set_pll - configure DAI PLL.
2923 * @pll_id: DAI specific PLL ID
2924 * @source: DAI specific source for the PLL
2925 * @freq_in: PLL input clock frequency in Hz
2926 * @freq_out: requested PLL output clock frequency in Hz
2928 * Configures and enables PLL to generate output clock based on input clock.
2930 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2931 unsigned int freq_in
, unsigned int freq_out
)
2933 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
2934 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
2936 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
2937 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
2942 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2945 * snd_soc_codec_set_pll - configure codec PLL.
2947 * @pll_id: DAI specific PLL ID
2948 * @source: DAI specific source for the PLL
2949 * @freq_in: PLL input clock frequency in Hz
2950 * @freq_out: requested PLL output clock frequency in Hz
2952 * Configures and enables PLL to generate output clock based on input clock.
2954 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
2955 unsigned int freq_in
, unsigned int freq_out
)
2957 if (codec
->driver
->set_pll
)
2958 return codec
->driver
->set_pll(codec
, pll_id
, source
,
2963 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
2966 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2968 * @fmt: SND_SOC_DAIFMT_ format value.
2970 * Configures the DAI hardware format and clocking.
2972 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2974 if (dai
->driver
&& dai
->driver
->ops
->set_fmt
)
2975 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
2979 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2982 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2984 * @tx_mask: bitmask representing active TX slots.
2985 * @rx_mask: bitmask representing active RX slots.
2986 * @slots: Number of slots in use.
2987 * @slot_width: Width in bits for each slot.
2989 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2992 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2993 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
2995 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
2996 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3001 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3004 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3006 * @tx_num: how many TX channels
3007 * @tx_slot: pointer to an array which imply the TX slot number channel
3009 * @rx_num: how many RX channels
3010 * @rx_slot: pointer to an array which imply the RX slot number channel
3013 * configure the relationship between channel number and TDM slot number.
3015 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3016 unsigned int tx_num
, unsigned int *tx_slot
,
3017 unsigned int rx_num
, unsigned int *rx_slot
)
3019 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3020 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3025 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3028 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3030 * @tristate: tristate enable
3032 * Tristates the DAI so that others can use it.
3034 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3036 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3037 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3041 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3044 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3046 * @mute: mute enable
3048 * Mutes the DAI DAC.
3050 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
3052 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
3053 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3057 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3060 * snd_soc_register_card - Register a card with the ASoC core
3062 * @card: Card to register
3065 int snd_soc_register_card(struct snd_soc_card
*card
)
3069 if (!card
->name
|| !card
->dev
)
3072 for (i
= 0; i
< card
->num_links
; i
++) {
3073 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3076 * Codec must be specified by 1 of name or OF node,
3077 * not both or neither.
3079 if (!!link
->codec_name
== !!link
->codec_of_node
) {
3081 "Neither/both codec name/of_node are set for %s\n",
3087 * Platform may be specified by either name or OF node, but
3088 * can be left unspecified, and a dummy platform will be used.
3090 if (link
->platform_name
&& link
->platform_of_node
) {
3092 "Both platform name/of_node are set for %s\n", link
->name
);
3097 * CPU DAI must be specified by 1 of name or OF node,
3098 * not both or neither.
3100 if (!!link
->cpu_dai_name
== !!link
->cpu_dai_of_node
) {
3102 "Neither/both cpu_dai name/of_node are set for %s\n",
3108 dev_set_drvdata(card
->dev
, card
);
3110 snd_soc_initialize_card_lists(card
);
3112 soc_init_card_debugfs(card
);
3114 card
->rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
) *
3115 (card
->num_links
+ card
->num_aux_devs
),
3117 if (card
->rtd
== NULL
)
3119 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3121 for (i
= 0; i
< card
->num_links
; i
++)
3122 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3124 INIT_LIST_HEAD(&card
->list
);
3125 INIT_LIST_HEAD(&card
->dapm_dirty
);
3126 card
->instantiated
= 0;
3127 mutex_init(&card
->mutex
);
3129 mutex_lock(&client_mutex
);
3130 list_add(&card
->list
, &card_list
);
3131 snd_soc_instantiate_cards();
3132 mutex_unlock(&client_mutex
);
3134 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
3138 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3141 * snd_soc_unregister_card - Unregister a card with the ASoC core
3143 * @card: Card to unregister
3146 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3148 if (card
->instantiated
)
3149 soc_cleanup_card_resources(card
);
3150 mutex_lock(&client_mutex
);
3151 list_del(&card
->list
);
3152 mutex_unlock(&client_mutex
);
3153 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
3157 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3160 * Simplify DAI link configuration by removing ".-1" from device names
3161 * and sanitizing names.
3163 static char *fmt_single_name(struct device
*dev
, int *id
)
3165 char *found
, name
[NAME_SIZE
];
3168 if (dev_name(dev
) == NULL
)
3171 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3173 /* are we a "%s.%d" name (platform and SPI components) */
3174 found
= strstr(name
, dev
->driver
->name
);
3177 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3179 /* discard ID from name if ID == -1 */
3181 found
[strlen(dev
->driver
->name
)] = '\0';
3185 /* I2C component devices are named "bus-addr" */
3186 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3187 char tmp
[NAME_SIZE
];
3189 /* create unique ID number from I2C addr and bus */
3190 *id
= ((id1
& 0xffff) << 16) + id2
;
3192 /* sanitize component name for DAI link creation */
3193 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3194 strlcpy(name
, tmp
, NAME_SIZE
);
3199 return kstrdup(name
, GFP_KERNEL
);
3203 * Simplify DAI link naming for single devices with multiple DAIs by removing
3204 * any ".-1" and using the DAI name (instead of device name).
3206 static inline char *fmt_multiple_name(struct device
*dev
,
3207 struct snd_soc_dai_driver
*dai_drv
)
3209 if (dai_drv
->name
== NULL
) {
3210 pr_err("asoc: error - multiple DAI %s registered with no name\n",
3215 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3219 * snd_soc_register_dai - Register a DAI with the ASoC core
3221 * @dai: DAI to register
3223 int snd_soc_register_dai(struct device
*dev
,
3224 struct snd_soc_dai_driver
*dai_drv
)
3226 struct snd_soc_dai
*dai
;
3228 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
3230 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3234 /* create DAI component name */
3235 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3236 if (dai
->name
== NULL
) {
3242 dai
->driver
= dai_drv
;
3243 if (!dai
->driver
->ops
)
3244 dai
->driver
->ops
= &null_dai_ops
;
3246 mutex_lock(&client_mutex
);
3247 list_add(&dai
->list
, &dai_list
);
3248 snd_soc_instantiate_cards();
3249 mutex_unlock(&client_mutex
);
3251 pr_debug("Registered DAI '%s'\n", dai
->name
);
3255 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3258 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3260 * @dai: DAI to unregister
3262 void snd_soc_unregister_dai(struct device
*dev
)
3264 struct snd_soc_dai
*dai
;
3266 list_for_each_entry(dai
, &dai_list
, list
) {
3267 if (dev
== dai
->dev
)
3273 mutex_lock(&client_mutex
);
3274 list_del(&dai
->list
);
3275 mutex_unlock(&client_mutex
);
3277 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3281 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3284 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3286 * @dai: Array of DAIs to register
3287 * @count: Number of DAIs
3289 int snd_soc_register_dais(struct device
*dev
,
3290 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3292 struct snd_soc_dai
*dai
;
3295 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3297 for (i
= 0; i
< count
; i
++) {
3299 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3305 /* create DAI component name */
3306 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3307 if (dai
->name
== NULL
) {
3314 dai
->driver
= &dai_drv
[i
];
3315 if (dai
->driver
->id
)
3316 dai
->id
= dai
->driver
->id
;
3319 if (!dai
->driver
->ops
)
3320 dai
->driver
->ops
= &null_dai_ops
;
3322 mutex_lock(&client_mutex
);
3323 list_add(&dai
->list
, &dai_list
);
3324 mutex_unlock(&client_mutex
);
3326 pr_debug("Registered DAI '%s'\n", dai
->name
);
3329 mutex_lock(&client_mutex
);
3330 snd_soc_instantiate_cards();
3331 mutex_unlock(&client_mutex
);
3335 for (i
--; i
>= 0; i
--)
3336 snd_soc_unregister_dai(dev
);
3340 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3343 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3345 * @dai: Array of DAIs to unregister
3346 * @count: Number of DAIs
3348 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3352 for (i
= 0; i
< count
; i
++)
3353 snd_soc_unregister_dai(dev
);
3355 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3358 * snd_soc_register_platform - Register a platform with the ASoC core
3360 * @platform: platform to register
3362 int snd_soc_register_platform(struct device
*dev
,
3363 struct snd_soc_platform_driver
*platform_drv
)
3365 struct snd_soc_platform
*platform
;
3367 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3369 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3370 if (platform
== NULL
)
3373 /* create platform component name */
3374 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3375 if (platform
->name
== NULL
) {
3380 platform
->dev
= dev
;
3381 platform
->driver
= platform_drv
;
3382 platform
->dapm
.dev
= dev
;
3383 platform
->dapm
.platform
= platform
;
3384 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3385 mutex_init(&platform
->mutex
);
3387 mutex_lock(&client_mutex
);
3388 list_add(&platform
->list
, &platform_list
);
3389 snd_soc_instantiate_cards();
3390 mutex_unlock(&client_mutex
);
3392 pr_debug("Registered platform '%s'\n", platform
->name
);
3396 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3399 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3401 * @platform: platform to unregister
3403 void snd_soc_unregister_platform(struct device
*dev
)
3405 struct snd_soc_platform
*platform
;
3407 list_for_each_entry(platform
, &platform_list
, list
) {
3408 if (dev
== platform
->dev
)
3414 mutex_lock(&client_mutex
);
3415 list_del(&platform
->list
);
3416 mutex_unlock(&client_mutex
);
3418 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3419 kfree(platform
->name
);
3422 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3424 static u64 codec_format_map
[] = {
3425 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3426 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3427 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3428 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3429 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3430 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3431 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3432 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3433 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3434 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3435 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3436 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3437 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3438 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3439 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3440 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3443 /* Fix up the DAI formats for endianness: codecs don't actually see
3444 * the endianness of the data but we're using the CPU format
3445 * definitions which do need to include endianness so we ensure that
3446 * codec DAIs always have both big and little endian variants set.
3448 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3452 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3453 if (stream
->formats
& codec_format_map
[i
])
3454 stream
->formats
|= codec_format_map
[i
];
3458 * snd_soc_register_codec - Register a codec with the ASoC core
3460 * @codec: codec to register
3462 int snd_soc_register_codec(struct device
*dev
,
3463 const struct snd_soc_codec_driver
*codec_drv
,
3464 struct snd_soc_dai_driver
*dai_drv
,
3468 struct snd_soc_codec
*codec
;
3471 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3473 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3477 /* create CODEC component name */
3478 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3479 if (codec
->name
== NULL
) {
3484 if (codec_drv
->compress_type
)
3485 codec
->compress_type
= codec_drv
->compress_type
;
3487 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3489 codec
->write
= codec_drv
->write
;
3490 codec
->read
= codec_drv
->read
;
3491 codec
->volatile_register
= codec_drv
->volatile_register
;
3492 codec
->readable_register
= codec_drv
->readable_register
;
3493 codec
->writable_register
= codec_drv
->writable_register
;
3494 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
3495 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3496 codec
->dapm
.dev
= dev
;
3497 codec
->dapm
.codec
= codec
;
3498 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3499 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3501 codec
->driver
= codec_drv
;
3502 codec
->num_dai
= num_dai
;
3503 mutex_init(&codec
->mutex
);
3505 /* allocate CODEC register cache */
3506 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3507 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3508 codec
->reg_size
= reg_size
;
3509 /* it is necessary to make a copy of the default register cache
3510 * because in the case of using a compression type that requires
3511 * the default register cache to be marked as __devinitconst the
3512 * kernel might have freed the array by the time we initialize
3515 if (codec_drv
->reg_cache_default
) {
3516 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3517 reg_size
, GFP_KERNEL
);
3518 if (!codec
->reg_def_copy
) {
3525 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3526 if (!codec
->volatile_register
)
3527 codec
->volatile_register
= snd_soc_default_volatile_register
;
3528 if (!codec
->readable_register
)
3529 codec
->readable_register
= snd_soc_default_readable_register
;
3530 if (!codec
->writable_register
)
3531 codec
->writable_register
= snd_soc_default_writable_register
;
3534 for (i
= 0; i
< num_dai
; i
++) {
3535 fixup_codec_formats(&dai_drv
[i
].playback
);
3536 fixup_codec_formats(&dai_drv
[i
].capture
);
3539 /* register any DAIs */
3541 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3546 mutex_lock(&client_mutex
);
3547 list_add(&codec
->list
, &codec_list
);
3548 snd_soc_instantiate_cards();
3549 mutex_unlock(&client_mutex
);
3551 pr_debug("Registered codec '%s'\n", codec
->name
);
3555 kfree(codec
->reg_def_copy
);
3556 codec
->reg_def_copy
= NULL
;
3561 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3564 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3566 * @codec: codec to unregister
3568 void snd_soc_unregister_codec(struct device
*dev
)
3570 struct snd_soc_codec
*codec
;
3573 list_for_each_entry(codec
, &codec_list
, list
) {
3574 if (dev
== codec
->dev
)
3581 for (i
= 0; i
< codec
->num_dai
; i
++)
3582 snd_soc_unregister_dai(dev
);
3584 mutex_lock(&client_mutex
);
3585 list_del(&codec
->list
);
3586 mutex_unlock(&client_mutex
);
3588 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3590 snd_soc_cache_exit(codec
);
3591 kfree(codec
->reg_def_copy
);
3595 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3597 /* Retrieve a card's name from device tree */
3598 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
3599 const char *propname
)
3601 struct device_node
*np
= card
->dev
->of_node
;
3604 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
3606 * EINVAL means the property does not exist. This is fine providing
3607 * card->name was previously set, which is checked later in
3608 * snd_soc_register_card.
3610 if (ret
< 0 && ret
!= -EINVAL
) {
3612 "Property '%s' could not be read: %d\n",
3619 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
3621 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
3622 const char *propname
)
3624 struct device_node
*np
= card
->dev
->of_node
;
3626 struct snd_soc_dapm_route
*routes
;
3629 num_routes
= of_property_count_strings(np
, propname
);
3630 if (num_routes
& 1) {
3632 "Property '%s's length is not even\n",
3639 "Property '%s's length is zero\n",
3644 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
3648 "Could not allocate DAPM route table\n");
3652 for (i
= 0; i
< num_routes
; i
++) {
3653 ret
= of_property_read_string_index(np
, propname
,
3654 2 * i
, &routes
[i
].sink
);
3657 "Property '%s' index %d could not be read: %d\n",
3658 propname
, 2 * i
, ret
);
3661 ret
= of_property_read_string_index(np
, propname
,
3662 (2 * i
) + 1, &routes
[i
].source
);
3665 "Property '%s' index %d could not be read: %d\n",
3666 propname
, (2 * i
) + 1, ret
);
3671 card
->num_dapm_routes
= num_routes
;
3672 card
->dapm_routes
= routes
;
3676 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
3678 static int __init
snd_soc_init(void)
3680 #ifdef CONFIG_DEBUG_FS
3681 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3682 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3683 pr_warn("ASoC: Failed to create debugfs directory\n");
3684 snd_soc_debugfs_root
= NULL
;
3687 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3689 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3691 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3693 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3695 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3696 &platform_list_fops
))
3697 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3700 snd_soc_util_init();
3702 return platform_driver_register(&soc_driver
);
3704 module_init(snd_soc_init
);
3706 static void __exit
snd_soc_exit(void)
3708 snd_soc_util_exit();
3710 #ifdef CONFIG_DEBUG_FS
3711 debugfs_remove_recursive(snd_soc_debugfs_root
);
3713 platform_driver_unregister(&soc_driver
);
3715 module_exit(snd_soc_exit
);
3717 /* Module information */
3718 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3719 MODULE_DESCRIPTION("ALSA SoC Core");
3720 MODULE_LICENSE("GPL");
3721 MODULE_ALIAS("platform:soc-audio");