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>
35 #include <sound/ac97_codec.h>
36 #include <sound/core.h>
37 #include <sound/jack.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/soc.h>
41 #include <sound/initval.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/asoc.h>
48 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
50 #ifdef CONFIG_DEBUG_FS
51 struct dentry
*snd_soc_debugfs_root
;
52 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
55 static DEFINE_MUTEX(client_mutex
);
56 static LIST_HEAD(card_list
);
57 static LIST_HEAD(dai_list
);
58 static LIST_HEAD(platform_list
);
59 static LIST_HEAD(codec_list
);
61 int soc_new_pcm(struct snd_soc_pcm_runtime
*rtd
, int num
);
64 * This is a timeout to do a DAPM powerdown after a stream is closed().
65 * It can be used to eliminate pops between different playback streams, e.g.
66 * between two audio tracks.
68 static int pmdown_time
= 5000;
69 module_param(pmdown_time
, int, 0);
70 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
72 /* returns the minimum number of bytes needed to represent
73 * a particular given value */
74 static int min_bytes_needed(unsigned long val
)
79 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
82 c
= (sizeof val
* 8) - c
;
90 /* fill buf which is 'len' bytes with a formatted
91 * string of the form 'reg: value\n' */
92 static int format_register_str(struct snd_soc_codec
*codec
,
93 unsigned int reg
, char *buf
, size_t len
)
95 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
96 int regsize
= codec
->driver
->reg_word_size
* 2;
99 char regbuf
[regsize
+ 1];
101 /* since tmpbuf is allocated on the stack, warn the callers if they
102 * try to abuse this function */
105 /* +2 for ': ' and + 1 for '\n' */
106 if (wordsize
+ regsize
+ 2 + 1 != len
)
109 ret
= snd_soc_read(codec
, reg
);
111 memset(regbuf
, 'X', regsize
);
112 regbuf
[regsize
] = '\0';
114 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
117 /* prepare the buffer */
118 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
119 /* copy it back to the caller without the '\0' */
120 memcpy(buf
, tmpbuf
, len
);
125 /* codec register dump */
126 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
127 size_t count
, loff_t pos
)
130 int wordsize
, regsize
;
135 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
136 regsize
= codec
->driver
->reg_word_size
* 2;
138 len
= wordsize
+ regsize
+ 2 + 1;
140 if (!codec
->driver
->reg_cache_size
)
143 if (codec
->driver
->reg_cache_step
)
144 step
= codec
->driver
->reg_cache_step
;
146 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
147 if (!snd_soc_codec_readable_register(codec
, i
))
149 if (codec
->driver
->display_register
) {
150 count
+= codec
->driver
->display_register(codec
, buf
+ count
,
151 PAGE_SIZE
- count
, i
);
153 /* only support larger than PAGE_SIZE bytes debugfs
154 * entries for the default case */
156 if (total
+ len
>= count
- 1)
158 format_register_str(codec
, i
, buf
+ total
, len
);
165 total
= min(total
, count
- 1);
170 static ssize_t
codec_reg_show(struct device
*dev
,
171 struct device_attribute
*attr
, char *buf
)
173 struct snd_soc_pcm_runtime
*rtd
=
174 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
176 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
179 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
181 static ssize_t
pmdown_time_show(struct device
*dev
,
182 struct device_attribute
*attr
, char *buf
)
184 struct snd_soc_pcm_runtime
*rtd
=
185 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
187 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
190 static ssize_t
pmdown_time_set(struct device
*dev
,
191 struct device_attribute
*attr
,
192 const char *buf
, size_t count
)
194 struct snd_soc_pcm_runtime
*rtd
=
195 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
198 ret
= strict_strtol(buf
, 10, &rtd
->pmdown_time
);
205 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
207 #ifdef CONFIG_DEBUG_FS
208 static int codec_reg_open_file(struct inode
*inode
, struct file
*file
)
210 file
->private_data
= inode
->i_private
;
214 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
215 size_t count
, loff_t
*ppos
)
218 struct snd_soc_codec
*codec
= file
->private_data
;
221 if (*ppos
< 0 || !count
)
224 buf
= kmalloc(count
, GFP_KERNEL
);
228 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
230 if (copy_to_user(user_buf
, buf
, ret
)) {
241 static ssize_t
codec_reg_write_file(struct file
*file
,
242 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
247 unsigned long reg
, value
;
248 struct snd_soc_codec
*codec
= file
->private_data
;
250 buf_size
= min(count
, (sizeof(buf
)-1));
251 if (copy_from_user(buf
, user_buf
, buf_size
))
255 while (*start
== ' ')
257 reg
= simple_strtoul(start
, &start
, 16);
258 while (*start
== ' ')
260 if (strict_strtoul(start
, 16, &value
))
263 /* Userspace has been fiddling around behind the kernel's back */
264 add_taint(TAINT_USER
);
266 snd_soc_write(codec
, reg
, value
);
270 static const struct file_operations codec_reg_fops
= {
271 .open
= codec_reg_open_file
,
272 .read
= codec_reg_read_file
,
273 .write
= codec_reg_write_file
,
274 .llseek
= default_llseek
,
277 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
279 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
281 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
283 if (!codec
->debugfs_codec_root
) {
285 "ASoC: Failed to create codec debugfs directory\n");
289 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
291 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
294 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
295 codec
->debugfs_codec_root
,
296 codec
, &codec_reg_fops
);
297 if (!codec
->debugfs_reg
)
299 "ASoC: Failed to create codec register debugfs file\n");
301 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
304 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
306 debugfs_remove_recursive(codec
->debugfs_codec_root
);
309 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
310 size_t count
, loff_t
*ppos
)
312 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
313 ssize_t len
, ret
= 0;
314 struct snd_soc_codec
*codec
;
319 list_for_each_entry(codec
, &codec_list
, list
) {
320 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
324 if (ret
> PAGE_SIZE
) {
331 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
338 static const struct file_operations codec_list_fops
= {
339 .read
= codec_list_read_file
,
340 .llseek
= default_llseek
,/* read accesses f_pos */
343 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
344 size_t count
, loff_t
*ppos
)
346 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
347 ssize_t len
, ret
= 0;
348 struct snd_soc_dai
*dai
;
353 list_for_each_entry(dai
, &dai_list
, list
) {
354 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
357 if (ret
> PAGE_SIZE
) {
363 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
370 static const struct file_operations dai_list_fops
= {
371 .read
= dai_list_read_file
,
372 .llseek
= default_llseek
,/* read accesses f_pos */
375 static ssize_t
platform_list_read_file(struct file
*file
,
376 char __user
*user_buf
,
377 size_t count
, loff_t
*ppos
)
379 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
380 ssize_t len
, ret
= 0;
381 struct snd_soc_platform
*platform
;
386 list_for_each_entry(platform
, &platform_list
, list
) {
387 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
391 if (ret
> PAGE_SIZE
) {
397 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
404 static const struct file_operations platform_list_fops
= {
405 .read
= platform_list_read_file
,
406 .llseek
= default_llseek
,/* read accesses f_pos */
409 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
411 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
412 snd_soc_debugfs_root
);
413 if (!card
->debugfs_card_root
) {
415 "ASoC: Failed to create codec debugfs directory\n");
419 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
420 card
->debugfs_card_root
,
422 if (!card
->debugfs_pop_time
)
424 "Failed to create pop time debugfs file\n");
427 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
429 debugfs_remove_recursive(card
->debugfs_card_root
);
434 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
438 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
442 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
446 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
451 #ifdef CONFIG_SND_SOC_AC97_BUS
452 /* unregister ac97 codec */
453 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
455 if (codec
->ac97
->dev
.bus
)
456 device_unregister(&codec
->ac97
->dev
);
460 /* stop no dev release warning */
461 static void soc_ac97_device_release(struct device
*dev
){}
463 /* register ac97 codec to bus */
464 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
468 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
469 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
470 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
472 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
473 codec
->card
->snd_card
->number
, 0, codec
->name
);
474 err
= device_register(&codec
->ac97
->dev
);
476 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
477 codec
->ac97
->dev
.bus
= NULL
;
484 #ifdef CONFIG_PM_SLEEP
485 /* powers down audio subsystem for suspend */
486 int snd_soc_suspend(struct device
*dev
)
488 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
489 struct snd_soc_codec
*codec
;
492 /* If the initialization of this soc device failed, there is no codec
493 * associated with it. Just bail out in this case.
495 if (list_empty(&card
->codec_dev_list
))
498 /* Due to the resume being scheduled into a workqueue we could
499 * suspend before that's finished - wait for it to complete.
501 snd_power_lock(card
->snd_card
);
502 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
503 snd_power_unlock(card
->snd_card
);
505 /* we're going to block userspace touching us until resume completes */
506 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
508 /* mute any active DACs */
509 for (i
= 0; i
< card
->num_rtd
; i
++) {
510 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
511 struct snd_soc_dai_driver
*drv
= dai
->driver
;
513 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
516 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
517 drv
->ops
->digital_mute(dai
, 1);
520 /* suspend all pcms */
521 for (i
= 0; i
< card
->num_rtd
; i
++) {
522 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
525 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
528 if (card
->suspend_pre
)
529 card
->suspend_pre(card
);
531 for (i
= 0; i
< card
->num_rtd
; i
++) {
532 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
533 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
535 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
538 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
539 cpu_dai
->driver
->suspend(cpu_dai
);
540 if (platform
->driver
->suspend
&& !platform
->suspended
) {
541 platform
->driver
->suspend(cpu_dai
);
542 platform
->suspended
= 1;
546 /* close any waiting streams and save state */
547 for (i
= 0; i
< card
->num_rtd
; i
++) {
548 flush_delayed_work_sync(&card
->rtd
[i
].delayed_work
);
549 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
552 for (i
= 0; i
< card
->num_rtd
; i
++) {
553 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
555 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
558 if (driver
->playback
.stream_name
!= NULL
)
559 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
560 SND_SOC_DAPM_STREAM_SUSPEND
);
562 if (driver
->capture
.stream_name
!= NULL
)
563 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
564 SND_SOC_DAPM_STREAM_SUSPEND
);
567 /* suspend all CODECs */
568 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
569 /* If there are paths active then the CODEC will be held with
570 * bias _ON and should not be suspended. */
571 if (!codec
->suspended
&& codec
->driver
->suspend
) {
572 switch (codec
->dapm
.bias_level
) {
573 case SND_SOC_BIAS_STANDBY
:
574 case SND_SOC_BIAS_OFF
:
575 codec
->driver
->suspend(codec
, PMSG_SUSPEND
);
576 codec
->suspended
= 1;
577 codec
->cache_sync
= 1;
580 dev_dbg(codec
->dev
, "CODEC is on over suspend\n");
586 for (i
= 0; i
< card
->num_rtd
; i
++) {
587 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
589 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
592 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
593 cpu_dai
->driver
->suspend(cpu_dai
);
596 if (card
->suspend_post
)
597 card
->suspend_post(card
);
601 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
603 /* deferred resume work, so resume can complete before we finished
604 * setting our codec back up, which can be very slow on I2C
606 static void soc_resume_deferred(struct work_struct
*work
)
608 struct snd_soc_card
*card
=
609 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
610 struct snd_soc_codec
*codec
;
613 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
614 * so userspace apps are blocked from touching us
617 dev_dbg(card
->dev
, "starting resume work\n");
619 /* Bring us up into D2 so that DAPM starts enabling things */
620 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
622 if (card
->resume_pre
)
623 card
->resume_pre(card
);
625 /* resume AC97 DAIs */
626 for (i
= 0; i
< card
->num_rtd
; i
++) {
627 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
629 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
632 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
633 cpu_dai
->driver
->resume(cpu_dai
);
636 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
637 /* If the CODEC was idle over suspend then it will have been
638 * left with bias OFF or STANDBY and suspended so we must now
639 * resume. Otherwise the suspend was suppressed.
641 if (codec
->driver
->resume
&& codec
->suspended
) {
642 switch (codec
->dapm
.bias_level
) {
643 case SND_SOC_BIAS_STANDBY
:
644 case SND_SOC_BIAS_OFF
:
645 codec
->driver
->resume(codec
);
646 codec
->suspended
= 0;
649 dev_dbg(codec
->dev
, "CODEC was on over suspend\n");
655 for (i
= 0; i
< card
->num_rtd
; i
++) {
656 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
658 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
661 if (driver
->playback
.stream_name
!= NULL
)
662 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
663 SND_SOC_DAPM_STREAM_RESUME
);
665 if (driver
->capture
.stream_name
!= NULL
)
666 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
667 SND_SOC_DAPM_STREAM_RESUME
);
670 /* unmute any active DACs */
671 for (i
= 0; i
< card
->num_rtd
; i
++) {
672 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
673 struct snd_soc_dai_driver
*drv
= dai
->driver
;
675 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
678 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
679 drv
->ops
->digital_mute(dai
, 0);
682 for (i
= 0; i
< card
->num_rtd
; i
++) {
683 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
684 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
686 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
689 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
690 cpu_dai
->driver
->resume(cpu_dai
);
691 if (platform
->driver
->resume
&& platform
->suspended
) {
692 platform
->driver
->resume(cpu_dai
);
693 platform
->suspended
= 0;
697 if (card
->resume_post
)
698 card
->resume_post(card
);
700 dev_dbg(card
->dev
, "resume work completed\n");
702 /* userspace can access us now we are back as we were before */
703 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
706 /* powers up audio subsystem after a suspend */
707 int snd_soc_resume(struct device
*dev
)
709 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
710 int i
, ac97_control
= 0;
712 /* AC97 devices might have other drivers hanging off them so
713 * need to resume immediately. Other drivers don't have that
714 * problem and may take a substantial amount of time to resume
715 * due to I/O costs and anti-pop so handle them out of line.
717 for (i
= 0; i
< card
->num_rtd
; i
++) {
718 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
719 ac97_control
|= cpu_dai
->driver
->ac97_control
;
722 dev_dbg(dev
, "Resuming AC97 immediately\n");
723 soc_resume_deferred(&card
->deferred_resume_work
);
725 dev_dbg(dev
, "Scheduling resume work\n");
726 if (!schedule_work(&card
->deferred_resume_work
))
727 dev_err(dev
, "resume work item may be lost\n");
732 EXPORT_SYMBOL_GPL(snd_soc_resume
);
734 #define snd_soc_suspend NULL
735 #define snd_soc_resume NULL
738 static struct snd_soc_dai_ops null_dai_ops
= {
741 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
743 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
744 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
745 struct snd_soc_codec
*codec
;
746 struct snd_soc_platform
*platform
;
747 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
748 const char *platform_name
;
752 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
754 /* do we already have the CPU DAI for this link ? */
758 /* no, then find CPU DAI from registered DAIs*/
759 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
760 if (!strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
)) {
761 rtd
->cpu_dai
= cpu_dai
;
765 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
766 dai_link
->cpu_dai_name
);
769 /* do we already have the CODEC for this link ? */
774 /* no, then find CODEC from registered CODECs*/
775 list_for_each_entry(codec
, &codec_list
, list
) {
776 if (!strcmp(codec
->name
, dai_link
->codec_name
)) {
779 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
780 list_for_each_entry(codec_dai
, &dai_list
, list
) {
781 if (codec
->dev
== codec_dai
->dev
&&
782 !strcmp(codec_dai
->name
, dai_link
->codec_dai_name
)) {
783 rtd
->codec_dai
= codec_dai
;
787 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
788 dai_link
->codec_dai_name
);
793 dev_dbg(card
->dev
, "CODEC %s not registered\n",
794 dai_link
->codec_name
);
797 /* do we need a platform? */
801 /* if there's no platform we match on the empty platform */
802 platform_name
= dai_link
->platform_name
;
804 platform_name
= "snd-soc-dummy";
806 /* no, then find one from the set of registered platforms */
807 list_for_each_entry(platform
, &platform_list
, list
) {
808 if (!strcmp(platform
->name
, platform_name
)) {
809 rtd
->platform
= platform
;
814 dev_dbg(card
->dev
, "platform %s not registered\n",
815 dai_link
->platform_name
);
819 /* mark rtd as complete if we found all 4 of our client devices */
820 if (rtd
->codec
&& rtd
->codec_dai
&& rtd
->platform
&& rtd
->cpu_dai
) {
827 static void soc_remove_codec(struct snd_soc_codec
*codec
)
831 if (codec
->driver
->remove
) {
832 err
= codec
->driver
->remove(codec
);
835 "asoc: failed to remove %s: %d\n",
839 /* Make sure all DAPM widgets are freed */
840 snd_soc_dapm_free(&codec
->dapm
);
842 soc_cleanup_codec_debugfs(codec
);
844 list_del(&codec
->card_list
);
845 module_put(codec
->dev
->driver
->owner
);
848 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
850 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
851 struct snd_soc_codec
*codec
= rtd
->codec
;
852 struct snd_soc_platform
*platform
= rtd
->platform
;
853 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
856 /* unregister the rtd device */
857 if (rtd
->dev_registered
) {
858 device_remove_file(&rtd
->dev
, &dev_attr_pmdown_time
);
859 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
860 device_unregister(&rtd
->dev
);
861 rtd
->dev_registered
= 0;
864 /* remove the CODEC DAI */
865 if (codec_dai
&& codec_dai
->probed
&&
866 codec_dai
->driver
->remove_order
== order
) {
867 if (codec_dai
->driver
->remove
) {
868 err
= codec_dai
->driver
->remove(codec_dai
);
870 printk(KERN_ERR
"asoc: failed to remove %s\n", codec_dai
->name
);
872 codec_dai
->probed
= 0;
873 list_del(&codec_dai
->card_list
);
876 /* remove the platform */
877 if (platform
&& platform
->probed
&&
878 platform
->driver
->remove_order
== order
) {
879 if (platform
->driver
->remove
) {
880 err
= platform
->driver
->remove(platform
);
882 printk(KERN_ERR
"asoc: failed to remove %s\n", platform
->name
);
884 platform
->probed
= 0;
885 list_del(&platform
->card_list
);
886 module_put(platform
->dev
->driver
->owner
);
889 /* remove the CODEC */
890 if (codec
&& codec
->probed
&&
891 codec
->driver
->remove_order
== order
)
892 soc_remove_codec(codec
);
894 /* remove the cpu_dai */
895 if (cpu_dai
&& cpu_dai
->probed
&&
896 cpu_dai
->driver
->remove_order
== order
) {
897 if (cpu_dai
->driver
->remove
) {
898 err
= cpu_dai
->driver
->remove(cpu_dai
);
900 printk(KERN_ERR
"asoc: failed to remove %s\n", cpu_dai
->name
);
903 list_del(&cpu_dai
->card_list
);
904 module_put(cpu_dai
->dev
->driver
->owner
);
908 static void soc_remove_dai_links(struct snd_soc_card
*card
)
912 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
914 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
915 soc_remove_dai_link(card
, dai
, order
);
920 static void soc_set_name_prefix(struct snd_soc_card
*card
,
921 struct snd_soc_codec
*codec
)
925 if (card
->codec_conf
== NULL
)
928 for (i
= 0; i
< card
->num_configs
; i
++) {
929 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
930 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
931 codec
->name_prefix
= map
->name_prefix
;
937 static int soc_probe_codec(struct snd_soc_card
*card
,
938 struct snd_soc_codec
*codec
)
941 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
944 codec
->dapm
.card
= card
;
945 soc_set_name_prefix(card
, codec
);
947 if (!try_module_get(codec
->dev
->driver
->owner
))
950 soc_init_codec_debugfs(codec
);
952 if (driver
->dapm_widgets
)
953 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
954 driver
->num_dapm_widgets
);
956 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
959 ret
= driver
->probe(codec
);
962 "asoc: failed to probe CODEC %s: %d\n",
968 if (driver
->controls
)
969 snd_soc_add_controls(codec
, driver
->controls
,
970 driver
->num_controls
);
971 if (driver
->dapm_routes
)
972 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
973 driver
->num_dapm_routes
);
975 /* mark codec as probed and add to card codec list */
977 list_add(&codec
->card_list
, &card
->codec_dev_list
);
978 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
983 soc_cleanup_codec_debugfs(codec
);
984 module_put(codec
->dev
->driver
->owner
);
989 static int soc_probe_platform(struct snd_soc_card
*card
,
990 struct snd_soc_platform
*platform
)
993 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
995 platform
->card
= card
;
996 platform
->dapm
.card
= card
;
998 if (!try_module_get(platform
->dev
->driver
->owner
))
1001 if (driver
->dapm_widgets
)
1002 snd_soc_dapm_new_controls(&platform
->dapm
,
1003 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1005 if (driver
->probe
) {
1006 ret
= driver
->probe(platform
);
1008 dev_err(platform
->dev
,
1009 "asoc: failed to probe platform %s: %d\n",
1010 platform
->name
, ret
);
1015 if (driver
->controls
)
1016 snd_soc_add_platform_controls(platform
, driver
->controls
,
1017 driver
->num_controls
);
1018 if (driver
->dapm_routes
)
1019 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1020 driver
->num_dapm_routes
);
1022 /* mark platform as probed and add to card platform list */
1023 platform
->probed
= 1;
1024 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1025 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1030 module_put(platform
->dev
->driver
->owner
);
1035 static void rtd_release(struct device
*dev
) {}
1037 static int soc_post_component_init(struct snd_soc_card
*card
,
1038 struct snd_soc_codec
*codec
,
1039 int num
, int dailess
)
1041 struct snd_soc_dai_link
*dai_link
= NULL
;
1042 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1043 struct snd_soc_pcm_runtime
*rtd
;
1044 const char *temp
, *name
;
1048 dai_link
= &card
->dai_link
[num
];
1049 rtd
= &card
->rtd
[num
];
1050 name
= dai_link
->name
;
1052 aux_dev
= &card
->aux_dev
[num
];
1053 rtd
= &card
->rtd_aux
[num
];
1054 name
= aux_dev
->name
;
1058 /* machine controls, routes and widgets are not prefixed */
1059 temp
= codec
->name_prefix
;
1060 codec
->name_prefix
= NULL
;
1062 /* do machine specific initialization */
1063 if (!dailess
&& dai_link
->init
)
1064 ret
= dai_link
->init(rtd
);
1065 else if (dailess
&& aux_dev
->init
)
1066 ret
= aux_dev
->init(&codec
->dapm
);
1068 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1071 codec
->name_prefix
= temp
;
1073 /* Make sure all DAPM widgets are instantiated */
1074 snd_soc_dapm_new_widgets(&codec
->dapm
);
1076 /* register the rtd device */
1078 rtd
->dev
.parent
= card
->dev
;
1079 rtd
->dev
.release
= rtd_release
;
1080 rtd
->dev
.init_name
= name
;
1081 mutex_init(&rtd
->pcm_mutex
);
1082 ret
= device_register(&rtd
->dev
);
1085 "asoc: failed to register runtime device: %d\n", ret
);
1088 rtd
->dev_registered
= 1;
1090 /* add DAPM sysfs entries for this codec */
1091 ret
= snd_soc_dapm_sys_add(&rtd
->dev
);
1094 "asoc: failed to add codec dapm sysfs entries: %d\n",
1097 /* add codec sysfs entries */
1098 ret
= device_create_file(&rtd
->dev
, &dev_attr_codec_reg
);
1101 "asoc: failed to add codec sysfs files: %d\n", ret
);
1106 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1108 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1109 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1110 struct snd_soc_codec
*codec
= rtd
->codec
;
1111 struct snd_soc_platform
*platform
= rtd
->platform
;
1112 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
1115 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1116 card
->name
, num
, order
);
1118 /* config components */
1119 codec_dai
->codec
= codec
;
1120 cpu_dai
->platform
= platform
;
1121 codec_dai
->card
= card
;
1122 cpu_dai
->card
= card
;
1124 /* set default power off timeout */
1125 rtd
->pmdown_time
= pmdown_time
;
1127 /* probe the cpu_dai */
1128 if (!cpu_dai
->probed
&&
1129 cpu_dai
->driver
->probe_order
== order
) {
1130 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1133 if (cpu_dai
->driver
->probe
) {
1134 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1136 printk(KERN_ERR
"asoc: failed to probe CPU DAI %s\n",
1138 module_put(cpu_dai
->dev
->driver
->owner
);
1142 cpu_dai
->probed
= 1;
1143 /* mark cpu_dai as probed and add to card dai list */
1144 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1147 /* probe the CODEC */
1148 if (!codec
->probed
&&
1149 codec
->driver
->probe_order
== order
) {
1150 ret
= soc_probe_codec(card
, codec
);
1155 /* probe the platform */
1156 if (!platform
->probed
&&
1157 platform
->driver
->probe_order
== order
) {
1158 ret
= soc_probe_platform(card
, platform
);
1163 /* probe the CODEC DAI */
1164 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1165 if (codec_dai
->driver
->probe
) {
1166 ret
= codec_dai
->driver
->probe(codec_dai
);
1168 printk(KERN_ERR
"asoc: failed to probe CODEC DAI %s\n",
1174 /* mark codec_dai as probed and add to card dai list */
1175 codec_dai
->probed
= 1;
1176 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1179 /* complete DAI probe during last probe */
1180 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1183 ret
= soc_post_component_init(card
, codec
, num
, 0);
1187 ret
= device_create_file(&rtd
->dev
, &dev_attr_pmdown_time
);
1189 printk(KERN_WARNING
"asoc: failed to add pmdown_time sysfs\n");
1191 /* create the pcm */
1192 ret
= soc_new_pcm(rtd
, num
);
1194 printk(KERN_ERR
"asoc: can't create pcm %s\n", dai_link
->stream_name
);
1198 /* add platform data for AC97 devices */
1199 if (rtd
->codec_dai
->driver
->ac97_control
)
1200 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1205 #ifdef CONFIG_SND_SOC_AC97_BUS
1206 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1210 /* Only instantiate AC97 if not already done by the adaptor
1211 * for the generic AC97 subsystem.
1213 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1215 * It is possible that the AC97 device is already registered to
1216 * the device subsystem. This happens when the device is created
1217 * via snd_ac97_mixer(). Currently only SoC codec that does so
1218 * is the generic AC97 glue but others migh emerge.
1220 * In those cases we don't try to register the device again.
1222 if (!rtd
->codec
->ac97_created
)
1225 ret
= soc_ac97_dev_register(rtd
->codec
);
1227 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1231 rtd
->codec
->ac97_registered
= 1;
1236 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1238 if (codec
->ac97_registered
) {
1239 soc_ac97_dev_unregister(codec
);
1240 codec
->ac97_registered
= 0;
1245 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1247 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1248 struct snd_soc_codec
*codec
;
1251 /* find CODEC from registered CODECs*/
1252 list_for_each_entry(codec
, &codec_list
, list
) {
1253 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1254 if (codec
->probed
) {
1256 "asoc: codec already probed");
1263 /* codec not found */
1264 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1268 ret
= soc_probe_codec(card
, codec
);
1272 ret
= soc_post_component_init(card
, codec
, num
, 1);
1278 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1280 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1281 struct snd_soc_codec
*codec
= rtd
->codec
;
1283 /* unregister the rtd device */
1284 if (rtd
->dev_registered
) {
1285 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
1286 device_unregister(&rtd
->dev
);
1287 rtd
->dev_registered
= 0;
1290 if (codec
&& codec
->probed
)
1291 soc_remove_codec(codec
);
1294 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1295 enum snd_soc_compress_type compress_type
)
1299 if (codec
->cache_init
)
1302 /* override the compress_type if necessary */
1303 if (compress_type
&& codec
->compress_type
!= compress_type
)
1304 codec
->compress_type
= compress_type
;
1305 ret
= snd_soc_cache_init(codec
);
1307 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1311 codec
->cache_init
= 1;
1315 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
1317 struct snd_soc_codec
*codec
;
1318 struct snd_soc_codec_conf
*codec_conf
;
1319 enum snd_soc_compress_type compress_type
;
1322 mutex_lock(&card
->mutex
);
1324 if (card
->instantiated
) {
1325 mutex_unlock(&card
->mutex
);
1330 for (i
= 0; i
< card
->num_links
; i
++)
1331 soc_bind_dai_link(card
, i
);
1333 /* bind completed ? */
1334 if (card
->num_rtd
!= card
->num_links
) {
1335 mutex_unlock(&card
->mutex
);
1339 /* initialize the register cache for each available codec */
1340 list_for_each_entry(codec
, &codec_list
, list
) {
1341 if (codec
->cache_init
)
1343 /* by default we don't override the compress_type */
1345 /* check to see if we need to override the compress_type */
1346 for (i
= 0; i
< card
->num_configs
; ++i
) {
1347 codec_conf
= &card
->codec_conf
[i
];
1348 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1349 compress_type
= codec_conf
->compress_type
;
1350 if (compress_type
&& compress_type
1351 != codec
->compress_type
)
1355 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1357 mutex_unlock(&card
->mutex
);
1362 /* card bind complete so register a sound card */
1363 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1364 card
->owner
, 0, &card
->snd_card
);
1366 printk(KERN_ERR
"asoc: can't create sound card for card %s\n",
1368 mutex_unlock(&card
->mutex
);
1371 card
->snd_card
->dev
= card
->dev
;
1373 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1374 card
->dapm
.dev
= card
->dev
;
1375 card
->dapm
.card
= card
;
1376 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1378 #ifdef CONFIG_DEBUG_FS
1379 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1382 #ifdef CONFIG_PM_SLEEP
1383 /* deferred resume work */
1384 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1387 if (card
->dapm_widgets
)
1388 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1389 card
->num_dapm_widgets
);
1391 /* initialise the sound card only once */
1393 ret
= card
->probe(card
);
1395 goto card_probe_error
;
1398 /* early DAI link probe */
1399 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1401 for (i
= 0; i
< card
->num_links
; i
++) {
1402 ret
= soc_probe_dai_link(card
, i
, order
);
1404 pr_err("asoc: failed to instantiate card %s: %d\n",
1411 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1412 ret
= soc_probe_aux_dev(card
, i
);
1414 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1416 goto probe_aux_dev_err
;
1420 /* We should have a non-codec control add function but we don't */
1422 snd_soc_add_controls(list_first_entry(&card
->codec_dev_list
,
1423 struct snd_soc_codec
,
1426 card
->num_controls
);
1428 if (card
->dapm_routes
)
1429 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1430 card
->num_dapm_routes
);
1432 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1434 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1435 "%s", card
->long_name
? card
->long_name
: card
->name
);
1436 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1437 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1438 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1439 switch (card
->snd_card
->driver
[i
]) {
1445 if (!isalnum(card
->snd_card
->driver
[i
]))
1446 card
->snd_card
->driver
[i
] = '_';
1451 if (card
->late_probe
) {
1452 ret
= card
->late_probe(card
);
1454 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1456 goto probe_aux_dev_err
;
1460 ret
= snd_card_register(card
->snd_card
);
1462 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n", card
->name
);
1463 goto probe_aux_dev_err
;
1466 #ifdef CONFIG_SND_SOC_AC97_BUS
1467 /* register any AC97 codecs */
1468 for (i
= 0; i
< card
->num_rtd
; i
++) {
1469 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1471 printk(KERN_ERR
"asoc: failed to register AC97 %s\n", card
->name
);
1473 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1474 goto probe_aux_dev_err
;
1479 card
->instantiated
= 1;
1480 mutex_unlock(&card
->mutex
);
1484 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1485 soc_remove_aux_dev(card
, i
);
1488 soc_remove_dai_links(card
);
1494 snd_card_free(card
->snd_card
);
1496 mutex_unlock(&card
->mutex
);
1500 * Attempt to initialise any uninitialised cards. Must be called with
1503 static void snd_soc_instantiate_cards(void)
1505 struct snd_soc_card
*card
;
1506 list_for_each_entry(card
, &card_list
, list
)
1507 snd_soc_instantiate_card(card
);
1510 /* probes a new socdev */
1511 static int soc_probe(struct platform_device
*pdev
)
1513 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1517 * no card, so machine driver should be registering card
1518 * we should not be here in that case so ret error
1523 /* Bodge while we unpick instantiation */
1524 card
->dev
= &pdev
->dev
;
1526 ret
= snd_soc_register_card(card
);
1528 dev_err(&pdev
->dev
, "Failed to register card\n");
1535 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1539 /* make sure any delayed work runs */
1540 for (i
= 0; i
< card
->num_rtd
; i
++) {
1541 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1542 flush_delayed_work_sync(&rtd
->delayed_work
);
1545 /* remove auxiliary devices */
1546 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1547 soc_remove_aux_dev(card
, i
);
1549 /* remove and free each DAI */
1550 soc_remove_dai_links(card
);
1552 soc_cleanup_card_debugfs(card
);
1554 /* remove the card */
1558 snd_soc_dapm_free(&card
->dapm
);
1561 snd_card_free(card
->snd_card
);
1566 /* removes a socdev */
1567 static int soc_remove(struct platform_device
*pdev
)
1569 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1571 snd_soc_unregister_card(card
);
1575 int snd_soc_poweroff(struct device
*dev
)
1577 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1580 if (!card
->instantiated
)
1583 /* Flush out pmdown_time work - we actually do want to run it
1584 * now, we're shutting down so no imminent restart. */
1585 for (i
= 0; i
< card
->num_rtd
; i
++) {
1586 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1587 flush_delayed_work_sync(&rtd
->delayed_work
);
1590 snd_soc_dapm_shutdown(card
);
1594 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1596 const struct dev_pm_ops snd_soc_pm_ops
= {
1597 .suspend
= snd_soc_suspend
,
1598 .resume
= snd_soc_resume
,
1599 .poweroff
= snd_soc_poweroff
,
1601 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1603 /* ASoC platform driver */
1604 static struct platform_driver soc_driver
= {
1606 .name
= "soc-audio",
1607 .owner
= THIS_MODULE
,
1608 .pm
= &snd_soc_pm_ops
,
1611 .remove
= soc_remove
,
1615 * snd_soc_codec_volatile_register: Report if a register is volatile.
1617 * @codec: CODEC to query.
1618 * @reg: Register to query.
1620 * Boolean function indiciating if a CODEC register is volatile.
1622 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1625 if (codec
->volatile_register
)
1626 return codec
->volatile_register(codec
, reg
);
1630 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1633 * snd_soc_codec_readable_register: Report if a register is readable.
1635 * @codec: CODEC to query.
1636 * @reg: Register to query.
1638 * Boolean function indicating if a CODEC register is readable.
1640 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1643 if (codec
->readable_register
)
1644 return codec
->readable_register(codec
, reg
);
1648 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1651 * snd_soc_codec_writable_register: Report if a register is writable.
1653 * @codec: CODEC to query.
1654 * @reg: Register to query.
1656 * Boolean function indicating if a CODEC register is writable.
1658 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1661 if (codec
->writable_register
)
1662 return codec
->writable_register(codec
, reg
);
1666 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1668 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1673 if (!platform
->driver
->read
) {
1674 dev_err(platform
->dev
, "platform has no read back\n");
1678 ret
= platform
->driver
->read(platform
, reg
);
1679 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1680 trace_snd_soc_preg_read(platform
, reg
, ret
);
1684 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1686 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1687 unsigned int reg
, unsigned int val
)
1689 if (!platform
->driver
->write
) {
1690 dev_err(platform
->dev
, "platform has no write back\n");
1694 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1695 trace_snd_soc_preg_write(platform
, reg
, val
);
1696 return platform
->driver
->write(platform
, reg
, val
);
1698 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1701 * snd_soc_new_ac97_codec - initailise AC97 device
1702 * @codec: audio codec
1703 * @ops: AC97 bus operations
1704 * @num: AC97 codec number
1706 * Initialises AC97 codec resources for use by ad-hoc devices only.
1708 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1709 struct snd_ac97_bus_ops
*ops
, int num
)
1711 mutex_lock(&codec
->mutex
);
1713 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1714 if (codec
->ac97
== NULL
) {
1715 mutex_unlock(&codec
->mutex
);
1719 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1720 if (codec
->ac97
->bus
== NULL
) {
1723 mutex_unlock(&codec
->mutex
);
1727 codec
->ac97
->bus
->ops
= ops
;
1728 codec
->ac97
->num
= num
;
1731 * Mark the AC97 device to be created by us. This way we ensure that the
1732 * device will be registered with the device subsystem later on.
1734 codec
->ac97_created
= 1;
1736 mutex_unlock(&codec
->mutex
);
1739 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1742 * snd_soc_free_ac97_codec - free AC97 codec device
1743 * @codec: audio codec
1745 * Frees AC97 codec device resources.
1747 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1749 mutex_lock(&codec
->mutex
);
1750 #ifdef CONFIG_SND_SOC_AC97_BUS
1751 soc_unregister_ac97_dai_link(codec
);
1753 kfree(codec
->ac97
->bus
);
1756 codec
->ac97_created
= 0;
1757 mutex_unlock(&codec
->mutex
);
1759 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1761 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1765 ret
= codec
->read(codec
, reg
);
1766 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1767 trace_snd_soc_reg_read(codec
, reg
, ret
);
1771 EXPORT_SYMBOL_GPL(snd_soc_read
);
1773 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
1774 unsigned int reg
, unsigned int val
)
1776 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
1777 trace_snd_soc_reg_write(codec
, reg
, val
);
1778 return codec
->write(codec
, reg
, val
);
1780 EXPORT_SYMBOL_GPL(snd_soc_write
);
1782 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
1783 unsigned int reg
, const void *data
, size_t len
)
1785 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
1787 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
1790 * snd_soc_update_bits - update codec register bits
1791 * @codec: audio codec
1792 * @reg: codec register
1793 * @mask: register mask
1796 * Writes new register value.
1798 * Returns 1 for change, 0 for no change, or negative error code.
1800 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1801 unsigned int mask
, unsigned int value
)
1804 unsigned int old
, new;
1807 ret
= snd_soc_read(codec
, reg
);
1812 new = (old
& ~mask
) | (value
& mask
);
1813 change
= old
!= new;
1815 ret
= snd_soc_write(codec
, reg
, new);
1822 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1825 * snd_soc_update_bits_locked - update codec register bits
1826 * @codec: audio codec
1827 * @reg: codec register
1828 * @mask: register mask
1831 * Writes new register value, and takes the codec mutex.
1833 * Returns 1 for change else 0.
1835 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
1836 unsigned short reg
, unsigned int mask
,
1841 mutex_lock(&codec
->mutex
);
1842 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
1843 mutex_unlock(&codec
->mutex
);
1847 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
1850 * snd_soc_test_bits - test register for change
1851 * @codec: audio codec
1852 * @reg: codec register
1853 * @mask: register mask
1856 * Tests a register with a new value and checks if the new value is
1857 * different from the old value.
1859 * Returns 1 for change else 0.
1861 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1862 unsigned int mask
, unsigned int value
)
1865 unsigned int old
, new;
1867 old
= snd_soc_read(codec
, reg
);
1868 new = (old
& ~mask
) | value
;
1869 change
= old
!= new;
1873 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1876 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1877 * @substream: the pcm substream
1878 * @hw: the hardware parameters
1880 * Sets the substream runtime hardware parameters.
1882 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1883 const struct snd_pcm_hardware
*hw
)
1885 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1886 runtime
->hw
.info
= hw
->info
;
1887 runtime
->hw
.formats
= hw
->formats
;
1888 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1889 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1890 runtime
->hw
.periods_min
= hw
->periods_min
;
1891 runtime
->hw
.periods_max
= hw
->periods_max
;
1892 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1893 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1896 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1899 * snd_soc_cnew - create new control
1900 * @_template: control template
1901 * @data: control private data
1902 * @long_name: control long name
1903 * @prefix: control name prefix
1905 * Create a new mixer control from a template control.
1907 * Returns 0 for success, else error.
1909 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1910 void *data
, char *long_name
,
1913 struct snd_kcontrol_new
template;
1914 struct snd_kcontrol
*kcontrol
;
1918 memcpy(&template, _template
, sizeof(template));
1922 long_name
= template.name
;
1925 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
1926 name
= kmalloc(name_len
, GFP_KERNEL
);
1930 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
1932 template.name
= name
;
1934 template.name
= long_name
;
1937 kcontrol
= snd_ctl_new1(&template, data
);
1943 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
1946 * snd_soc_add_controls - add an array of controls to a codec.
1947 * Convienience function to add a list of controls. Many codecs were
1948 * duplicating this code.
1950 * @codec: codec to add controls to
1951 * @controls: array of controls to add
1952 * @num_controls: number of elements in the array
1954 * Return 0 for success, else error.
1956 int snd_soc_add_controls(struct snd_soc_codec
*codec
,
1957 const struct snd_kcontrol_new
*controls
, int num_controls
)
1959 struct snd_card
*card
= codec
->card
->snd_card
;
1962 for (i
= 0; i
< num_controls
; i
++) {
1963 const struct snd_kcontrol_new
*control
= &controls
[i
];
1964 err
= snd_ctl_add(card
, snd_soc_cnew(control
, codec
,
1966 codec
->name_prefix
));
1968 dev_err(codec
->dev
, "%s: Failed to add %s: %d\n",
1969 codec
->name
, control
->name
, err
);
1976 EXPORT_SYMBOL_GPL(snd_soc_add_controls
);
1979 * snd_soc_add_platform_controls - add an array of controls to a platform.
1980 * Convienience function to add a list of controls.
1982 * @platform: platform to add controls to
1983 * @controls: array of controls to add
1984 * @num_controls: number of elements in the array
1986 * Return 0 for success, else error.
1988 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
1989 const struct snd_kcontrol_new
*controls
, int num_controls
)
1991 struct snd_card
*card
= platform
->card
->snd_card
;
1994 for (i
= 0; i
< num_controls
; i
++) {
1995 const struct snd_kcontrol_new
*control
= &controls
[i
];
1996 err
= snd_ctl_add(card
, snd_soc_cnew(control
, platform
,
1997 control
->name
, NULL
));
1999 dev_err(platform
->dev
, "Failed to add %s %d\n",control
->name
, err
);
2006 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2009 * snd_soc_info_enum_double - enumerated double mixer info callback
2010 * @kcontrol: mixer control
2011 * @uinfo: control element information
2013 * Callback to provide information about a double enumerated
2016 * Returns 0 for success.
2018 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2019 struct snd_ctl_elem_info
*uinfo
)
2021 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2023 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2024 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2025 uinfo
->value
.enumerated
.items
= e
->max
;
2027 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2028 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2029 strcpy(uinfo
->value
.enumerated
.name
,
2030 e
->texts
[uinfo
->value
.enumerated
.item
]);
2033 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2036 * snd_soc_get_enum_double - enumerated double mixer get callback
2037 * @kcontrol: mixer control
2038 * @ucontrol: control element information
2040 * Callback to get the value of a double enumerated mixer.
2042 * Returns 0 for success.
2044 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2045 struct snd_ctl_elem_value
*ucontrol
)
2047 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2048 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2049 unsigned int val
, bitmask
;
2051 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2053 val
= snd_soc_read(codec
, e
->reg
);
2054 ucontrol
->value
.enumerated
.item
[0]
2055 = (val
>> e
->shift_l
) & (bitmask
- 1);
2056 if (e
->shift_l
!= e
->shift_r
)
2057 ucontrol
->value
.enumerated
.item
[1] =
2058 (val
>> e
->shift_r
) & (bitmask
- 1);
2062 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2065 * snd_soc_put_enum_double - enumerated double mixer put callback
2066 * @kcontrol: mixer control
2067 * @ucontrol: control element information
2069 * Callback to set the value of a double enumerated mixer.
2071 * Returns 0 for success.
2073 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2074 struct snd_ctl_elem_value
*ucontrol
)
2076 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2077 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2079 unsigned int mask
, bitmask
;
2081 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2083 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2085 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2086 mask
= (bitmask
- 1) << e
->shift_l
;
2087 if (e
->shift_l
!= e
->shift_r
) {
2088 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2090 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2091 mask
|= (bitmask
- 1) << e
->shift_r
;
2094 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2096 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2099 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2100 * @kcontrol: mixer control
2101 * @ucontrol: control element information
2103 * Callback to get the value of a double semi enumerated mixer.
2105 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2106 * used for handling bitfield coded enumeration for example.
2108 * Returns 0 for success.
2110 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2111 struct snd_ctl_elem_value
*ucontrol
)
2113 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2114 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2115 unsigned int reg_val
, val
, mux
;
2117 reg_val
= snd_soc_read(codec
, e
->reg
);
2118 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2119 for (mux
= 0; mux
< e
->max
; mux
++) {
2120 if (val
== e
->values
[mux
])
2123 ucontrol
->value
.enumerated
.item
[0] = mux
;
2124 if (e
->shift_l
!= e
->shift_r
) {
2125 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2126 for (mux
= 0; mux
< e
->max
; mux
++) {
2127 if (val
== e
->values
[mux
])
2130 ucontrol
->value
.enumerated
.item
[1] = mux
;
2135 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2138 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2139 * @kcontrol: mixer control
2140 * @ucontrol: control element information
2142 * Callback to set the value of a double semi enumerated mixer.
2144 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2145 * used for handling bitfield coded enumeration for example.
2147 * Returns 0 for success.
2149 int snd_soc_put_value_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
;
2157 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2159 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2160 mask
= e
->mask
<< e
->shift_l
;
2161 if (e
->shift_l
!= e
->shift_r
) {
2162 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2164 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2165 mask
|= e
->mask
<< e
->shift_r
;
2168 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2170 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2173 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2174 * @kcontrol: mixer control
2175 * @uinfo: control element information
2177 * Callback to provide information about an external enumerated
2180 * Returns 0 for success.
2182 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2183 struct snd_ctl_elem_info
*uinfo
)
2185 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2187 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2189 uinfo
->value
.enumerated
.items
= e
->max
;
2191 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2192 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2193 strcpy(uinfo
->value
.enumerated
.name
,
2194 e
->texts
[uinfo
->value
.enumerated
.item
]);
2197 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2200 * snd_soc_info_volsw_ext - external single mixer info callback
2201 * @kcontrol: mixer control
2202 * @uinfo: control element information
2204 * Callback to provide information about a single external mixer control.
2206 * Returns 0 for success.
2208 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2209 struct snd_ctl_elem_info
*uinfo
)
2211 int max
= kcontrol
->private_value
;
2213 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2214 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2216 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2219 uinfo
->value
.integer
.min
= 0;
2220 uinfo
->value
.integer
.max
= max
;
2223 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2226 * snd_soc_info_volsw - single mixer info callback
2227 * @kcontrol: mixer control
2228 * @uinfo: control element information
2230 * Callback to provide information about a single mixer control.
2232 * Returns 0 for success.
2234 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2235 struct snd_ctl_elem_info
*uinfo
)
2237 struct soc_mixer_control
*mc
=
2238 (struct soc_mixer_control
*)kcontrol
->private_value
;
2240 unsigned int shift
= mc
->shift
;
2241 unsigned int rshift
= mc
->rshift
;
2243 if (!mc
->platform_max
)
2244 mc
->platform_max
= mc
->max
;
2245 platform_max
= mc
->platform_max
;
2247 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2248 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2250 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2252 uinfo
->count
= shift
== rshift
? 1 : 2;
2253 uinfo
->value
.integer
.min
= 0;
2254 uinfo
->value
.integer
.max
= platform_max
;
2257 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2260 * snd_soc_get_volsw - single mixer get callback
2261 * @kcontrol: mixer control
2262 * @ucontrol: control element information
2264 * Callback to get the value of a single mixer control.
2266 * Returns 0 for success.
2268 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2269 struct snd_ctl_elem_value
*ucontrol
)
2271 struct soc_mixer_control
*mc
=
2272 (struct soc_mixer_control
*)kcontrol
->private_value
;
2273 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2274 unsigned int reg
= mc
->reg
;
2275 unsigned int shift
= mc
->shift
;
2276 unsigned int rshift
= mc
->rshift
;
2278 unsigned int mask
= (1 << fls(max
)) - 1;
2279 unsigned int invert
= mc
->invert
;
2281 ucontrol
->value
.integer
.value
[0] =
2282 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2283 if (shift
!= rshift
)
2284 ucontrol
->value
.integer
.value
[1] =
2285 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2287 ucontrol
->value
.integer
.value
[0] =
2288 max
- ucontrol
->value
.integer
.value
[0];
2289 if (shift
!= rshift
)
2290 ucontrol
->value
.integer
.value
[1] =
2291 max
- ucontrol
->value
.integer
.value
[1];
2296 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2299 * snd_soc_put_volsw - single mixer put callback
2300 * @kcontrol: mixer control
2301 * @ucontrol: control element information
2303 * Callback to set the value of a single mixer control.
2305 * Returns 0 for success.
2307 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2308 struct snd_ctl_elem_value
*ucontrol
)
2310 struct soc_mixer_control
*mc
=
2311 (struct soc_mixer_control
*)kcontrol
->private_value
;
2312 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2313 unsigned int reg
= mc
->reg
;
2314 unsigned int shift
= mc
->shift
;
2315 unsigned int rshift
= mc
->rshift
;
2317 unsigned int mask
= (1 << fls(max
)) - 1;
2318 unsigned int invert
= mc
->invert
;
2319 unsigned int val
, val2
, val_mask
;
2321 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2324 val_mask
= mask
<< shift
;
2326 if (shift
!= rshift
) {
2327 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2330 val_mask
|= mask
<< rshift
;
2331 val
|= val2
<< rshift
;
2333 return snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2335 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2338 * snd_soc_info_volsw_2r - double mixer info callback
2339 * @kcontrol: mixer control
2340 * @uinfo: control element information
2342 * Callback to provide information about a double mixer control that
2343 * spans 2 codec registers.
2345 * Returns 0 for success.
2347 int snd_soc_info_volsw_2r(struct snd_kcontrol
*kcontrol
,
2348 struct snd_ctl_elem_info
*uinfo
)
2350 struct soc_mixer_control
*mc
=
2351 (struct soc_mixer_control
*)kcontrol
->private_value
;
2354 if (!mc
->platform_max
)
2355 mc
->platform_max
= mc
->max
;
2356 platform_max
= mc
->platform_max
;
2358 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2359 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2361 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2364 uinfo
->value
.integer
.min
= 0;
2365 uinfo
->value
.integer
.max
= platform_max
;
2368 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r
);
2371 * snd_soc_get_volsw_2r - double mixer get callback
2372 * @kcontrol: mixer control
2373 * @ucontrol: control element information
2375 * Callback to get the value of a double mixer control that spans 2 registers.
2377 * Returns 0 for success.
2379 int snd_soc_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
2380 struct snd_ctl_elem_value
*ucontrol
)
2382 struct soc_mixer_control
*mc
=
2383 (struct soc_mixer_control
*)kcontrol
->private_value
;
2384 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2385 unsigned int reg
= mc
->reg
;
2386 unsigned int reg2
= mc
->rreg
;
2387 unsigned int shift
= mc
->shift
;
2389 unsigned int mask
= (1 << fls(max
)) - 1;
2390 unsigned int invert
= mc
->invert
;
2392 ucontrol
->value
.integer
.value
[0] =
2393 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2394 ucontrol
->value
.integer
.value
[1] =
2395 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2397 ucontrol
->value
.integer
.value
[0] =
2398 max
- ucontrol
->value
.integer
.value
[0];
2399 ucontrol
->value
.integer
.value
[1] =
2400 max
- ucontrol
->value
.integer
.value
[1];
2405 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r
);
2408 * snd_soc_put_volsw_2r - double mixer set callback
2409 * @kcontrol: mixer control
2410 * @ucontrol: control element information
2412 * Callback to set the value of a double mixer control that spans 2 registers.
2414 * Returns 0 for success.
2416 int snd_soc_put_volsw_2r(struct snd_kcontrol
*kcontrol
,
2417 struct snd_ctl_elem_value
*ucontrol
)
2419 struct soc_mixer_control
*mc
=
2420 (struct soc_mixer_control
*)kcontrol
->private_value
;
2421 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2422 unsigned int reg
= mc
->reg
;
2423 unsigned int reg2
= mc
->rreg
;
2424 unsigned int shift
= mc
->shift
;
2426 unsigned int mask
= (1 << fls(max
)) - 1;
2427 unsigned int invert
= mc
->invert
;
2429 unsigned int val
, val2
, val_mask
;
2431 val_mask
= mask
<< shift
;
2432 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2433 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2441 val2
= val2
<< shift
;
2443 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2447 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2450 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r
);
2453 * snd_soc_info_volsw_s8 - signed mixer info callback
2454 * @kcontrol: mixer control
2455 * @uinfo: control element information
2457 * Callback to provide information about a signed mixer control.
2459 * Returns 0 for success.
2461 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2462 struct snd_ctl_elem_info
*uinfo
)
2464 struct soc_mixer_control
*mc
=
2465 (struct soc_mixer_control
*)kcontrol
->private_value
;
2469 if (!mc
->platform_max
)
2470 mc
->platform_max
= mc
->max
;
2471 platform_max
= mc
->platform_max
;
2473 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2475 uinfo
->value
.integer
.min
= 0;
2476 uinfo
->value
.integer
.max
= platform_max
- min
;
2479 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2482 * snd_soc_get_volsw_s8 - signed mixer get callback
2483 * @kcontrol: mixer control
2484 * @ucontrol: control element information
2486 * Callback to get the value of a signed mixer control.
2488 * Returns 0 for success.
2490 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2491 struct snd_ctl_elem_value
*ucontrol
)
2493 struct soc_mixer_control
*mc
=
2494 (struct soc_mixer_control
*)kcontrol
->private_value
;
2495 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2496 unsigned int reg
= mc
->reg
;
2498 int val
= snd_soc_read(codec
, reg
);
2500 ucontrol
->value
.integer
.value
[0] =
2501 ((signed char)(val
& 0xff))-min
;
2502 ucontrol
->value
.integer
.value
[1] =
2503 ((signed char)((val
>> 8) & 0xff))-min
;
2506 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2509 * snd_soc_put_volsw_sgn - signed mixer put callback
2510 * @kcontrol: mixer control
2511 * @ucontrol: control element information
2513 * Callback to set the value of a signed mixer control.
2515 * Returns 0 for success.
2517 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2518 struct snd_ctl_elem_value
*ucontrol
)
2520 struct soc_mixer_control
*mc
=
2521 (struct soc_mixer_control
*)kcontrol
->private_value
;
2522 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2523 unsigned int reg
= mc
->reg
;
2527 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2528 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2530 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2532 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2535 * snd_soc_limit_volume - Set new limit to an existing volume control.
2537 * @codec: where to look for the control
2538 * @name: Name of the control
2539 * @max: new maximum limit
2541 * Return 0 for success, else error.
2543 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2544 const char *name
, int max
)
2546 struct snd_card
*card
= codec
->card
->snd_card
;
2547 struct snd_kcontrol
*kctl
;
2548 struct soc_mixer_control
*mc
;
2552 /* Sanity check for name and max */
2553 if (unlikely(!name
|| max
<= 0))
2556 list_for_each_entry(kctl
, &card
->controls
, list
) {
2557 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2563 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2564 if (max
<= mc
->max
) {
2565 mc
->platform_max
= max
;
2571 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2574 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2575 * mixer info callback
2576 * @kcontrol: mixer control
2577 * @uinfo: control element information
2579 * Returns 0 for success.
2581 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2582 struct snd_ctl_elem_info
*uinfo
)
2584 struct soc_mixer_control
*mc
=
2585 (struct soc_mixer_control
*)kcontrol
->private_value
;
2589 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2591 uinfo
->value
.integer
.min
= 0;
2592 uinfo
->value
.integer
.max
= max
-min
;
2596 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx
);
2599 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2600 * mixer get callback
2601 * @kcontrol: mixer control
2602 * @uinfo: control element information
2604 * Returns 0 for success.
2606 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2607 struct snd_ctl_elem_value
*ucontrol
)
2609 struct soc_mixer_control
*mc
=
2610 (struct soc_mixer_control
*)kcontrol
->private_value
;
2611 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2612 unsigned int mask
= (1<<mc
->shift
)-1;
2614 int val
= snd_soc_read(codec
, mc
->reg
) & mask
;
2615 int valr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2617 ucontrol
->value
.integer
.value
[0] = ((val
& 0xff)-min
) & mask
;
2618 ucontrol
->value
.integer
.value
[1] = ((valr
& 0xff)-min
) & mask
;
2621 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx
);
2624 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2625 * mixer put callback
2626 * @kcontrol: mixer control
2627 * @uinfo: control element information
2629 * Returns 0 for success.
2631 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2632 struct snd_ctl_elem_value
*ucontrol
)
2634 struct soc_mixer_control
*mc
=
2635 (struct soc_mixer_control
*)kcontrol
->private_value
;
2636 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2637 unsigned int mask
= (1<<mc
->shift
)-1;
2640 unsigned int val
, valr
, oval
, ovalr
;
2642 val
= ((ucontrol
->value
.integer
.value
[0]+min
) & 0xff);
2644 valr
= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff);
2647 oval
= snd_soc_read(codec
, mc
->reg
) & mask
;
2648 ovalr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2652 ret
= snd_soc_write(codec
, mc
->reg
, val
);
2656 if (ovalr
!= valr
) {
2657 ret
= snd_soc_write(codec
, mc
->rreg
, valr
);
2664 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx
);
2667 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2669 * @clk_id: DAI specific clock ID
2670 * @freq: new clock frequency in Hz
2671 * @dir: new clock direction - input/output.
2673 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2675 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2676 unsigned int freq
, int dir
)
2678 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
2679 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
2680 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
2681 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
2686 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2689 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2691 * @clk_id: DAI specific clock ID
2692 * @source: Source for the clock
2693 * @freq: new clock frequency in Hz
2694 * @dir: new clock direction - input/output.
2696 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2698 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
2699 int source
, unsigned int freq
, int dir
)
2701 if (codec
->driver
->set_sysclk
)
2702 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
2707 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
2710 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2712 * @div_id: DAI specific clock divider ID
2713 * @div: new clock divisor.
2715 * Configures the clock dividers. This is used to derive the best DAI bit and
2716 * frame clocks from the system or master clock. It's best to set the DAI bit
2717 * and frame clocks as low as possible to save system power.
2719 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2720 int div_id
, int div
)
2722 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
2723 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
2727 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2730 * snd_soc_dai_set_pll - configure DAI PLL.
2732 * @pll_id: DAI specific PLL ID
2733 * @source: DAI specific source for the PLL
2734 * @freq_in: PLL input clock frequency in Hz
2735 * @freq_out: requested PLL output clock frequency in Hz
2737 * Configures and enables PLL to generate output clock based on input clock.
2739 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2740 unsigned int freq_in
, unsigned int freq_out
)
2742 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
2743 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
2745 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
2746 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
2751 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2754 * snd_soc_codec_set_pll - configure codec PLL.
2756 * @pll_id: DAI specific PLL ID
2757 * @source: DAI specific source for the PLL
2758 * @freq_in: PLL input clock frequency in Hz
2759 * @freq_out: requested PLL output clock frequency in Hz
2761 * Configures and enables PLL to generate output clock based on input clock.
2763 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
2764 unsigned int freq_in
, unsigned int freq_out
)
2766 if (codec
->driver
->set_pll
)
2767 return codec
->driver
->set_pll(codec
, pll_id
, source
,
2772 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
2775 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2777 * @fmt: SND_SOC_DAIFMT_ format value.
2779 * Configures the DAI hardware format and clocking.
2781 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2783 if (dai
->driver
&& dai
->driver
->ops
->set_fmt
)
2784 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
2788 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2791 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2793 * @tx_mask: bitmask representing active TX slots.
2794 * @rx_mask: bitmask representing active RX slots.
2795 * @slots: Number of slots in use.
2796 * @slot_width: Width in bits for each slot.
2798 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2801 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2802 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
2804 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
2805 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
2810 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
2813 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2815 * @tx_num: how many TX channels
2816 * @tx_slot: pointer to an array which imply the TX slot number channel
2818 * @rx_num: how many RX channels
2819 * @rx_slot: pointer to an array which imply the RX slot number channel
2822 * configure the relationship between channel number and TDM slot number.
2824 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
2825 unsigned int tx_num
, unsigned int *tx_slot
,
2826 unsigned int rx_num
, unsigned int *rx_slot
)
2828 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
2829 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
2834 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
2837 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2839 * @tristate: tristate enable
2841 * Tristates the DAI so that others can use it.
2843 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2845 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
2846 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
2850 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
2853 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2855 * @mute: mute enable
2857 * Mutes the DAI DAC.
2859 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
2861 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
2862 return dai
->driver
->ops
->digital_mute(dai
, mute
);
2866 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
2869 * snd_soc_register_card - Register a card with the ASoC core
2871 * @card: Card to register
2874 int snd_soc_register_card(struct snd_soc_card
*card
)
2878 if (!card
->name
|| !card
->dev
)
2881 dev_set_drvdata(card
->dev
, card
);
2883 snd_soc_initialize_card_lists(card
);
2885 soc_init_card_debugfs(card
);
2887 card
->rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
) *
2888 (card
->num_links
+ card
->num_aux_devs
),
2890 if (card
->rtd
== NULL
)
2892 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
2894 for (i
= 0; i
< card
->num_links
; i
++)
2895 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
2897 INIT_LIST_HEAD(&card
->list
);
2898 card
->instantiated
= 0;
2899 mutex_init(&card
->mutex
);
2901 mutex_lock(&client_mutex
);
2902 list_add(&card
->list
, &card_list
);
2903 snd_soc_instantiate_cards();
2904 mutex_unlock(&client_mutex
);
2906 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
2910 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
2913 * snd_soc_unregister_card - Unregister a card with the ASoC core
2915 * @card: Card to unregister
2918 int snd_soc_unregister_card(struct snd_soc_card
*card
)
2920 if (card
->instantiated
)
2921 soc_cleanup_card_resources(card
);
2922 mutex_lock(&client_mutex
);
2923 list_del(&card
->list
);
2924 mutex_unlock(&client_mutex
);
2925 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
2929 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
2932 * Simplify DAI link configuration by removing ".-1" from device names
2933 * and sanitizing names.
2935 static char *fmt_single_name(struct device
*dev
, int *id
)
2937 char *found
, name
[NAME_SIZE
];
2940 if (dev_name(dev
) == NULL
)
2943 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
2945 /* are we a "%s.%d" name (platform and SPI components) */
2946 found
= strstr(name
, dev
->driver
->name
);
2949 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
2951 /* discard ID from name if ID == -1 */
2953 found
[strlen(dev
->driver
->name
)] = '\0';
2957 /* I2C component devices are named "bus-addr" */
2958 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
2959 char tmp
[NAME_SIZE
];
2961 /* create unique ID number from I2C addr and bus */
2962 *id
= ((id1
& 0xffff) << 16) + id2
;
2964 /* sanitize component name for DAI link creation */
2965 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
2966 strlcpy(name
, tmp
, NAME_SIZE
);
2971 return kstrdup(name
, GFP_KERNEL
);
2975 * Simplify DAI link naming for single devices with multiple DAIs by removing
2976 * any ".-1" and using the DAI name (instead of device name).
2978 static inline char *fmt_multiple_name(struct device
*dev
,
2979 struct snd_soc_dai_driver
*dai_drv
)
2981 if (dai_drv
->name
== NULL
) {
2982 printk(KERN_ERR
"asoc: error - multiple DAI %s registered with no name\n",
2987 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
2991 * snd_soc_register_dai - Register a DAI with the ASoC core
2993 * @dai: DAI to register
2995 int snd_soc_register_dai(struct device
*dev
,
2996 struct snd_soc_dai_driver
*dai_drv
)
2998 struct snd_soc_dai
*dai
;
3000 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
3002 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3006 /* create DAI component name */
3007 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3008 if (dai
->name
== NULL
) {
3014 dai
->driver
= dai_drv
;
3015 if (!dai
->driver
->ops
)
3016 dai
->driver
->ops
= &null_dai_ops
;
3018 mutex_lock(&client_mutex
);
3019 list_add(&dai
->list
, &dai_list
);
3020 snd_soc_instantiate_cards();
3021 mutex_unlock(&client_mutex
);
3023 pr_debug("Registered DAI '%s'\n", dai
->name
);
3027 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3030 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3032 * @dai: DAI to unregister
3034 void snd_soc_unregister_dai(struct device
*dev
)
3036 struct snd_soc_dai
*dai
;
3038 list_for_each_entry(dai
, &dai_list
, list
) {
3039 if (dev
== dai
->dev
)
3045 mutex_lock(&client_mutex
);
3046 list_del(&dai
->list
);
3047 mutex_unlock(&client_mutex
);
3049 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3053 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3056 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3058 * @dai: Array of DAIs to register
3059 * @count: Number of DAIs
3061 int snd_soc_register_dais(struct device
*dev
,
3062 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3064 struct snd_soc_dai
*dai
;
3067 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3069 for (i
= 0; i
< count
; i
++) {
3071 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3077 /* create DAI component name */
3078 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3079 if (dai
->name
== NULL
) {
3086 dai
->driver
= &dai_drv
[i
];
3087 if (dai
->driver
->id
)
3088 dai
->id
= dai
->driver
->id
;
3091 if (!dai
->driver
->ops
)
3092 dai
->driver
->ops
= &null_dai_ops
;
3094 mutex_lock(&client_mutex
);
3095 list_add(&dai
->list
, &dai_list
);
3096 mutex_unlock(&client_mutex
);
3098 pr_debug("Registered DAI '%s'\n", dai
->name
);
3101 mutex_lock(&client_mutex
);
3102 snd_soc_instantiate_cards();
3103 mutex_unlock(&client_mutex
);
3107 for (i
--; i
>= 0; i
--)
3108 snd_soc_unregister_dai(dev
);
3112 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3115 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3117 * @dai: Array of DAIs to unregister
3118 * @count: Number of DAIs
3120 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3124 for (i
= 0; i
< count
; i
++)
3125 snd_soc_unregister_dai(dev
);
3127 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3130 * snd_soc_register_platform - Register a platform with the ASoC core
3132 * @platform: platform to register
3134 int snd_soc_register_platform(struct device
*dev
,
3135 struct snd_soc_platform_driver
*platform_drv
)
3137 struct snd_soc_platform
*platform
;
3139 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3141 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3142 if (platform
== NULL
)
3145 /* create platform component name */
3146 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3147 if (platform
->name
== NULL
) {
3152 platform
->dev
= dev
;
3153 platform
->driver
= platform_drv
;
3154 platform
->dapm
.dev
= dev
;
3155 platform
->dapm
.platform
= platform
;
3156 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3158 mutex_lock(&client_mutex
);
3159 list_add(&platform
->list
, &platform_list
);
3160 snd_soc_instantiate_cards();
3161 mutex_unlock(&client_mutex
);
3163 pr_debug("Registered platform '%s'\n", platform
->name
);
3167 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3170 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3172 * @platform: platform to unregister
3174 void snd_soc_unregister_platform(struct device
*dev
)
3176 struct snd_soc_platform
*platform
;
3178 list_for_each_entry(platform
, &platform_list
, list
) {
3179 if (dev
== platform
->dev
)
3185 mutex_lock(&client_mutex
);
3186 list_del(&platform
->list
);
3187 mutex_unlock(&client_mutex
);
3189 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3190 kfree(platform
->name
);
3193 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3195 static u64 codec_format_map
[] = {
3196 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3197 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3198 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3199 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3200 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3201 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3202 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3203 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3204 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3205 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3206 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3207 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3208 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3209 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3210 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3211 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3214 /* Fix up the DAI formats for endianness: codecs don't actually see
3215 * the endianness of the data but we're using the CPU format
3216 * definitions which do need to include endianness so we ensure that
3217 * codec DAIs always have both big and little endian variants set.
3219 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3223 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3224 if (stream
->formats
& codec_format_map
[i
])
3225 stream
->formats
|= codec_format_map
[i
];
3229 * snd_soc_register_codec - Register a codec with the ASoC core
3231 * @codec: codec to register
3233 int snd_soc_register_codec(struct device
*dev
,
3234 const struct snd_soc_codec_driver
*codec_drv
,
3235 struct snd_soc_dai_driver
*dai_drv
,
3239 struct snd_soc_codec
*codec
;
3242 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3244 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3248 /* create CODEC component name */
3249 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3250 if (codec
->name
== NULL
) {
3255 if (codec_drv
->compress_type
)
3256 codec
->compress_type
= codec_drv
->compress_type
;
3258 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3260 codec
->write
= codec_drv
->write
;
3261 codec
->read
= codec_drv
->read
;
3262 codec
->volatile_register
= codec_drv
->volatile_register
;
3263 codec
->readable_register
= codec_drv
->readable_register
;
3264 codec
->writable_register
= codec_drv
->writable_register
;
3265 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3266 codec
->dapm
.dev
= dev
;
3267 codec
->dapm
.codec
= codec
;
3268 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3269 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3271 codec
->driver
= codec_drv
;
3272 codec
->num_dai
= num_dai
;
3273 mutex_init(&codec
->mutex
);
3275 /* allocate CODEC register cache */
3276 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3277 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3278 codec
->reg_size
= reg_size
;
3279 /* it is necessary to make a copy of the default register cache
3280 * because in the case of using a compression type that requires
3281 * the default register cache to be marked as __devinitconst the
3282 * kernel might have freed the array by the time we initialize
3285 if (codec_drv
->reg_cache_default
) {
3286 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3287 reg_size
, GFP_KERNEL
);
3288 if (!codec
->reg_def_copy
) {
3295 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3296 if (!codec
->volatile_register
)
3297 codec
->volatile_register
= snd_soc_default_volatile_register
;
3298 if (!codec
->readable_register
)
3299 codec
->readable_register
= snd_soc_default_readable_register
;
3300 if (!codec
->writable_register
)
3301 codec
->writable_register
= snd_soc_default_writable_register
;
3304 for (i
= 0; i
< num_dai
; i
++) {
3305 fixup_codec_formats(&dai_drv
[i
].playback
);
3306 fixup_codec_formats(&dai_drv
[i
].capture
);
3309 /* register any DAIs */
3311 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3316 mutex_lock(&client_mutex
);
3317 list_add(&codec
->list
, &codec_list
);
3318 snd_soc_instantiate_cards();
3319 mutex_unlock(&client_mutex
);
3321 pr_debug("Registered codec '%s'\n", codec
->name
);
3325 kfree(codec
->reg_def_copy
);
3326 codec
->reg_def_copy
= NULL
;
3331 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3334 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3336 * @codec: codec to unregister
3338 void snd_soc_unregister_codec(struct device
*dev
)
3340 struct snd_soc_codec
*codec
;
3343 list_for_each_entry(codec
, &codec_list
, list
) {
3344 if (dev
== codec
->dev
)
3351 for (i
= 0; i
< codec
->num_dai
; i
++)
3352 snd_soc_unregister_dai(dev
);
3354 mutex_lock(&client_mutex
);
3355 list_del(&codec
->list
);
3356 mutex_unlock(&client_mutex
);
3358 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3360 snd_soc_cache_exit(codec
);
3361 kfree(codec
->reg_def_copy
);
3365 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3367 static int __init
snd_soc_init(void)
3369 #ifdef CONFIG_DEBUG_FS
3370 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3371 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3373 "ASoC: Failed to create debugfs directory\n");
3374 snd_soc_debugfs_root
= NULL
;
3377 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3379 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3381 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3383 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3385 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3386 &platform_list_fops
))
3387 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3390 snd_soc_util_init();
3392 return platform_driver_register(&soc_driver
);
3394 module_init(snd_soc_init
);
3396 static void __exit
snd_soc_exit(void)
3398 snd_soc_util_exit();
3400 #ifdef CONFIG_DEBUG_FS
3401 debugfs_remove_recursive(snd_soc_debugfs_root
);
3403 platform_driver_unregister(&soc_driver
);
3405 module_exit(snd_soc_exit
);
3407 /* Module information */
3408 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3409 MODULE_DESCRIPTION("ALSA SoC Core");
3410 MODULE_LICENSE("GPL");
3411 MODULE_ALIAS("platform:soc-audio");