2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 * o Add hw rules to enforce rates, etc.
20 * o More testing with other codecs/machines.
21 * o Add more codecs and platforms to ensure good API coverage.
22 * o Support TDM on PCM and I2S
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
30 #include <linux/bitops.h>
31 #include <linux/debugfs.h>
32 #include <linux/platform_device.h>
33 #include <linux/ctype.h>
34 #include <linux/slab.h>
36 #include <sound/ac97_codec.h>
37 #include <sound/core.h>
38 #include <sound/jack.h>
39 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/soc.h>
42 #include <sound/initval.h>
44 #define CREATE_TRACE_POINTS
45 #include <trace/events/asoc.h>
49 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
51 #ifdef CONFIG_DEBUG_FS
52 struct dentry
*snd_soc_debugfs_root
;
53 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
56 static DEFINE_MUTEX(client_mutex
);
57 static LIST_HEAD(card_list
);
58 static LIST_HEAD(dai_list
);
59 static LIST_HEAD(platform_list
);
60 static LIST_HEAD(codec_list
);
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
67 static int pmdown_time
= 5000;
68 module_param(pmdown_time
, int, 0);
69 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
71 /* returns the minimum number of bytes needed to represent
72 * a particular given value */
73 static int min_bytes_needed(unsigned long val
)
78 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
81 c
= (sizeof val
* 8) - c
;
89 /* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91 static int format_register_str(struct snd_soc_codec
*codec
,
92 unsigned int reg
, char *buf
, size_t len
)
94 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
95 int regsize
= codec
->driver
->reg_word_size
* 2;
98 char regbuf
[regsize
+ 1];
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize
+ regsize
+ 2 + 1 != len
)
108 ret
= snd_soc_read(codec
, reg
);
110 memset(regbuf
, 'X', regsize
);
111 regbuf
[regsize
] = '\0';
113 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
116 /* prepare the buffer */
117 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf
, tmpbuf
, len
);
124 /* codec register dump */
125 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
126 size_t count
, loff_t pos
)
129 int wordsize
, regsize
;
134 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
135 regsize
= codec
->driver
->reg_word_size
* 2;
137 len
= wordsize
+ regsize
+ 2 + 1;
139 if (!codec
->driver
->reg_cache_size
)
142 if (codec
->driver
->reg_cache_step
)
143 step
= codec
->driver
->reg_cache_step
;
145 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
146 if (!snd_soc_codec_readable_register(codec
, i
))
148 if (codec
->driver
->display_register
) {
149 count
+= codec
->driver
->display_register(codec
, buf
+ count
,
150 PAGE_SIZE
- count
, i
);
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
155 if (total
+ len
>= count
- 1)
157 format_register_str(codec
, i
, buf
+ total
, len
);
164 total
= min(total
, count
- 1);
169 static ssize_t
codec_reg_show(struct device
*dev
,
170 struct device_attribute
*attr
, char *buf
)
172 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
174 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
177 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
179 static ssize_t
pmdown_time_show(struct device
*dev
,
180 struct device_attribute
*attr
, char *buf
)
182 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
184 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
187 static ssize_t
pmdown_time_set(struct device
*dev
,
188 struct device_attribute
*attr
,
189 const char *buf
, size_t count
)
191 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
194 ret
= strict_strtol(buf
, 10, &rtd
->pmdown_time
);
201 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
203 #ifdef CONFIG_DEBUG_FS
204 static int codec_reg_open_file(struct inode
*inode
, struct file
*file
)
206 file
->private_data
= inode
->i_private
;
210 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
211 size_t count
, loff_t
*ppos
)
214 struct snd_soc_codec
*codec
= file
->private_data
;
217 if (*ppos
< 0 || !count
)
220 buf
= kmalloc(count
, GFP_KERNEL
);
224 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
226 if (copy_to_user(user_buf
, buf
, ret
)) {
237 static ssize_t
codec_reg_write_file(struct file
*file
,
238 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
243 unsigned long reg
, value
;
244 struct snd_soc_codec
*codec
= file
->private_data
;
246 buf_size
= min(count
, (sizeof(buf
)-1));
247 if (copy_from_user(buf
, user_buf
, buf_size
))
251 while (*start
== ' ')
253 reg
= simple_strtoul(start
, &start
, 16);
254 while (*start
== ' ')
256 if (strict_strtoul(start
, 16, &value
))
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER
);
262 snd_soc_write(codec
, reg
, value
);
266 static const struct file_operations codec_reg_fops
= {
267 .open
= codec_reg_open_file
,
268 .read
= codec_reg_read_file
,
269 .write
= codec_reg_write_file
,
270 .llseek
= default_llseek
,
273 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
275 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
277 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
279 if (!codec
->debugfs_codec_root
) {
281 "ASoC: Failed to create codec debugfs directory\n");
285 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
287 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
290 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
291 codec
->debugfs_codec_root
,
292 codec
, &codec_reg_fops
);
293 if (!codec
->debugfs_reg
)
295 "ASoC: Failed to create codec register debugfs file\n");
297 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
300 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
302 debugfs_remove_recursive(codec
->debugfs_codec_root
);
305 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
306 size_t count
, loff_t
*ppos
)
308 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
309 ssize_t len
, ret
= 0;
310 struct snd_soc_codec
*codec
;
315 list_for_each_entry(codec
, &codec_list
, list
) {
316 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
320 if (ret
> PAGE_SIZE
) {
327 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
334 static const struct file_operations codec_list_fops
= {
335 .read
= codec_list_read_file
,
336 .llseek
= default_llseek
,/* read accesses f_pos */
339 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
340 size_t count
, loff_t
*ppos
)
342 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
343 ssize_t len
, ret
= 0;
344 struct snd_soc_dai
*dai
;
349 list_for_each_entry(dai
, &dai_list
, list
) {
350 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
353 if (ret
> PAGE_SIZE
) {
359 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
366 static const struct file_operations dai_list_fops
= {
367 .read
= dai_list_read_file
,
368 .llseek
= default_llseek
,/* read accesses f_pos */
371 static ssize_t
platform_list_read_file(struct file
*file
,
372 char __user
*user_buf
,
373 size_t count
, loff_t
*ppos
)
375 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
376 ssize_t len
, ret
= 0;
377 struct snd_soc_platform
*platform
;
382 list_for_each_entry(platform
, &platform_list
, list
) {
383 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
387 if (ret
> PAGE_SIZE
) {
393 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
400 static const struct file_operations platform_list_fops
= {
401 .read
= platform_list_read_file
,
402 .llseek
= default_llseek
,/* read accesses f_pos */
405 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
407 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
408 snd_soc_debugfs_root
);
409 if (!card
->debugfs_card_root
) {
411 "ASoC: Failed to create card debugfs directory\n");
415 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
416 card
->debugfs_card_root
,
418 if (!card
->debugfs_pop_time
)
420 "Failed to create pop time debugfs file\n");
423 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
425 debugfs_remove_recursive(card
->debugfs_card_root
);
430 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
434 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
438 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
442 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
447 #ifdef CONFIG_SND_SOC_AC97_BUS
448 /* unregister ac97 codec */
449 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
451 if (codec
->ac97
->dev
.bus
)
452 device_unregister(&codec
->ac97
->dev
);
456 /* stop no dev release warning */
457 static void soc_ac97_device_release(struct device
*dev
){}
459 /* register ac97 codec to bus */
460 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
464 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
465 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
466 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
468 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
469 codec
->card
->snd_card
->number
, 0, codec
->name
);
470 err
= device_register(&codec
->ac97
->dev
);
472 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
473 codec
->ac97
->dev
.bus
= NULL
;
480 #ifdef CONFIG_PM_SLEEP
481 /* powers down audio subsystem for suspend */
482 int snd_soc_suspend(struct device
*dev
)
484 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
485 struct snd_soc_codec
*codec
;
488 /* If the initialization of this soc device failed, there is no codec
489 * associated with it. Just bail out in this case.
491 if (list_empty(&card
->codec_dev_list
))
494 /* Due to the resume being scheduled into a workqueue we could
495 * suspend before that's finished - wait for it to complete.
497 snd_power_lock(card
->snd_card
);
498 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
499 snd_power_unlock(card
->snd_card
);
501 /* we're going to block userspace touching us until resume completes */
502 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
504 /* mute any active DACs */
505 for (i
= 0; i
< card
->num_rtd
; i
++) {
506 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
507 struct snd_soc_dai_driver
*drv
= dai
->driver
;
509 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
512 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
513 drv
->ops
->digital_mute(dai
, 1);
516 /* suspend all pcms */
517 for (i
= 0; i
< card
->num_rtd
; i
++) {
518 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
521 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
524 if (card
->suspend_pre
)
525 card
->suspend_pre(card
);
527 for (i
= 0; i
< card
->num_rtd
; i
++) {
528 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
529 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
531 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
534 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
535 cpu_dai
->driver
->suspend(cpu_dai
);
536 if (platform
->driver
->suspend
&& !platform
->suspended
) {
537 platform
->driver
->suspend(cpu_dai
);
538 platform
->suspended
= 1;
542 /* close any waiting streams and save state */
543 for (i
= 0; i
< card
->num_rtd
; i
++) {
544 flush_delayed_work_sync(&card
->rtd
[i
].delayed_work
);
545 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
548 for (i
= 0; i
< card
->num_rtd
; i
++) {
549 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
551 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
554 if (driver
->playback
.stream_name
!= NULL
)
555 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
556 SND_SOC_DAPM_STREAM_SUSPEND
);
558 if (driver
->capture
.stream_name
!= NULL
)
559 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
560 SND_SOC_DAPM_STREAM_SUSPEND
);
563 /* suspend all CODECs */
564 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
565 /* If there are paths active then the CODEC will be held with
566 * bias _ON and should not be suspended. */
567 if (!codec
->suspended
&& codec
->driver
->suspend
) {
568 switch (codec
->dapm
.bias_level
) {
569 case SND_SOC_BIAS_STANDBY
:
570 case SND_SOC_BIAS_OFF
:
571 codec
->driver
->suspend(codec
);
572 codec
->suspended
= 1;
573 codec
->cache_sync
= 1;
576 dev_dbg(codec
->dev
, "CODEC is on over suspend\n");
582 for (i
= 0; i
< card
->num_rtd
; i
++) {
583 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
585 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
588 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
589 cpu_dai
->driver
->suspend(cpu_dai
);
592 if (card
->suspend_post
)
593 card
->suspend_post(card
);
597 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
599 /* deferred resume work, so resume can complete before we finished
600 * setting our codec back up, which can be very slow on I2C
602 static void soc_resume_deferred(struct work_struct
*work
)
604 struct snd_soc_card
*card
=
605 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
606 struct snd_soc_codec
*codec
;
609 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
610 * so userspace apps are blocked from touching us
613 dev_dbg(card
->dev
, "starting resume work\n");
615 /* Bring us up into D2 so that DAPM starts enabling things */
616 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
618 if (card
->resume_pre
)
619 card
->resume_pre(card
);
621 /* resume AC97 DAIs */
622 for (i
= 0; i
< card
->num_rtd
; i
++) {
623 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
625 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
628 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
629 cpu_dai
->driver
->resume(cpu_dai
);
632 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
633 /* If the CODEC was idle over suspend then it will have been
634 * left with bias OFF or STANDBY and suspended so we must now
635 * resume. Otherwise the suspend was suppressed.
637 if (codec
->driver
->resume
&& codec
->suspended
) {
638 switch (codec
->dapm
.bias_level
) {
639 case SND_SOC_BIAS_STANDBY
:
640 case SND_SOC_BIAS_OFF
:
641 codec
->driver
->resume(codec
);
642 codec
->suspended
= 0;
645 dev_dbg(codec
->dev
, "CODEC was on over suspend\n");
651 for (i
= 0; i
< card
->num_rtd
; i
++) {
652 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
654 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
657 if (driver
->playback
.stream_name
!= NULL
)
658 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
659 SND_SOC_DAPM_STREAM_RESUME
);
661 if (driver
->capture
.stream_name
!= NULL
)
662 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
663 SND_SOC_DAPM_STREAM_RESUME
);
666 /* unmute any active DACs */
667 for (i
= 0; i
< card
->num_rtd
; i
++) {
668 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
669 struct snd_soc_dai_driver
*drv
= dai
->driver
;
671 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
674 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
675 drv
->ops
->digital_mute(dai
, 0);
678 for (i
= 0; i
< card
->num_rtd
; i
++) {
679 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
680 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
682 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
685 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
686 cpu_dai
->driver
->resume(cpu_dai
);
687 if (platform
->driver
->resume
&& platform
->suspended
) {
688 platform
->driver
->resume(cpu_dai
);
689 platform
->suspended
= 0;
693 if (card
->resume_post
)
694 card
->resume_post(card
);
696 dev_dbg(card
->dev
, "resume work completed\n");
698 /* userspace can access us now we are back as we were before */
699 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
702 /* powers up audio subsystem after a suspend */
703 int snd_soc_resume(struct device
*dev
)
705 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
706 int i
, ac97_control
= 0;
708 /* If the initialization of this soc device failed, there is no codec
709 * associated with it. Just bail out in this case.
711 if (list_empty(&card
->codec_dev_list
))
714 /* AC97 devices might have other drivers hanging off them so
715 * need to resume immediately. Other drivers don't have that
716 * problem and may take a substantial amount of time to resume
717 * due to I/O costs and anti-pop so handle them out of line.
719 for (i
= 0; i
< card
->num_rtd
; i
++) {
720 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
721 ac97_control
|= cpu_dai
->driver
->ac97_control
;
724 dev_dbg(dev
, "Resuming AC97 immediately\n");
725 soc_resume_deferred(&card
->deferred_resume_work
);
727 dev_dbg(dev
, "Scheduling resume work\n");
728 if (!schedule_work(&card
->deferred_resume_work
))
729 dev_err(dev
, "resume work item may be lost\n");
734 EXPORT_SYMBOL_GPL(snd_soc_resume
);
736 #define snd_soc_suspend NULL
737 #define snd_soc_resume NULL
740 static const struct snd_soc_dai_ops null_dai_ops
= {
743 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
745 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
746 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
747 struct snd_soc_codec
*codec
;
748 struct snd_soc_platform
*platform
;
749 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
750 const char *platform_name
;
754 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
756 /* do we already have the CPU DAI for this link ? */
760 /* no, then find CPU DAI from registered DAIs*/
761 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
762 if (dai_link
->cpu_dai_of_node
) {
763 if (cpu_dai
->dev
->of_node
!= dai_link
->cpu_dai_of_node
)
766 if (strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
))
770 rtd
->cpu_dai
= cpu_dai
;
773 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
774 dai_link
->cpu_dai_name
);
777 /* do we already have the CODEC for this link ? */
782 /* no, then find CODEC from registered CODECs*/
783 list_for_each_entry(codec
, &codec_list
, list
) {
784 if (dai_link
->codec_of_node
) {
785 if (codec
->dev
->of_node
!= dai_link
->codec_of_node
)
788 if (strcmp(codec
->name
, dai_link
->codec_name
))
795 * CODEC found, so find CODEC DAI from registered DAIs from
798 list_for_each_entry(codec_dai
, &dai_list
, list
) {
799 if (codec
->dev
== codec_dai
->dev
&&
800 !strcmp(codec_dai
->name
,
801 dai_link
->codec_dai_name
)) {
803 rtd
->codec_dai
= codec_dai
;
807 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
808 dai_link
->codec_dai_name
);
812 dev_dbg(card
->dev
, "CODEC %s not registered\n",
813 dai_link
->codec_name
);
816 /* do we need a platform? */
820 /* if there's no platform we match on the empty platform */
821 platform_name
= dai_link
->platform_name
;
822 if (!platform_name
&& !dai_link
->platform_of_node
)
823 platform_name
= "snd-soc-dummy";
825 /* no, then find one from the set of registered platforms */
826 list_for_each_entry(platform
, &platform_list
, list
) {
827 if (dai_link
->platform_of_node
) {
828 if (platform
->dev
->of_node
!=
829 dai_link
->platform_of_node
)
832 if (strcmp(platform
->name
, platform_name
))
836 rtd
->platform
= platform
;
840 dev_dbg(card
->dev
, "platform %s not registered\n",
841 dai_link
->platform_name
);
845 /* mark rtd as complete if we found all 4 of our client devices */
846 if (rtd
->codec
&& rtd
->codec_dai
&& rtd
->platform
&& rtd
->cpu_dai
) {
853 static void soc_remove_codec(struct snd_soc_codec
*codec
)
857 if (codec
->driver
->remove
) {
858 err
= codec
->driver
->remove(codec
);
861 "asoc: failed to remove %s: %d\n",
865 /* Make sure all DAPM widgets are freed */
866 snd_soc_dapm_free(&codec
->dapm
);
868 soc_cleanup_codec_debugfs(codec
);
870 list_del(&codec
->card_list
);
871 module_put(codec
->dev
->driver
->owner
);
874 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
876 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
877 struct snd_soc_codec
*codec
= rtd
->codec
;
878 struct snd_soc_platform
*platform
= rtd
->platform
;
879 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
882 /* unregister the rtd device */
883 if (rtd
->dev_registered
) {
884 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
885 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
886 device_unregister(rtd
->dev
);
887 rtd
->dev_registered
= 0;
890 /* remove the CODEC DAI */
891 if (codec_dai
&& codec_dai
->probed
&&
892 codec_dai
->driver
->remove_order
== order
) {
893 if (codec_dai
->driver
->remove
) {
894 err
= codec_dai
->driver
->remove(codec_dai
);
896 printk(KERN_ERR
"asoc: failed to remove %s\n", codec_dai
->name
);
898 codec_dai
->probed
= 0;
899 list_del(&codec_dai
->card_list
);
902 /* remove the platform */
903 if (platform
&& platform
->probed
&&
904 platform
->driver
->remove_order
== order
) {
905 if (platform
->driver
->remove
) {
906 err
= platform
->driver
->remove(platform
);
908 printk(KERN_ERR
"asoc: failed to remove %s\n", platform
->name
);
911 /* Make sure all DAPM widgets are freed */
912 snd_soc_dapm_free(&platform
->dapm
);
914 platform
->probed
= 0;
915 list_del(&platform
->card_list
);
916 module_put(platform
->dev
->driver
->owner
);
919 /* remove the CODEC */
920 if (codec
&& codec
->probed
&&
921 codec
->driver
->remove_order
== order
)
922 soc_remove_codec(codec
);
924 /* remove the cpu_dai */
925 if (cpu_dai
&& cpu_dai
->probed
&&
926 cpu_dai
->driver
->remove_order
== order
) {
927 if (cpu_dai
->driver
->remove
) {
928 err
= cpu_dai
->driver
->remove(cpu_dai
);
930 printk(KERN_ERR
"asoc: failed to remove %s\n", cpu_dai
->name
);
933 list_del(&cpu_dai
->card_list
);
934 module_put(cpu_dai
->dev
->driver
->owner
);
938 static void soc_remove_dai_links(struct snd_soc_card
*card
)
942 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
944 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
945 soc_remove_dai_link(card
, dai
, order
);
950 static void soc_set_name_prefix(struct snd_soc_card
*card
,
951 struct snd_soc_codec
*codec
)
955 if (card
->codec_conf
== NULL
)
958 for (i
= 0; i
< card
->num_configs
; i
++) {
959 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
960 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
961 codec
->name_prefix
= map
->name_prefix
;
967 static int soc_probe_codec(struct snd_soc_card
*card
,
968 struct snd_soc_codec
*codec
)
971 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
974 codec
->dapm
.card
= card
;
975 soc_set_name_prefix(card
, codec
);
977 if (!try_module_get(codec
->dev
->driver
->owner
))
980 soc_init_codec_debugfs(codec
);
982 if (driver
->dapm_widgets
)
983 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
984 driver
->num_dapm_widgets
);
986 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
989 ret
= driver
->probe(codec
);
992 "asoc: failed to probe CODEC %s: %d\n",
998 if (driver
->controls
)
999 snd_soc_add_codec_controls(codec
, driver
->controls
,
1000 driver
->num_controls
);
1001 if (driver
->dapm_routes
)
1002 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1003 driver
->num_dapm_routes
);
1005 /* mark codec as probed and add to card codec list */
1007 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1008 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1013 soc_cleanup_codec_debugfs(codec
);
1014 module_put(codec
->dev
->driver
->owner
);
1019 static int soc_probe_platform(struct snd_soc_card
*card
,
1020 struct snd_soc_platform
*platform
)
1023 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1025 platform
->card
= card
;
1026 platform
->dapm
.card
= card
;
1028 if (!try_module_get(platform
->dev
->driver
->owner
))
1031 if (driver
->dapm_widgets
)
1032 snd_soc_dapm_new_controls(&platform
->dapm
,
1033 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1035 if (driver
->probe
) {
1036 ret
= driver
->probe(platform
);
1038 dev_err(platform
->dev
,
1039 "asoc: failed to probe platform %s: %d\n",
1040 platform
->name
, ret
);
1045 if (driver
->controls
)
1046 snd_soc_add_platform_controls(platform
, driver
->controls
,
1047 driver
->num_controls
);
1048 if (driver
->dapm_routes
)
1049 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1050 driver
->num_dapm_routes
);
1052 /* mark platform as probed and add to card platform list */
1053 platform
->probed
= 1;
1054 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1055 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1060 module_put(platform
->dev
->driver
->owner
);
1065 static void rtd_release(struct device
*dev
)
1070 static int soc_post_component_init(struct snd_soc_card
*card
,
1071 struct snd_soc_codec
*codec
,
1072 int num
, int dailess
)
1074 struct snd_soc_dai_link
*dai_link
= NULL
;
1075 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1076 struct snd_soc_pcm_runtime
*rtd
;
1077 const char *temp
, *name
;
1081 dai_link
= &card
->dai_link
[num
];
1082 rtd
= &card
->rtd
[num
];
1083 name
= dai_link
->name
;
1085 aux_dev
= &card
->aux_dev
[num
];
1086 rtd
= &card
->rtd_aux
[num
];
1087 name
= aux_dev
->name
;
1091 /* Make sure all DAPM widgets are instantiated */
1092 snd_soc_dapm_new_widgets(&codec
->dapm
);
1094 /* machine controls, routes and widgets are not prefixed */
1095 temp
= codec
->name_prefix
;
1096 codec
->name_prefix
= NULL
;
1098 /* do machine specific initialization */
1099 if (!dailess
&& dai_link
->init
)
1100 ret
= dai_link
->init(rtd
);
1101 else if (dailess
&& aux_dev
->init
)
1102 ret
= aux_dev
->init(&codec
->dapm
);
1104 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1107 codec
->name_prefix
= temp
;
1109 /* register the rtd device */
1112 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1115 device_initialize(rtd
->dev
);
1116 rtd
->dev
->parent
= card
->dev
;
1117 rtd
->dev
->release
= rtd_release
;
1118 rtd
->dev
->init_name
= name
;
1119 dev_set_drvdata(rtd
->dev
, rtd
);
1120 mutex_init(&rtd
->pcm_mutex
);
1121 ret
= device_add(rtd
->dev
);
1124 "asoc: failed to register runtime device: %d\n", ret
);
1127 rtd
->dev_registered
= 1;
1129 /* add DAPM sysfs entries for this codec */
1130 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1133 "asoc: failed to add codec dapm sysfs entries: %d\n",
1136 /* add codec sysfs entries */
1137 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1140 "asoc: failed to add codec sysfs files: %d\n", ret
);
1145 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1147 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1148 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1149 struct snd_soc_codec
*codec
= rtd
->codec
;
1150 struct snd_soc_platform
*platform
= rtd
->platform
;
1151 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
1154 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1155 card
->name
, num
, order
);
1157 /* config components */
1158 codec_dai
->codec
= codec
;
1159 cpu_dai
->platform
= platform
;
1160 codec_dai
->card
= card
;
1161 cpu_dai
->card
= card
;
1163 /* set default power off timeout */
1164 rtd
->pmdown_time
= pmdown_time
;
1166 /* probe the cpu_dai */
1167 if (!cpu_dai
->probed
&&
1168 cpu_dai
->driver
->probe_order
== order
) {
1169 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1172 if (cpu_dai
->driver
->probe
) {
1173 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1175 printk(KERN_ERR
"asoc: failed to probe CPU DAI %s\n",
1177 module_put(cpu_dai
->dev
->driver
->owner
);
1181 cpu_dai
->probed
= 1;
1182 /* mark cpu_dai as probed and add to card dai list */
1183 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1186 /* probe the CODEC */
1187 if (!codec
->probed
&&
1188 codec
->driver
->probe_order
== order
) {
1189 ret
= soc_probe_codec(card
, codec
);
1194 /* probe the platform */
1195 if (!platform
->probed
&&
1196 platform
->driver
->probe_order
== order
) {
1197 ret
= soc_probe_platform(card
, platform
);
1202 /* probe the CODEC DAI */
1203 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1204 if (codec_dai
->driver
->probe
) {
1205 ret
= codec_dai
->driver
->probe(codec_dai
);
1207 printk(KERN_ERR
"asoc: failed to probe CODEC DAI %s\n",
1213 /* mark codec_dai as probed and add to card dai list */
1214 codec_dai
->probed
= 1;
1215 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1218 /* complete DAI probe during last probe */
1219 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1222 ret
= soc_post_component_init(card
, codec
, num
, 0);
1226 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1228 printk(KERN_WARNING
"asoc: failed to add pmdown_time sysfs\n");
1230 /* create the pcm */
1231 ret
= soc_new_pcm(rtd
, num
);
1233 printk(KERN_ERR
"asoc: can't create pcm %s\n", dai_link
->stream_name
);
1237 /* add platform data for AC97 devices */
1238 if (rtd
->codec_dai
->driver
->ac97_control
)
1239 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1244 #ifdef CONFIG_SND_SOC_AC97_BUS
1245 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1249 /* Only instantiate AC97 if not already done by the adaptor
1250 * for the generic AC97 subsystem.
1252 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1254 * It is possible that the AC97 device is already registered to
1255 * the device subsystem. This happens when the device is created
1256 * via snd_ac97_mixer(). Currently only SoC codec that does so
1257 * is the generic AC97 glue but others migh emerge.
1259 * In those cases we don't try to register the device again.
1261 if (!rtd
->codec
->ac97_created
)
1264 ret
= soc_ac97_dev_register(rtd
->codec
);
1266 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1270 rtd
->codec
->ac97_registered
= 1;
1275 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1277 if (codec
->ac97_registered
) {
1278 soc_ac97_dev_unregister(codec
);
1279 codec
->ac97_registered
= 0;
1284 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1286 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1287 struct snd_soc_codec
*codec
;
1290 /* find CODEC from registered CODECs*/
1291 list_for_each_entry(codec
, &codec_list
, list
) {
1292 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1293 if (codec
->probed
) {
1295 "asoc: codec already probed");
1302 /* codec not found */
1303 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1307 ret
= soc_probe_codec(card
, codec
);
1311 ret
= soc_post_component_init(card
, codec
, num
, 1);
1317 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1319 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1320 struct snd_soc_codec
*codec
= rtd
->codec
;
1322 /* unregister the rtd device */
1323 if (rtd
->dev_registered
) {
1324 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1325 device_del(rtd
->dev
);
1326 rtd
->dev_registered
= 0;
1329 if (codec
&& codec
->probed
)
1330 soc_remove_codec(codec
);
1333 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1334 enum snd_soc_compress_type compress_type
)
1338 if (codec
->cache_init
)
1341 /* override the compress_type if necessary */
1342 if (compress_type
&& codec
->compress_type
!= compress_type
)
1343 codec
->compress_type
= compress_type
;
1344 ret
= snd_soc_cache_init(codec
);
1346 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1350 codec
->cache_init
= 1;
1354 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
1356 struct snd_soc_codec
*codec
;
1357 struct snd_soc_codec_conf
*codec_conf
;
1358 enum snd_soc_compress_type compress_type
;
1359 struct snd_soc_dai_link
*dai_link
;
1362 mutex_lock(&card
->mutex
);
1364 if (card
->instantiated
) {
1365 mutex_unlock(&card
->mutex
);
1370 for (i
= 0; i
< card
->num_links
; i
++)
1371 soc_bind_dai_link(card
, i
);
1373 /* bind completed ? */
1374 if (card
->num_rtd
!= card
->num_links
) {
1375 mutex_unlock(&card
->mutex
);
1379 /* initialize the register cache for each available codec */
1380 list_for_each_entry(codec
, &codec_list
, list
) {
1381 if (codec
->cache_init
)
1383 /* by default we don't override the compress_type */
1385 /* check to see if we need to override the compress_type */
1386 for (i
= 0; i
< card
->num_configs
; ++i
) {
1387 codec_conf
= &card
->codec_conf
[i
];
1388 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1389 compress_type
= codec_conf
->compress_type
;
1390 if (compress_type
&& compress_type
1391 != codec
->compress_type
)
1395 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1397 mutex_unlock(&card
->mutex
);
1402 /* card bind complete so register a sound card */
1403 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1404 card
->owner
, 0, &card
->snd_card
);
1406 printk(KERN_ERR
"asoc: can't create sound card for card %s\n",
1408 mutex_unlock(&card
->mutex
);
1411 card
->snd_card
->dev
= card
->dev
;
1413 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1414 card
->dapm
.dev
= card
->dev
;
1415 card
->dapm
.card
= card
;
1416 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1418 #ifdef CONFIG_DEBUG_FS
1419 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1422 #ifdef CONFIG_PM_SLEEP
1423 /* deferred resume work */
1424 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1427 if (card
->dapm_widgets
)
1428 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1429 card
->num_dapm_widgets
);
1431 /* initialise the sound card only once */
1433 ret
= card
->probe(card
);
1435 goto card_probe_error
;
1438 /* early DAI link probe */
1439 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1441 for (i
= 0; i
< card
->num_links
; i
++) {
1442 ret
= soc_probe_dai_link(card
, i
, order
);
1444 pr_err("asoc: failed to instantiate card %s: %d\n",
1451 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1452 ret
= soc_probe_aux_dev(card
, i
);
1454 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1456 goto probe_aux_dev_err
;
1461 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1463 if (card
->dapm_routes
)
1464 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1465 card
->num_dapm_routes
);
1467 snd_soc_dapm_new_widgets(&card
->dapm
);
1469 for (i
= 0; i
< card
->num_links
; i
++) {
1470 dai_link
= &card
->dai_link
[i
];
1472 if (dai_link
->dai_fmt
) {
1473 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1476 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1477 "Failed to set DAI format: %d\n",
1480 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1483 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1484 "Failed to set DAI format: %d\n",
1489 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1491 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1492 "%s", card
->long_name
? card
->long_name
: card
->name
);
1493 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1494 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1495 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1496 switch (card
->snd_card
->driver
[i
]) {
1502 if (!isalnum(card
->snd_card
->driver
[i
]))
1503 card
->snd_card
->driver
[i
] = '_';
1508 if (card
->late_probe
) {
1509 ret
= card
->late_probe(card
);
1511 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1513 goto probe_aux_dev_err
;
1517 snd_soc_dapm_new_widgets(&card
->dapm
);
1519 if (card
->fully_routed
)
1520 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1521 snd_soc_dapm_auto_nc_codec_pins(codec
);
1523 ret
= snd_card_register(card
->snd_card
);
1525 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n", card
->name
);
1526 goto probe_aux_dev_err
;
1529 #ifdef CONFIG_SND_SOC_AC97_BUS
1530 /* register any AC97 codecs */
1531 for (i
= 0; i
< card
->num_rtd
; i
++) {
1532 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1534 printk(KERN_ERR
"asoc: failed to register AC97 %s\n", card
->name
);
1536 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1537 goto probe_aux_dev_err
;
1542 card
->instantiated
= 1;
1543 snd_soc_dapm_sync(&card
->dapm
);
1544 mutex_unlock(&card
->mutex
);
1548 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1549 soc_remove_aux_dev(card
, i
);
1552 soc_remove_dai_links(card
);
1558 snd_card_free(card
->snd_card
);
1560 mutex_unlock(&card
->mutex
);
1564 * Attempt to initialise any uninitialised cards. Must be called with
1567 static void snd_soc_instantiate_cards(void)
1569 struct snd_soc_card
*card
;
1570 list_for_each_entry(card
, &card_list
, list
)
1571 snd_soc_instantiate_card(card
);
1574 /* probes a new socdev */
1575 static int soc_probe(struct platform_device
*pdev
)
1577 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1581 * no card, so machine driver should be registering card
1582 * we should not be here in that case so ret error
1587 /* Bodge while we unpick instantiation */
1588 card
->dev
= &pdev
->dev
;
1590 ret
= snd_soc_register_card(card
);
1592 dev_err(&pdev
->dev
, "Failed to register card\n");
1599 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1603 /* make sure any delayed work runs */
1604 for (i
= 0; i
< card
->num_rtd
; i
++) {
1605 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1606 flush_delayed_work_sync(&rtd
->delayed_work
);
1609 /* remove auxiliary devices */
1610 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1611 soc_remove_aux_dev(card
, i
);
1613 /* remove and free each DAI */
1614 soc_remove_dai_links(card
);
1616 soc_cleanup_card_debugfs(card
);
1618 /* remove the card */
1622 snd_soc_dapm_free(&card
->dapm
);
1625 snd_card_free(card
->snd_card
);
1630 /* removes a socdev */
1631 static int soc_remove(struct platform_device
*pdev
)
1633 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1635 snd_soc_unregister_card(card
);
1639 int snd_soc_poweroff(struct device
*dev
)
1641 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1644 if (!card
->instantiated
)
1647 /* Flush out pmdown_time work - we actually do want to run it
1648 * now, we're shutting down so no imminent restart. */
1649 for (i
= 0; i
< card
->num_rtd
; i
++) {
1650 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1651 flush_delayed_work_sync(&rtd
->delayed_work
);
1654 snd_soc_dapm_shutdown(card
);
1658 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1660 const struct dev_pm_ops snd_soc_pm_ops
= {
1661 SET_SYSTEM_SLEEP_PM_OPS(snd_soc_suspend
, snd_soc_resume
)
1662 .poweroff
= snd_soc_poweroff
,
1664 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1666 /* ASoC platform driver */
1667 static struct platform_driver soc_driver
= {
1669 .name
= "soc-audio",
1670 .owner
= THIS_MODULE
,
1671 .pm
= &snd_soc_pm_ops
,
1674 .remove
= soc_remove
,
1678 * snd_soc_codec_volatile_register: Report if a register is volatile.
1680 * @codec: CODEC to query.
1681 * @reg: Register to query.
1683 * Boolean function indiciating if a CODEC register is volatile.
1685 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1688 if (codec
->volatile_register
)
1689 return codec
->volatile_register(codec
, reg
);
1693 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1696 * snd_soc_codec_readable_register: Report if a register is readable.
1698 * @codec: CODEC to query.
1699 * @reg: Register to query.
1701 * Boolean function indicating if a CODEC register is readable.
1703 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1706 if (codec
->readable_register
)
1707 return codec
->readable_register(codec
, reg
);
1711 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1714 * snd_soc_codec_writable_register: Report if a register is writable.
1716 * @codec: CODEC to query.
1717 * @reg: Register to query.
1719 * Boolean function indicating if a CODEC register is writable.
1721 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1724 if (codec
->writable_register
)
1725 return codec
->writable_register(codec
, reg
);
1729 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1731 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1736 if (!platform
->driver
->read
) {
1737 dev_err(platform
->dev
, "platform has no read back\n");
1741 ret
= platform
->driver
->read(platform
, reg
);
1742 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1743 trace_snd_soc_preg_read(platform
, reg
, ret
);
1747 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1749 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1750 unsigned int reg
, unsigned int val
)
1752 if (!platform
->driver
->write
) {
1753 dev_err(platform
->dev
, "platform has no write back\n");
1757 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1758 trace_snd_soc_preg_write(platform
, reg
, val
);
1759 return platform
->driver
->write(platform
, reg
, val
);
1761 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1764 * snd_soc_new_ac97_codec - initailise AC97 device
1765 * @codec: audio codec
1766 * @ops: AC97 bus operations
1767 * @num: AC97 codec number
1769 * Initialises AC97 codec resources for use by ad-hoc devices only.
1771 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1772 struct snd_ac97_bus_ops
*ops
, int num
)
1774 mutex_lock(&codec
->mutex
);
1776 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1777 if (codec
->ac97
== NULL
) {
1778 mutex_unlock(&codec
->mutex
);
1782 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1783 if (codec
->ac97
->bus
== NULL
) {
1786 mutex_unlock(&codec
->mutex
);
1790 codec
->ac97
->bus
->ops
= ops
;
1791 codec
->ac97
->num
= num
;
1794 * Mark the AC97 device to be created by us. This way we ensure that the
1795 * device will be registered with the device subsystem later on.
1797 codec
->ac97_created
= 1;
1799 mutex_unlock(&codec
->mutex
);
1802 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1805 * snd_soc_free_ac97_codec - free AC97 codec device
1806 * @codec: audio codec
1808 * Frees AC97 codec device resources.
1810 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1812 mutex_lock(&codec
->mutex
);
1813 #ifdef CONFIG_SND_SOC_AC97_BUS
1814 soc_unregister_ac97_dai_link(codec
);
1816 kfree(codec
->ac97
->bus
);
1819 codec
->ac97_created
= 0;
1820 mutex_unlock(&codec
->mutex
);
1822 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1824 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1828 ret
= codec
->read(codec
, reg
);
1829 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1830 trace_snd_soc_reg_read(codec
, reg
, ret
);
1834 EXPORT_SYMBOL_GPL(snd_soc_read
);
1836 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
1837 unsigned int reg
, unsigned int val
)
1839 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
1840 trace_snd_soc_reg_write(codec
, reg
, val
);
1841 return codec
->write(codec
, reg
, val
);
1843 EXPORT_SYMBOL_GPL(snd_soc_write
);
1845 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
1846 unsigned int reg
, const void *data
, size_t len
)
1848 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
1850 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
1853 * snd_soc_update_bits - update codec register bits
1854 * @codec: audio codec
1855 * @reg: codec register
1856 * @mask: register mask
1859 * Writes new register value.
1861 * Returns 1 for change, 0 for no change, or negative error code.
1863 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1864 unsigned int mask
, unsigned int value
)
1867 unsigned int old
, new;
1870 if (codec
->using_regmap
) {
1871 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
1872 mask
, value
, &change
);
1874 ret
= snd_soc_read(codec
, reg
);
1879 new = (old
& ~mask
) | (value
& mask
);
1880 change
= old
!= new;
1882 ret
= snd_soc_write(codec
, reg
, new);
1890 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1893 * snd_soc_update_bits_locked - update codec register bits
1894 * @codec: audio codec
1895 * @reg: codec register
1896 * @mask: register mask
1899 * Writes new register value, and takes the codec mutex.
1901 * Returns 1 for change else 0.
1903 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
1904 unsigned short reg
, unsigned int mask
,
1909 mutex_lock(&codec
->mutex
);
1910 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
1911 mutex_unlock(&codec
->mutex
);
1915 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
1918 * snd_soc_test_bits - test register for change
1919 * @codec: audio codec
1920 * @reg: codec register
1921 * @mask: register mask
1924 * Tests a register with a new value and checks if the new value is
1925 * different from the old value.
1927 * Returns 1 for change else 0.
1929 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1930 unsigned int mask
, unsigned int value
)
1933 unsigned int old
, new;
1935 old
= snd_soc_read(codec
, reg
);
1936 new = (old
& ~mask
) | value
;
1937 change
= old
!= new;
1941 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1944 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1945 * @substream: the pcm substream
1946 * @hw: the hardware parameters
1948 * Sets the substream runtime hardware parameters.
1950 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1951 const struct snd_pcm_hardware
*hw
)
1953 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1954 runtime
->hw
.info
= hw
->info
;
1955 runtime
->hw
.formats
= hw
->formats
;
1956 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1957 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1958 runtime
->hw
.periods_min
= hw
->periods_min
;
1959 runtime
->hw
.periods_max
= hw
->periods_max
;
1960 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1961 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1964 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1967 * snd_soc_cnew - create new control
1968 * @_template: control template
1969 * @data: control private data
1970 * @long_name: control long name
1971 * @prefix: control name prefix
1973 * Create a new mixer control from a template control.
1975 * Returns 0 for success, else error.
1977 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1978 void *data
, char *long_name
,
1981 struct snd_kcontrol_new
template;
1982 struct snd_kcontrol
*kcontrol
;
1986 memcpy(&template, _template
, sizeof(template));
1990 long_name
= template.name
;
1993 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
1994 name
= kmalloc(name_len
, GFP_KERNEL
);
1998 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
2000 template.name
= name
;
2002 template.name
= long_name
;
2005 kcontrol
= snd_ctl_new1(&template, data
);
2011 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2013 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2014 const struct snd_kcontrol_new
*controls
, int num_controls
,
2015 const char *prefix
, void *data
)
2019 for (i
= 0; i
< num_controls
; i
++) {
2020 const struct snd_kcontrol_new
*control
= &controls
[i
];
2021 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2022 control
->name
, prefix
));
2024 dev_err(dev
, "Failed to add %s: %d\n", control
->name
, err
);
2033 * snd_soc_add_codec_controls - add an array of controls to a codec.
2034 * Convenience function to add a list of controls. Many codecs were
2035 * duplicating this code.
2037 * @codec: codec to add controls to
2038 * @controls: array of controls to add
2039 * @num_controls: number of elements in the array
2041 * Return 0 for success, else error.
2043 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2044 const struct snd_kcontrol_new
*controls
, int num_controls
)
2046 struct snd_card
*card
= codec
->card
->snd_card
;
2048 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2049 codec
->name_prefix
, codec
);
2051 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2054 * snd_soc_add_platform_controls - add an array of controls to a platform.
2055 * Convenience function to add a list of controls.
2057 * @platform: platform to add controls to
2058 * @controls: array of controls to add
2059 * @num_controls: number of elements in the array
2061 * Return 0 for success, else error.
2063 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2064 const struct snd_kcontrol_new
*controls
, int num_controls
)
2066 struct snd_card
*card
= platform
->card
->snd_card
;
2068 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2071 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2074 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2075 * Convenience function to add a list of controls.
2077 * @soc_card: SoC card to add controls to
2078 * @controls: array of controls to add
2079 * @num_controls: number of elements in the array
2081 * Return 0 for success, else error.
2083 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2084 const struct snd_kcontrol_new
*controls
, int num_controls
)
2086 struct snd_card
*card
= soc_card
->snd_card
;
2088 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2091 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2094 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2095 * Convienience function to add a list of controls.
2097 * @dai: DAI to add controls to
2098 * @controls: array of controls to add
2099 * @num_controls: number of elements in the array
2101 * Return 0 for success, else error.
2103 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2104 const struct snd_kcontrol_new
*controls
, int num_controls
)
2106 struct snd_card
*card
= dai
->card
->snd_card
;
2108 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2111 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2114 * snd_soc_info_enum_double - enumerated double mixer info callback
2115 * @kcontrol: mixer control
2116 * @uinfo: control element information
2118 * Callback to provide information about a double enumerated
2121 * Returns 0 for success.
2123 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2124 struct snd_ctl_elem_info
*uinfo
)
2126 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2128 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2129 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2130 uinfo
->value
.enumerated
.items
= e
->max
;
2132 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2133 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2134 strcpy(uinfo
->value
.enumerated
.name
,
2135 e
->texts
[uinfo
->value
.enumerated
.item
]);
2138 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2141 * snd_soc_get_enum_double - enumerated double mixer get callback
2142 * @kcontrol: mixer control
2143 * @ucontrol: control element information
2145 * Callback to get the value of a double enumerated mixer.
2147 * Returns 0 for success.
2149 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2150 struct snd_ctl_elem_value
*ucontrol
)
2152 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2153 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2154 unsigned int val
, bitmask
;
2156 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2158 val
= snd_soc_read(codec
, e
->reg
);
2159 ucontrol
->value
.enumerated
.item
[0]
2160 = (val
>> e
->shift_l
) & (bitmask
- 1);
2161 if (e
->shift_l
!= e
->shift_r
)
2162 ucontrol
->value
.enumerated
.item
[1] =
2163 (val
>> e
->shift_r
) & (bitmask
- 1);
2167 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2170 * snd_soc_put_enum_double - enumerated double mixer put callback
2171 * @kcontrol: mixer control
2172 * @ucontrol: control element information
2174 * Callback to set the value of a double enumerated mixer.
2176 * Returns 0 for success.
2178 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2179 struct snd_ctl_elem_value
*ucontrol
)
2181 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2182 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2184 unsigned int mask
, bitmask
;
2186 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2188 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2190 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2191 mask
= (bitmask
- 1) << e
->shift_l
;
2192 if (e
->shift_l
!= e
->shift_r
) {
2193 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2195 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2196 mask
|= (bitmask
- 1) << e
->shift_r
;
2199 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2201 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2204 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2205 * @kcontrol: mixer control
2206 * @ucontrol: control element information
2208 * Callback to get the value of a double semi enumerated mixer.
2210 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2211 * used for handling bitfield coded enumeration for example.
2213 * Returns 0 for success.
2215 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2216 struct snd_ctl_elem_value
*ucontrol
)
2218 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2219 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2220 unsigned int reg_val
, val
, mux
;
2222 reg_val
= snd_soc_read(codec
, e
->reg
);
2223 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2224 for (mux
= 0; mux
< e
->max
; mux
++) {
2225 if (val
== e
->values
[mux
])
2228 ucontrol
->value
.enumerated
.item
[0] = mux
;
2229 if (e
->shift_l
!= e
->shift_r
) {
2230 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2231 for (mux
= 0; mux
< e
->max
; mux
++) {
2232 if (val
== e
->values
[mux
])
2235 ucontrol
->value
.enumerated
.item
[1] = mux
;
2240 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2243 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2244 * @kcontrol: mixer control
2245 * @ucontrol: control element information
2247 * Callback to set the value of a double semi enumerated mixer.
2249 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2250 * used for handling bitfield coded enumeration for example.
2252 * Returns 0 for success.
2254 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2255 struct snd_ctl_elem_value
*ucontrol
)
2257 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2258 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2262 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2264 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2265 mask
= e
->mask
<< e
->shift_l
;
2266 if (e
->shift_l
!= e
->shift_r
) {
2267 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2269 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2270 mask
|= e
->mask
<< e
->shift_r
;
2273 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2275 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2278 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2279 * @kcontrol: mixer control
2280 * @uinfo: control element information
2282 * Callback to provide information about an external enumerated
2285 * Returns 0 for success.
2287 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2288 struct snd_ctl_elem_info
*uinfo
)
2290 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2292 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2294 uinfo
->value
.enumerated
.items
= e
->max
;
2296 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2297 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2298 strcpy(uinfo
->value
.enumerated
.name
,
2299 e
->texts
[uinfo
->value
.enumerated
.item
]);
2302 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2305 * snd_soc_info_volsw_ext - external single mixer info callback
2306 * @kcontrol: mixer control
2307 * @uinfo: control element information
2309 * Callback to provide information about a single external mixer control.
2311 * Returns 0 for success.
2313 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2314 struct snd_ctl_elem_info
*uinfo
)
2316 int max
= kcontrol
->private_value
;
2318 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2319 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2321 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2324 uinfo
->value
.integer
.min
= 0;
2325 uinfo
->value
.integer
.max
= max
;
2328 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2331 * snd_soc_info_volsw - single mixer info callback
2332 * @kcontrol: mixer control
2333 * @uinfo: control element information
2335 * Callback to provide information about a single mixer control, or a double
2336 * mixer control that spans 2 registers.
2338 * Returns 0 for success.
2340 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2341 struct snd_ctl_elem_info
*uinfo
)
2343 struct soc_mixer_control
*mc
=
2344 (struct soc_mixer_control
*)kcontrol
->private_value
;
2347 if (!mc
->platform_max
)
2348 mc
->platform_max
= mc
->max
;
2349 platform_max
= mc
->platform_max
;
2351 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2352 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2354 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2356 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2357 uinfo
->value
.integer
.min
= 0;
2358 uinfo
->value
.integer
.max
= platform_max
;
2361 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2364 * snd_soc_get_volsw - single mixer get callback
2365 * @kcontrol: mixer control
2366 * @ucontrol: control element information
2368 * Callback to get the value of a single mixer control, or a double mixer
2369 * control that spans 2 registers.
2371 * Returns 0 for success.
2373 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2374 struct snd_ctl_elem_value
*ucontrol
)
2376 struct soc_mixer_control
*mc
=
2377 (struct soc_mixer_control
*)kcontrol
->private_value
;
2378 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2379 unsigned int reg
= mc
->reg
;
2380 unsigned int reg2
= mc
->rreg
;
2381 unsigned int shift
= mc
->shift
;
2382 unsigned int rshift
= mc
->rshift
;
2384 unsigned int mask
= (1 << fls(max
)) - 1;
2385 unsigned int invert
= mc
->invert
;
2387 ucontrol
->value
.integer
.value
[0] =
2388 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2390 ucontrol
->value
.integer
.value
[0] =
2391 max
- ucontrol
->value
.integer
.value
[0];
2393 if (snd_soc_volsw_is_stereo(mc
)) {
2395 ucontrol
->value
.integer
.value
[1] =
2396 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2398 ucontrol
->value
.integer
.value
[1] =
2399 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2401 ucontrol
->value
.integer
.value
[1] =
2402 max
- ucontrol
->value
.integer
.value
[1];
2407 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2410 * snd_soc_put_volsw - single mixer put callback
2411 * @kcontrol: mixer control
2412 * @ucontrol: control element information
2414 * Callback to set the value of a single mixer control, or a double mixer
2415 * control that spans 2 registers.
2417 * Returns 0 for success.
2419 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2420 struct snd_ctl_elem_value
*ucontrol
)
2422 struct soc_mixer_control
*mc
=
2423 (struct soc_mixer_control
*)kcontrol
->private_value
;
2424 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2425 unsigned int reg
= mc
->reg
;
2426 unsigned int reg2
= mc
->rreg
;
2427 unsigned int shift
= mc
->shift
;
2428 unsigned int rshift
= mc
->rshift
;
2430 unsigned int mask
= (1 << fls(max
)) - 1;
2431 unsigned int invert
= mc
->invert
;
2434 unsigned int val2
= 0;
2435 unsigned int val
, val_mask
;
2437 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2440 val_mask
= mask
<< shift
;
2442 if (snd_soc_volsw_is_stereo(mc
)) {
2443 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2447 val_mask
|= mask
<< rshift
;
2448 val
|= val2
<< rshift
;
2450 val2
= val2
<< shift
;
2454 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2459 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2463 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2466 * snd_soc_info_volsw_s8 - signed mixer info callback
2467 * @kcontrol: mixer control
2468 * @uinfo: control element information
2470 * Callback to provide information about a signed mixer control.
2472 * Returns 0 for success.
2474 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2475 struct snd_ctl_elem_info
*uinfo
)
2477 struct soc_mixer_control
*mc
=
2478 (struct soc_mixer_control
*)kcontrol
->private_value
;
2482 if (!mc
->platform_max
)
2483 mc
->platform_max
= mc
->max
;
2484 platform_max
= mc
->platform_max
;
2486 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2488 uinfo
->value
.integer
.min
= 0;
2489 uinfo
->value
.integer
.max
= platform_max
- min
;
2492 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2495 * snd_soc_get_volsw_s8 - signed mixer get callback
2496 * @kcontrol: mixer control
2497 * @ucontrol: control element information
2499 * Callback to get the value of a signed mixer control.
2501 * Returns 0 for success.
2503 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2504 struct snd_ctl_elem_value
*ucontrol
)
2506 struct soc_mixer_control
*mc
=
2507 (struct soc_mixer_control
*)kcontrol
->private_value
;
2508 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2509 unsigned int reg
= mc
->reg
;
2511 int val
= snd_soc_read(codec
, reg
);
2513 ucontrol
->value
.integer
.value
[0] =
2514 ((signed char)(val
& 0xff))-min
;
2515 ucontrol
->value
.integer
.value
[1] =
2516 ((signed char)((val
>> 8) & 0xff))-min
;
2519 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2522 * snd_soc_put_volsw_sgn - signed mixer put callback
2523 * @kcontrol: mixer control
2524 * @ucontrol: control element information
2526 * Callback to set the value of a signed mixer control.
2528 * Returns 0 for success.
2530 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2531 struct snd_ctl_elem_value
*ucontrol
)
2533 struct soc_mixer_control
*mc
=
2534 (struct soc_mixer_control
*)kcontrol
->private_value
;
2535 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2536 unsigned int reg
= mc
->reg
;
2540 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2541 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2543 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2545 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2548 * snd_soc_limit_volume - Set new limit to an existing volume control.
2550 * @codec: where to look for the control
2551 * @name: Name of the control
2552 * @max: new maximum limit
2554 * Return 0 for success, else error.
2556 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2557 const char *name
, int max
)
2559 struct snd_card
*card
= codec
->card
->snd_card
;
2560 struct snd_kcontrol
*kctl
;
2561 struct soc_mixer_control
*mc
;
2565 /* Sanity check for name and max */
2566 if (unlikely(!name
|| max
<= 0))
2569 list_for_each_entry(kctl
, &card
->controls
, list
) {
2570 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2576 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2577 if (max
<= mc
->max
) {
2578 mc
->platform_max
= max
;
2584 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2587 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2588 * mixer info callback
2589 * @kcontrol: mixer control
2590 * @uinfo: control element information
2592 * Returns 0 for success.
2594 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2595 struct snd_ctl_elem_info
*uinfo
)
2597 struct soc_mixer_control
*mc
=
2598 (struct soc_mixer_control
*)kcontrol
->private_value
;
2602 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2604 uinfo
->value
.integer
.min
= 0;
2605 uinfo
->value
.integer
.max
= max
-min
;
2609 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx
);
2612 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2613 * mixer get callback
2614 * @kcontrol: mixer control
2615 * @uinfo: control element information
2617 * Returns 0 for success.
2619 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2620 struct snd_ctl_elem_value
*ucontrol
)
2622 struct soc_mixer_control
*mc
=
2623 (struct soc_mixer_control
*)kcontrol
->private_value
;
2624 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2625 unsigned int mask
= (1<<mc
->shift
)-1;
2627 int val
= snd_soc_read(codec
, mc
->reg
) & mask
;
2628 int valr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2630 ucontrol
->value
.integer
.value
[0] = ((val
& 0xff)-min
) & mask
;
2631 ucontrol
->value
.integer
.value
[1] = ((valr
& 0xff)-min
) & mask
;
2634 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx
);
2637 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2638 * mixer put callback
2639 * @kcontrol: mixer control
2640 * @uinfo: control element information
2642 * Returns 0 for success.
2644 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2645 struct snd_ctl_elem_value
*ucontrol
)
2647 struct soc_mixer_control
*mc
=
2648 (struct soc_mixer_control
*)kcontrol
->private_value
;
2649 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2650 unsigned int mask
= (1<<mc
->shift
)-1;
2653 unsigned int val
, valr
, oval
, ovalr
;
2655 val
= ((ucontrol
->value
.integer
.value
[0]+min
) & 0xff);
2657 valr
= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff);
2660 oval
= snd_soc_read(codec
, mc
->reg
) & mask
;
2661 ovalr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2665 ret
= snd_soc_write(codec
, mc
->reg
, val
);
2669 if (ovalr
!= valr
) {
2670 ret
= snd_soc_write(codec
, mc
->rreg
, valr
);
2677 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx
);
2680 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2682 * @clk_id: DAI specific clock ID
2683 * @freq: new clock frequency in Hz
2684 * @dir: new clock direction - input/output.
2686 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2688 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2689 unsigned int freq
, int dir
)
2691 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
2692 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
2693 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
2694 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
2699 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2702 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2704 * @clk_id: DAI specific clock ID
2705 * @source: Source for the clock
2706 * @freq: new clock frequency in Hz
2707 * @dir: new clock direction - input/output.
2709 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2711 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
2712 int source
, unsigned int freq
, int dir
)
2714 if (codec
->driver
->set_sysclk
)
2715 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
2720 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
2723 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2725 * @div_id: DAI specific clock divider ID
2726 * @div: new clock divisor.
2728 * Configures the clock dividers. This is used to derive the best DAI bit and
2729 * frame clocks from the system or master clock. It's best to set the DAI bit
2730 * and frame clocks as low as possible to save system power.
2732 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2733 int div_id
, int div
)
2735 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
2736 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
2740 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2743 * snd_soc_dai_set_pll - configure DAI PLL.
2745 * @pll_id: DAI specific PLL ID
2746 * @source: DAI specific source for the PLL
2747 * @freq_in: PLL input clock frequency in Hz
2748 * @freq_out: requested PLL output clock frequency in Hz
2750 * Configures and enables PLL to generate output clock based on input clock.
2752 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2753 unsigned int freq_in
, unsigned int freq_out
)
2755 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
2756 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
2758 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
2759 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
2764 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2767 * snd_soc_codec_set_pll - configure codec PLL.
2769 * @pll_id: DAI specific PLL ID
2770 * @source: DAI specific source for the PLL
2771 * @freq_in: PLL input clock frequency in Hz
2772 * @freq_out: requested PLL output clock frequency in Hz
2774 * Configures and enables PLL to generate output clock based on input clock.
2776 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
2777 unsigned int freq_in
, unsigned int freq_out
)
2779 if (codec
->driver
->set_pll
)
2780 return codec
->driver
->set_pll(codec
, pll_id
, source
,
2785 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
2788 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2790 * @fmt: SND_SOC_DAIFMT_ format value.
2792 * Configures the DAI hardware format and clocking.
2794 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2796 if (dai
->driver
&& dai
->driver
->ops
->set_fmt
)
2797 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
2801 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2804 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2806 * @tx_mask: bitmask representing active TX slots.
2807 * @rx_mask: bitmask representing active RX slots.
2808 * @slots: Number of slots in use.
2809 * @slot_width: Width in bits for each slot.
2811 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2814 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2815 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
2817 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
2818 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
2823 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
2826 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2828 * @tx_num: how many TX channels
2829 * @tx_slot: pointer to an array which imply the TX slot number channel
2831 * @rx_num: how many RX channels
2832 * @rx_slot: pointer to an array which imply the RX slot number channel
2835 * configure the relationship between channel number and TDM slot number.
2837 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
2838 unsigned int tx_num
, unsigned int *tx_slot
,
2839 unsigned int rx_num
, unsigned int *rx_slot
)
2841 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
2842 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
2847 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
2850 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2852 * @tristate: tristate enable
2854 * Tristates the DAI so that others can use it.
2856 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2858 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
2859 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
2863 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
2866 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2868 * @mute: mute enable
2870 * Mutes the DAI DAC.
2872 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
2874 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
2875 return dai
->driver
->ops
->digital_mute(dai
, mute
);
2879 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
2882 * snd_soc_register_card - Register a card with the ASoC core
2884 * @card: Card to register
2887 int snd_soc_register_card(struct snd_soc_card
*card
)
2891 if (!card
->name
|| !card
->dev
)
2894 for (i
= 0; i
< card
->num_links
; i
++) {
2895 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
2898 * Codec must be specified by 1 of name or OF node,
2899 * not both or neither.
2901 if (!!link
->codec_name
== !!link
->codec_of_node
) {
2903 "Neither/both codec name/of_node are set for %s\n",
2909 * Platform may be specified by either name or OF node, but
2910 * can be left unspecified, and a dummy platform will be used.
2912 if (link
->platform_name
&& link
->platform_of_node
) {
2914 "Both platform name/of_node are set for %s\n", link
->name
);
2919 * CPU DAI must be specified by 1 of name or OF node,
2920 * not both or neither.
2922 if (!!link
->cpu_dai_name
== !!link
->cpu_dai_of_node
) {
2924 "Neither/both cpu_dai name/of_node are set for %s\n",
2930 dev_set_drvdata(card
->dev
, card
);
2932 snd_soc_initialize_card_lists(card
);
2934 soc_init_card_debugfs(card
);
2936 card
->rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
) *
2937 (card
->num_links
+ card
->num_aux_devs
),
2939 if (card
->rtd
== NULL
)
2941 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
2943 for (i
= 0; i
< card
->num_links
; i
++)
2944 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
2946 INIT_LIST_HEAD(&card
->list
);
2947 INIT_LIST_HEAD(&card
->dapm_dirty
);
2948 card
->instantiated
= 0;
2949 mutex_init(&card
->mutex
);
2951 mutex_lock(&client_mutex
);
2952 list_add(&card
->list
, &card_list
);
2953 snd_soc_instantiate_cards();
2954 mutex_unlock(&client_mutex
);
2956 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
2960 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
2963 * snd_soc_unregister_card - Unregister a card with the ASoC core
2965 * @card: Card to unregister
2968 int snd_soc_unregister_card(struct snd_soc_card
*card
)
2970 if (card
->instantiated
)
2971 soc_cleanup_card_resources(card
);
2972 mutex_lock(&client_mutex
);
2973 list_del(&card
->list
);
2974 mutex_unlock(&client_mutex
);
2975 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
2979 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
2982 * Simplify DAI link configuration by removing ".-1" from device names
2983 * and sanitizing names.
2985 static char *fmt_single_name(struct device
*dev
, int *id
)
2987 char *found
, name
[NAME_SIZE
];
2990 if (dev_name(dev
) == NULL
)
2993 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
2995 /* are we a "%s.%d" name (platform and SPI components) */
2996 found
= strstr(name
, dev
->driver
->name
);
2999 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3001 /* discard ID from name if ID == -1 */
3003 found
[strlen(dev
->driver
->name
)] = '\0';
3007 /* I2C component devices are named "bus-addr" */
3008 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3009 char tmp
[NAME_SIZE
];
3011 /* create unique ID number from I2C addr and bus */
3012 *id
= ((id1
& 0xffff) << 16) + id2
;
3014 /* sanitize component name for DAI link creation */
3015 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3016 strlcpy(name
, tmp
, NAME_SIZE
);
3021 return kstrdup(name
, GFP_KERNEL
);
3025 * Simplify DAI link naming for single devices with multiple DAIs by removing
3026 * any ".-1" and using the DAI name (instead of device name).
3028 static inline char *fmt_multiple_name(struct device
*dev
,
3029 struct snd_soc_dai_driver
*dai_drv
)
3031 if (dai_drv
->name
== NULL
) {
3032 printk(KERN_ERR
"asoc: error - multiple DAI %s registered with no name\n",
3037 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3041 * snd_soc_register_dai - Register a DAI with the ASoC core
3043 * @dai: DAI to register
3045 int snd_soc_register_dai(struct device
*dev
,
3046 struct snd_soc_dai_driver
*dai_drv
)
3048 struct snd_soc_dai
*dai
;
3050 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
3052 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3056 /* create DAI component name */
3057 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3058 if (dai
->name
== NULL
) {
3064 dai
->driver
= dai_drv
;
3065 if (!dai
->driver
->ops
)
3066 dai
->driver
->ops
= &null_dai_ops
;
3068 mutex_lock(&client_mutex
);
3069 list_add(&dai
->list
, &dai_list
);
3070 snd_soc_instantiate_cards();
3071 mutex_unlock(&client_mutex
);
3073 pr_debug("Registered DAI '%s'\n", dai
->name
);
3077 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3080 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3082 * @dai: DAI to unregister
3084 void snd_soc_unregister_dai(struct device
*dev
)
3086 struct snd_soc_dai
*dai
;
3088 list_for_each_entry(dai
, &dai_list
, list
) {
3089 if (dev
== dai
->dev
)
3095 mutex_lock(&client_mutex
);
3096 list_del(&dai
->list
);
3097 mutex_unlock(&client_mutex
);
3099 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3103 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3106 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3108 * @dai: Array of DAIs to register
3109 * @count: Number of DAIs
3111 int snd_soc_register_dais(struct device
*dev
,
3112 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3114 struct snd_soc_dai
*dai
;
3117 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3119 for (i
= 0; i
< count
; i
++) {
3121 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3127 /* create DAI component name */
3128 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3129 if (dai
->name
== NULL
) {
3136 dai
->driver
= &dai_drv
[i
];
3137 if (dai
->driver
->id
)
3138 dai
->id
= dai
->driver
->id
;
3141 if (!dai
->driver
->ops
)
3142 dai
->driver
->ops
= &null_dai_ops
;
3144 mutex_lock(&client_mutex
);
3145 list_add(&dai
->list
, &dai_list
);
3146 mutex_unlock(&client_mutex
);
3148 pr_debug("Registered DAI '%s'\n", dai
->name
);
3151 mutex_lock(&client_mutex
);
3152 snd_soc_instantiate_cards();
3153 mutex_unlock(&client_mutex
);
3157 for (i
--; i
>= 0; i
--)
3158 snd_soc_unregister_dai(dev
);
3162 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3165 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3167 * @dai: Array of DAIs to unregister
3168 * @count: Number of DAIs
3170 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3174 for (i
= 0; i
< count
; i
++)
3175 snd_soc_unregister_dai(dev
);
3177 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3180 * snd_soc_register_platform - Register a platform with the ASoC core
3182 * @platform: platform to register
3184 int snd_soc_register_platform(struct device
*dev
,
3185 struct snd_soc_platform_driver
*platform_drv
)
3187 struct snd_soc_platform
*platform
;
3189 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3191 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3192 if (platform
== NULL
)
3195 /* create platform component name */
3196 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3197 if (platform
->name
== NULL
) {
3202 platform
->dev
= dev
;
3203 platform
->driver
= platform_drv
;
3204 platform
->dapm
.dev
= dev
;
3205 platform
->dapm
.platform
= platform
;
3206 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3208 mutex_lock(&client_mutex
);
3209 list_add(&platform
->list
, &platform_list
);
3210 snd_soc_instantiate_cards();
3211 mutex_unlock(&client_mutex
);
3213 pr_debug("Registered platform '%s'\n", platform
->name
);
3217 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3220 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3222 * @platform: platform to unregister
3224 void snd_soc_unregister_platform(struct device
*dev
)
3226 struct snd_soc_platform
*platform
;
3228 list_for_each_entry(platform
, &platform_list
, list
) {
3229 if (dev
== platform
->dev
)
3235 mutex_lock(&client_mutex
);
3236 list_del(&platform
->list
);
3237 mutex_unlock(&client_mutex
);
3239 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3240 kfree(platform
->name
);
3243 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3245 static u64 codec_format_map
[] = {
3246 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3247 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3248 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3249 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3250 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3251 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3252 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3253 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3254 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3255 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3256 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3257 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3258 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3259 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3260 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3261 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3264 /* Fix up the DAI formats for endianness: codecs don't actually see
3265 * the endianness of the data but we're using the CPU format
3266 * definitions which do need to include endianness so we ensure that
3267 * codec DAIs always have both big and little endian variants set.
3269 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3273 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3274 if (stream
->formats
& codec_format_map
[i
])
3275 stream
->formats
|= codec_format_map
[i
];
3279 * snd_soc_register_codec - Register a codec with the ASoC core
3281 * @codec: codec to register
3283 int snd_soc_register_codec(struct device
*dev
,
3284 const struct snd_soc_codec_driver
*codec_drv
,
3285 struct snd_soc_dai_driver
*dai_drv
,
3289 struct snd_soc_codec
*codec
;
3292 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3294 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3298 /* create CODEC component name */
3299 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3300 if (codec
->name
== NULL
) {
3305 if (codec_drv
->compress_type
)
3306 codec
->compress_type
= codec_drv
->compress_type
;
3308 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3310 codec
->write
= codec_drv
->write
;
3311 codec
->read
= codec_drv
->read
;
3312 codec
->volatile_register
= codec_drv
->volatile_register
;
3313 codec
->readable_register
= codec_drv
->readable_register
;
3314 codec
->writable_register
= codec_drv
->writable_register
;
3315 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
3316 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3317 codec
->dapm
.dev
= dev
;
3318 codec
->dapm
.codec
= codec
;
3319 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3320 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3322 codec
->driver
= codec_drv
;
3323 codec
->num_dai
= num_dai
;
3324 mutex_init(&codec
->mutex
);
3326 /* allocate CODEC register cache */
3327 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3328 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3329 codec
->reg_size
= reg_size
;
3330 /* it is necessary to make a copy of the default register cache
3331 * because in the case of using a compression type that requires
3332 * the default register cache to be marked as __devinitconst the
3333 * kernel might have freed the array by the time we initialize
3336 if (codec_drv
->reg_cache_default
) {
3337 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3338 reg_size
, GFP_KERNEL
);
3339 if (!codec
->reg_def_copy
) {
3346 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3347 if (!codec
->volatile_register
)
3348 codec
->volatile_register
= snd_soc_default_volatile_register
;
3349 if (!codec
->readable_register
)
3350 codec
->readable_register
= snd_soc_default_readable_register
;
3351 if (!codec
->writable_register
)
3352 codec
->writable_register
= snd_soc_default_writable_register
;
3355 for (i
= 0; i
< num_dai
; i
++) {
3356 fixup_codec_formats(&dai_drv
[i
].playback
);
3357 fixup_codec_formats(&dai_drv
[i
].capture
);
3360 /* register any DAIs */
3362 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3367 mutex_lock(&client_mutex
);
3368 list_add(&codec
->list
, &codec_list
);
3369 snd_soc_instantiate_cards();
3370 mutex_unlock(&client_mutex
);
3372 pr_debug("Registered codec '%s'\n", codec
->name
);
3376 kfree(codec
->reg_def_copy
);
3377 codec
->reg_def_copy
= NULL
;
3382 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3385 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3387 * @codec: codec to unregister
3389 void snd_soc_unregister_codec(struct device
*dev
)
3391 struct snd_soc_codec
*codec
;
3394 list_for_each_entry(codec
, &codec_list
, list
) {
3395 if (dev
== codec
->dev
)
3402 for (i
= 0; i
< codec
->num_dai
; i
++)
3403 snd_soc_unregister_dai(dev
);
3405 mutex_lock(&client_mutex
);
3406 list_del(&codec
->list
);
3407 mutex_unlock(&client_mutex
);
3409 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3411 snd_soc_cache_exit(codec
);
3412 kfree(codec
->reg_def_copy
);
3416 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3418 /* Retrieve a card's name from device tree */
3419 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
3420 const char *propname
)
3422 struct device_node
*np
= card
->dev
->of_node
;
3425 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
3427 * EINVAL means the property does not exist. This is fine providing
3428 * card->name was previously set, which is checked later in
3429 * snd_soc_register_card.
3431 if (ret
< 0 && ret
!= -EINVAL
) {
3433 "Property '%s' could not be read: %d\n",
3440 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
3442 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
3443 const char *propname
)
3445 struct device_node
*np
= card
->dev
->of_node
;
3447 struct snd_soc_dapm_route
*routes
;
3450 num_routes
= of_property_count_strings(np
, propname
);
3451 if (num_routes
& 1) {
3453 "Property '%s's length is not even\n",
3460 "Property '%s's length is zero\n",
3465 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
3469 "Could not allocate DAPM route table\n");
3473 for (i
= 0; i
< num_routes
; i
++) {
3474 ret
= of_property_read_string_index(np
, propname
,
3475 2 * i
, &routes
[i
].sink
);
3478 "Property '%s' index %d could not be read: %d\n",
3479 propname
, 2 * i
, ret
);
3482 ret
= of_property_read_string_index(np
, propname
,
3483 (2 * i
) + 1, &routes
[i
].source
);
3486 "Property '%s' index %d could not be read: %d\n",
3487 propname
, (2 * i
) + 1, ret
);
3492 card
->num_dapm_routes
= num_routes
;
3493 card
->dapm_routes
= routes
;
3497 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
3499 static int __init
snd_soc_init(void)
3501 #ifdef CONFIG_DEBUG_FS
3502 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3503 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3505 "ASoC: Failed to create debugfs directory\n");
3506 snd_soc_debugfs_root
= NULL
;
3509 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3511 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3513 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3515 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3517 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3518 &platform_list_fops
))
3519 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3522 snd_soc_util_init();
3524 return platform_driver_register(&soc_driver
);
3526 module_init(snd_soc_init
);
3528 static void __exit
snd_soc_exit(void)
3530 snd_soc_util_exit();
3532 #ifdef CONFIG_DEBUG_FS
3533 debugfs_remove_recursive(snd_soc_debugfs_root
);
3535 platform_driver_unregister(&soc_driver
);
3537 module_exit(snd_soc_exit
);
3539 /* Module information */
3540 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3541 MODULE_DESCRIPTION("ALSA SoC Core");
3542 MODULE_LICENSE("GPL");
3543 MODULE_ALIAS("platform:soc-audio");