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/slab.h>
34 #include <sound/ac97_codec.h>
35 #include <sound/core.h>
36 #include <sound/jack.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/soc.h>
40 #include <sound/initval.h>
42 #define CREATE_TRACE_POINTS
43 #include <trace/events/asoc.h>
47 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
49 #ifdef CONFIG_DEBUG_FS
50 struct dentry
*snd_soc_debugfs_root
;
51 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
54 static DEFINE_MUTEX(client_mutex
);
55 static LIST_HEAD(card_list
);
56 static LIST_HEAD(dai_list
);
57 static LIST_HEAD(platform_list
);
58 static LIST_HEAD(codec_list
);
60 int soc_new_pcm(struct snd_soc_pcm_runtime
*rtd
, int num
);
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 (codec
->readable_register
&& !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
=
173 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
175 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
178 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
180 static ssize_t
pmdown_time_show(struct device
*dev
,
181 struct device_attribute
*attr
, char *buf
)
183 struct snd_soc_pcm_runtime
*rtd
=
184 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
186 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
189 static ssize_t
pmdown_time_set(struct device
*dev
,
190 struct device_attribute
*attr
,
191 const char *buf
, size_t count
)
193 struct snd_soc_pcm_runtime
*rtd
=
194 container_of(dev
, struct snd_soc_pcm_runtime
, dev
);
197 ret
= strict_strtol(buf
, 10, &rtd
->pmdown_time
);
204 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
206 #ifdef CONFIG_DEBUG_FS
207 static int codec_reg_open_file(struct inode
*inode
, struct file
*file
)
209 file
->private_data
= inode
->i_private
;
213 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
214 size_t count
, loff_t
*ppos
)
217 struct snd_soc_codec
*codec
= file
->private_data
;
220 if (*ppos
< 0 || !count
)
223 buf
= kmalloc(count
, GFP_KERNEL
);
227 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
229 if (copy_to_user(user_buf
, buf
, ret
)) {
240 static ssize_t
codec_reg_write_file(struct file
*file
,
241 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
246 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 if (codec
->driver
->reg_cache_step
)
256 step
= codec
->driver
->reg_cache_step
;
258 while (*start
== ' ')
260 reg
= simple_strtoul(start
, &start
, 16);
261 while (*start
== ' ')
263 if (strict_strtoul(start
, 16, &value
))
266 /* Userspace has been fiddling around behind the kernel's back */
267 add_taint(TAINT_USER
);
269 snd_soc_write(codec
, reg
, value
);
273 static const struct file_operations codec_reg_fops
= {
274 .open
= codec_reg_open_file
,
275 .read
= codec_reg_read_file
,
276 .write
= codec_reg_write_file
,
277 .llseek
= default_llseek
,
280 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
282 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
284 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
286 if (!codec
->debugfs_codec_root
) {
288 "ASoC: Failed to create codec debugfs directory\n");
292 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
294 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
297 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
298 codec
->debugfs_codec_root
,
299 codec
, &codec_reg_fops
);
300 if (!codec
->debugfs_reg
)
302 "ASoC: Failed to create codec register debugfs file\n");
304 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
307 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
309 debugfs_remove_recursive(codec
->debugfs_codec_root
);
312 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
313 size_t count
, loff_t
*ppos
)
315 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
316 ssize_t len
, ret
= 0;
317 struct snd_soc_codec
*codec
;
322 list_for_each_entry(codec
, &codec_list
, list
) {
323 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
327 if (ret
> PAGE_SIZE
) {
334 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
341 static const struct file_operations codec_list_fops
= {
342 .read
= codec_list_read_file
,
343 .llseek
= default_llseek
,/* read accesses f_pos */
346 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
347 size_t count
, loff_t
*ppos
)
349 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
350 ssize_t len
, ret
= 0;
351 struct snd_soc_dai
*dai
;
356 list_for_each_entry(dai
, &dai_list
, list
) {
357 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
360 if (ret
> PAGE_SIZE
) {
366 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
373 static const struct file_operations dai_list_fops
= {
374 .read
= dai_list_read_file
,
375 .llseek
= default_llseek
,/* read accesses f_pos */
378 static ssize_t
platform_list_read_file(struct file
*file
,
379 char __user
*user_buf
,
380 size_t count
, loff_t
*ppos
)
382 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
383 ssize_t len
, ret
= 0;
384 struct snd_soc_platform
*platform
;
389 list_for_each_entry(platform
, &platform_list
, list
) {
390 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
394 if (ret
> PAGE_SIZE
) {
400 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
407 static const struct file_operations platform_list_fops
= {
408 .read
= platform_list_read_file
,
409 .llseek
= default_llseek
,/* read accesses f_pos */
412 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
414 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
415 snd_soc_debugfs_root
);
416 if (!card
->debugfs_card_root
) {
418 "ASoC: Failed to create codec debugfs directory\n");
422 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
423 card
->debugfs_card_root
,
425 if (!card
->debugfs_pop_time
)
427 "Failed to create pop time debugfs file\n");
430 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
432 debugfs_remove_recursive(card
->debugfs_card_root
);
437 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
441 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
445 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
449 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
454 #ifdef CONFIG_SND_SOC_AC97_BUS
455 /* unregister ac97 codec */
456 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
458 if (codec
->ac97
->dev
.bus
)
459 device_unregister(&codec
->ac97
->dev
);
463 /* stop no dev release warning */
464 static void soc_ac97_device_release(struct device
*dev
){}
466 /* register ac97 codec to bus */
467 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
471 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
472 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
473 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
475 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
476 codec
->card
->snd_card
->number
, 0, codec
->name
);
477 err
= device_register(&codec
->ac97
->dev
);
479 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
480 codec
->ac97
->dev
.bus
= NULL
;
487 #ifdef CONFIG_PM_SLEEP
488 /* powers down audio subsystem for suspend */
489 int snd_soc_suspend(struct device
*dev
)
491 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
492 struct snd_soc_codec
*codec
;
495 /* If the initialization of this soc device failed, there is no codec
496 * associated with it. Just bail out in this case.
498 if (list_empty(&card
->codec_dev_list
))
501 /* Due to the resume being scheduled into a workqueue we could
502 * suspend before that's finished - wait for it to complete.
504 snd_power_lock(card
->snd_card
);
505 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
506 snd_power_unlock(card
->snd_card
);
508 /* we're going to block userspace touching us until resume completes */
509 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
511 /* mute any active DACs */
512 for (i
= 0; i
< card
->num_rtd
; i
++) {
513 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
514 struct snd_soc_dai_driver
*drv
= dai
->driver
;
516 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
519 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
520 drv
->ops
->digital_mute(dai
, 1);
523 /* suspend all pcms */
524 for (i
= 0; i
< card
->num_rtd
; i
++) {
525 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
528 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
531 if (card
->suspend_pre
)
532 card
->suspend_pre(card
);
534 for (i
= 0; i
< card
->num_rtd
; i
++) {
535 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
536 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
538 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
541 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
542 cpu_dai
->driver
->suspend(cpu_dai
);
543 if (platform
->driver
->suspend
&& !platform
->suspended
) {
544 platform
->driver
->suspend(cpu_dai
);
545 platform
->suspended
= 1;
549 /* close any waiting streams and save state */
550 for (i
= 0; i
< card
->num_rtd
; i
++) {
551 flush_delayed_work_sync(&card
->rtd
[i
].delayed_work
);
552 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
555 for (i
= 0; i
< card
->num_rtd
; i
++) {
556 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
558 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
561 if (driver
->playback
.stream_name
!= NULL
)
562 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
563 SND_SOC_DAPM_STREAM_SUSPEND
);
565 if (driver
->capture
.stream_name
!= NULL
)
566 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
567 SND_SOC_DAPM_STREAM_SUSPEND
);
570 /* suspend all CODECs */
571 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
572 /* If there are paths active then the CODEC will be held with
573 * bias _ON and should not be suspended. */
574 if (!codec
->suspended
&& codec
->driver
->suspend
) {
575 switch (codec
->dapm
.bias_level
) {
576 case SND_SOC_BIAS_STANDBY
:
577 case SND_SOC_BIAS_OFF
:
578 codec
->driver
->suspend(codec
, PMSG_SUSPEND
);
579 codec
->suspended
= 1;
580 codec
->cache_sync
= 1;
583 dev_dbg(codec
->dev
, "CODEC is on over suspend\n");
589 for (i
= 0; i
< card
->num_rtd
; i
++) {
590 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
592 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
595 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
596 cpu_dai
->driver
->suspend(cpu_dai
);
599 if (card
->suspend_post
)
600 card
->suspend_post(card
);
604 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
606 /* deferred resume work, so resume can complete before we finished
607 * setting our codec back up, which can be very slow on I2C
609 static void soc_resume_deferred(struct work_struct
*work
)
611 struct snd_soc_card
*card
=
612 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
613 struct snd_soc_codec
*codec
;
616 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
617 * so userspace apps are blocked from touching us
620 dev_dbg(card
->dev
, "starting resume work\n");
622 /* Bring us up into D2 so that DAPM starts enabling things */
623 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
625 if (card
->resume_pre
)
626 card
->resume_pre(card
);
628 /* resume AC97 DAIs */
629 for (i
= 0; i
< card
->num_rtd
; i
++) {
630 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
632 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
635 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
636 cpu_dai
->driver
->resume(cpu_dai
);
639 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
640 /* If the CODEC was idle over suspend then it will have been
641 * left with bias OFF or STANDBY and suspended so we must now
642 * resume. Otherwise the suspend was suppressed.
644 if (codec
->driver
->resume
&& codec
->suspended
) {
645 switch (codec
->dapm
.bias_level
) {
646 case SND_SOC_BIAS_STANDBY
:
647 case SND_SOC_BIAS_OFF
:
648 codec
->driver
->resume(codec
);
649 codec
->suspended
= 0;
652 dev_dbg(codec
->dev
, "CODEC was on over suspend\n");
658 for (i
= 0; i
< card
->num_rtd
; i
++) {
659 struct snd_soc_dai_driver
*driver
= card
->rtd
[i
].codec_dai
->driver
;
661 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
664 if (driver
->playback
.stream_name
!= NULL
)
665 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->playback
.stream_name
,
666 SND_SOC_DAPM_STREAM_RESUME
);
668 if (driver
->capture
.stream_name
!= NULL
)
669 snd_soc_dapm_stream_event(&card
->rtd
[i
], driver
->capture
.stream_name
,
670 SND_SOC_DAPM_STREAM_RESUME
);
673 /* unmute any active DACs */
674 for (i
= 0; i
< card
->num_rtd
; i
++) {
675 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
676 struct snd_soc_dai_driver
*drv
= dai
->driver
;
678 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
681 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
682 drv
->ops
->digital_mute(dai
, 0);
685 for (i
= 0; i
< card
->num_rtd
; i
++) {
686 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
687 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
689 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
692 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
693 cpu_dai
->driver
->resume(cpu_dai
);
694 if (platform
->driver
->resume
&& platform
->suspended
) {
695 platform
->driver
->resume(cpu_dai
);
696 platform
->suspended
= 0;
700 if (card
->resume_post
)
701 card
->resume_post(card
);
703 dev_dbg(card
->dev
, "resume work completed\n");
705 /* userspace can access us now we are back as we were before */
706 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
709 /* powers up audio subsystem after a suspend */
710 int snd_soc_resume(struct device
*dev
)
712 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
713 int i
, ac97_control
= 0;
715 /* AC97 devices might have other drivers hanging off them so
716 * need to resume immediately. Other drivers don't have that
717 * problem and may take a substantial amount of time to resume
718 * due to I/O costs and anti-pop so handle them out of line.
720 for (i
= 0; i
< card
->num_rtd
; i
++) {
721 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
722 ac97_control
|= cpu_dai
->driver
->ac97_control
;
725 dev_dbg(dev
, "Resuming AC97 immediately\n");
726 soc_resume_deferred(&card
->deferred_resume_work
);
728 dev_dbg(dev
, "Scheduling resume work\n");
729 if (!schedule_work(&card
->deferred_resume_work
))
730 dev_err(dev
, "resume work item may be lost\n");
735 EXPORT_SYMBOL_GPL(snd_soc_resume
);
737 #define snd_soc_suspend NULL
738 #define snd_soc_resume NULL
741 static struct snd_soc_dai_ops null_dai_ops
= {
744 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
746 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
747 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
748 struct snd_soc_codec
*codec
;
749 struct snd_soc_platform
*platform
;
750 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
751 const char *platform_name
;
755 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
757 /* do we already have the CPU DAI for this link ? */
761 /* no, then find CPU DAI from registered DAIs*/
762 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
763 if (!strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
)) {
764 rtd
->cpu_dai
= cpu_dai
;
768 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
769 dai_link
->cpu_dai_name
);
772 /* do we already have the CODEC for this link ? */
777 /* no, then find CODEC from registered CODECs*/
778 list_for_each_entry(codec
, &codec_list
, list
) {
779 if (!strcmp(codec
->name
, dai_link
->codec_name
)) {
782 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
783 list_for_each_entry(codec_dai
, &dai_list
, list
) {
784 if (codec
->dev
== codec_dai
->dev
&&
785 !strcmp(codec_dai
->name
, dai_link
->codec_dai_name
)) {
786 rtd
->codec_dai
= codec_dai
;
790 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
791 dai_link
->codec_dai_name
);
796 dev_dbg(card
->dev
, "CODEC %s not registered\n",
797 dai_link
->codec_name
);
800 /* do we need a platform? */
804 /* if there's no platform we match on the empty platform */
805 platform_name
= dai_link
->platform_name
;
807 platform_name
= "snd-soc-dummy";
809 /* no, then find one from the set of registered platforms */
810 list_for_each_entry(platform
, &platform_list
, list
) {
811 if (!strcmp(platform
->name
, platform_name
)) {
812 rtd
->platform
= platform
;
817 dev_dbg(card
->dev
, "platform %s not registered\n",
818 dai_link
->platform_name
);
822 /* mark rtd as complete if we found all 4 of our client devices */
823 if (rtd
->codec
&& rtd
->codec_dai
&& rtd
->platform
&& rtd
->cpu_dai
) {
830 static void soc_remove_codec(struct snd_soc_codec
*codec
)
834 if (codec
->driver
->remove
) {
835 err
= codec
->driver
->remove(codec
);
838 "asoc: failed to remove %s: %d\n",
842 /* Make sure all DAPM widgets are freed */
843 snd_soc_dapm_free(&codec
->dapm
);
845 soc_cleanup_codec_debugfs(codec
);
847 list_del(&codec
->card_list
);
848 module_put(codec
->dev
->driver
->owner
);
851 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
853 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
854 struct snd_soc_codec
*codec
= rtd
->codec
;
855 struct snd_soc_platform
*platform
= rtd
->platform
;
856 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
859 /* unregister the rtd device */
860 if (rtd
->dev_registered
) {
861 device_remove_file(&rtd
->dev
, &dev_attr_pmdown_time
);
862 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
863 device_unregister(&rtd
->dev
);
864 rtd
->dev_registered
= 0;
867 /* remove the CODEC DAI */
868 if (codec_dai
&& codec_dai
->probed
&&
869 codec_dai
->driver
->remove_order
== order
) {
870 if (codec_dai
->driver
->remove
) {
871 err
= codec_dai
->driver
->remove(codec_dai
);
873 printk(KERN_ERR
"asoc: failed to remove %s\n", codec_dai
->name
);
875 codec_dai
->probed
= 0;
876 list_del(&codec_dai
->card_list
);
879 /* remove the platform */
880 if (platform
&& platform
->probed
&&
881 platform
->driver
->remove_order
== order
) {
882 if (platform
->driver
->remove
) {
883 err
= platform
->driver
->remove(platform
);
885 printk(KERN_ERR
"asoc: failed to remove %s\n", platform
->name
);
887 platform
->probed
= 0;
888 list_del(&platform
->card_list
);
889 module_put(platform
->dev
->driver
->owner
);
892 /* remove the CODEC */
893 if (codec
&& codec
->probed
&&
894 codec
->driver
->remove_order
== order
)
895 soc_remove_codec(codec
);
897 /* remove the cpu_dai */
898 if (cpu_dai
&& cpu_dai
->probed
&&
899 cpu_dai
->driver
->remove_order
== order
) {
900 if (cpu_dai
->driver
->remove
) {
901 err
= cpu_dai
->driver
->remove(cpu_dai
);
903 printk(KERN_ERR
"asoc: failed to remove %s\n", cpu_dai
->name
);
906 list_del(&cpu_dai
->card_list
);
907 module_put(cpu_dai
->dev
->driver
->owner
);
911 static void soc_remove_dai_links(struct snd_soc_card
*card
)
915 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
917 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
918 soc_remove_dai_link(card
, dai
, order
);
923 static void soc_set_name_prefix(struct snd_soc_card
*card
,
924 struct snd_soc_codec
*codec
)
928 if (card
->codec_conf
== NULL
)
931 for (i
= 0; i
< card
->num_configs
; i
++) {
932 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
933 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
934 codec
->name_prefix
= map
->name_prefix
;
940 static int soc_probe_codec(struct snd_soc_card
*card
,
941 struct snd_soc_codec
*codec
)
944 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
947 codec
->dapm
.card
= card
;
948 soc_set_name_prefix(card
, codec
);
950 if (!try_module_get(codec
->dev
->driver
->owner
))
953 soc_init_codec_debugfs(codec
);
955 if (driver
->dapm_widgets
)
956 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
957 driver
->num_dapm_widgets
);
959 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
962 ret
= driver
->probe(codec
);
965 "asoc: failed to probe CODEC %s: %d\n",
971 if (driver
->controls
)
972 snd_soc_add_controls(codec
, driver
->controls
,
973 driver
->num_controls
);
974 if (driver
->dapm_routes
)
975 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
976 driver
->num_dapm_routes
);
978 /* mark codec as probed and add to card codec list */
980 list_add(&codec
->card_list
, &card
->codec_dev_list
);
981 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
986 soc_cleanup_codec_debugfs(codec
);
987 module_put(codec
->dev
->driver
->owner
);
992 static int soc_probe_platform(struct snd_soc_card
*card
,
993 struct snd_soc_platform
*platform
)
996 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
998 platform
->card
= card
;
999 platform
->dapm
.card
= card
;
1001 if (!try_module_get(platform
->dev
->driver
->owner
))
1004 if (driver
->dapm_widgets
)
1005 snd_soc_dapm_new_controls(&platform
->dapm
,
1006 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1008 if (driver
->probe
) {
1009 ret
= driver
->probe(platform
);
1011 dev_err(platform
->dev
,
1012 "asoc: failed to probe platform %s: %d\n",
1013 platform
->name
, ret
);
1018 if (driver
->controls
)
1019 snd_soc_add_platform_controls(platform
, driver
->controls
,
1020 driver
->num_controls
);
1021 if (driver
->dapm_routes
)
1022 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1023 driver
->num_dapm_routes
);
1025 /* mark platform as probed and add to card platform list */
1026 platform
->probed
= 1;
1027 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1028 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1033 module_put(platform
->dev
->driver
->owner
);
1038 static void rtd_release(struct device
*dev
) {}
1040 static int soc_post_component_init(struct snd_soc_card
*card
,
1041 struct snd_soc_codec
*codec
,
1042 int num
, int dailess
)
1044 struct snd_soc_dai_link
*dai_link
= NULL
;
1045 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1046 struct snd_soc_pcm_runtime
*rtd
;
1047 const char *temp
, *name
;
1051 dai_link
= &card
->dai_link
[num
];
1052 rtd
= &card
->rtd
[num
];
1053 name
= dai_link
->name
;
1055 aux_dev
= &card
->aux_dev
[num
];
1056 rtd
= &card
->rtd_aux
[num
];
1057 name
= aux_dev
->name
;
1061 /* machine controls, routes and widgets are not prefixed */
1062 temp
= codec
->name_prefix
;
1063 codec
->name_prefix
= NULL
;
1065 /* do machine specific initialization */
1066 if (!dailess
&& dai_link
->init
)
1067 ret
= dai_link
->init(rtd
);
1068 else if (dailess
&& aux_dev
->init
)
1069 ret
= aux_dev
->init(&codec
->dapm
);
1071 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1074 codec
->name_prefix
= temp
;
1076 /* Make sure all DAPM widgets are instantiated */
1077 snd_soc_dapm_new_widgets(&codec
->dapm
);
1079 /* register the rtd device */
1081 rtd
->dev
.parent
= card
->dev
;
1082 rtd
->dev
.release
= rtd_release
;
1083 rtd
->dev
.init_name
= name
;
1084 mutex_init(&rtd
->pcm_mutex
);
1085 ret
= device_register(&rtd
->dev
);
1088 "asoc: failed to register runtime device: %d\n", ret
);
1091 rtd
->dev_registered
= 1;
1093 /* add DAPM sysfs entries for this codec */
1094 ret
= snd_soc_dapm_sys_add(&rtd
->dev
);
1097 "asoc: failed to add codec dapm sysfs entries: %d\n",
1100 /* add codec sysfs entries */
1101 ret
= device_create_file(&rtd
->dev
, &dev_attr_codec_reg
);
1104 "asoc: failed to add codec sysfs files: %d\n", ret
);
1109 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1111 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1112 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1113 struct snd_soc_codec
*codec
= rtd
->codec
;
1114 struct snd_soc_platform
*platform
= rtd
->platform
;
1115 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
1118 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1119 card
->name
, num
, order
);
1121 /* config components */
1122 codec_dai
->codec
= codec
;
1123 cpu_dai
->platform
= platform
;
1124 codec_dai
->card
= card
;
1125 cpu_dai
->card
= card
;
1127 /* set default power off timeout */
1128 rtd
->pmdown_time
= pmdown_time
;
1130 /* probe the cpu_dai */
1131 if (!cpu_dai
->probed
&&
1132 cpu_dai
->driver
->probe_order
== order
) {
1133 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1136 if (cpu_dai
->driver
->probe
) {
1137 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1139 printk(KERN_ERR
"asoc: failed to probe CPU DAI %s\n",
1141 module_put(cpu_dai
->dev
->driver
->owner
);
1145 cpu_dai
->probed
= 1;
1146 /* mark cpu_dai as probed and add to card dai list */
1147 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1150 /* probe the CODEC */
1151 if (!codec
->probed
&&
1152 codec
->driver
->probe_order
== order
) {
1153 ret
= soc_probe_codec(card
, codec
);
1158 /* probe the platform */
1159 if (!platform
->probed
&&
1160 platform
->driver
->probe_order
== order
) {
1161 ret
= soc_probe_platform(card
, platform
);
1166 /* probe the CODEC DAI */
1167 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1168 if (codec_dai
->driver
->probe
) {
1169 ret
= codec_dai
->driver
->probe(codec_dai
);
1171 printk(KERN_ERR
"asoc: failed to probe CODEC DAI %s\n",
1177 /* mark codec_dai as probed and add to card dai list */
1178 codec_dai
->probed
= 1;
1179 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1182 /* complete DAI probe during last probe */
1183 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1186 ret
= soc_post_component_init(card
, codec
, num
, 0);
1190 ret
= device_create_file(&rtd
->dev
, &dev_attr_pmdown_time
);
1192 printk(KERN_WARNING
"asoc: failed to add pmdown_time sysfs\n");
1194 /* create the pcm */
1195 ret
= soc_new_pcm(rtd
, num
);
1197 printk(KERN_ERR
"asoc: can't create pcm %s\n", dai_link
->stream_name
);
1201 /* add platform data for AC97 devices */
1202 if (rtd
->codec_dai
->driver
->ac97_control
)
1203 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1208 #ifdef CONFIG_SND_SOC_AC97_BUS
1209 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1213 /* Only instantiate AC97 if not already done by the adaptor
1214 * for the generic AC97 subsystem.
1216 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1218 * It is possible that the AC97 device is already registered to
1219 * the device subsystem. This happens when the device is created
1220 * via snd_ac97_mixer(). Currently only SoC codec that does so
1221 * is the generic AC97 glue but others migh emerge.
1223 * In those cases we don't try to register the device again.
1225 if (!rtd
->codec
->ac97_created
)
1228 ret
= soc_ac97_dev_register(rtd
->codec
);
1230 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1234 rtd
->codec
->ac97_registered
= 1;
1239 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1241 if (codec
->ac97_registered
) {
1242 soc_ac97_dev_unregister(codec
);
1243 codec
->ac97_registered
= 0;
1248 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1250 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1251 struct snd_soc_codec
*codec
;
1254 /* find CODEC from registered CODECs*/
1255 list_for_each_entry(codec
, &codec_list
, list
) {
1256 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1257 if (codec
->probed
) {
1259 "asoc: codec already probed");
1266 /* codec not found */
1267 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1271 ret
= soc_probe_codec(card
, codec
);
1275 ret
= soc_post_component_init(card
, codec
, num
, 1);
1281 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1283 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1284 struct snd_soc_codec
*codec
= rtd
->codec
;
1286 /* unregister the rtd device */
1287 if (rtd
->dev_registered
) {
1288 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
1289 device_unregister(&rtd
->dev
);
1290 rtd
->dev_registered
= 0;
1293 if (codec
&& codec
->probed
)
1294 soc_remove_codec(codec
);
1297 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1298 enum snd_soc_compress_type compress_type
)
1302 if (codec
->cache_init
)
1305 /* override the compress_type if necessary */
1306 if (compress_type
&& codec
->compress_type
!= compress_type
)
1307 codec
->compress_type
= compress_type
;
1308 ret
= snd_soc_cache_init(codec
);
1310 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1314 codec
->cache_init
= 1;
1318 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
1320 struct snd_soc_codec
*codec
;
1321 struct snd_soc_codec_conf
*codec_conf
;
1322 enum snd_soc_compress_type compress_type
;
1325 mutex_lock(&card
->mutex
);
1327 if (card
->instantiated
) {
1328 mutex_unlock(&card
->mutex
);
1333 for (i
= 0; i
< card
->num_links
; i
++)
1334 soc_bind_dai_link(card
, i
);
1336 /* bind completed ? */
1337 if (card
->num_rtd
!= card
->num_links
) {
1338 mutex_unlock(&card
->mutex
);
1342 /* initialize the register cache for each available codec */
1343 list_for_each_entry(codec
, &codec_list
, list
) {
1344 if (codec
->cache_init
)
1346 /* by default we don't override the compress_type */
1348 /* check to see if we need to override the compress_type */
1349 for (i
= 0; i
< card
->num_configs
; ++i
) {
1350 codec_conf
= &card
->codec_conf
[i
];
1351 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1352 compress_type
= codec_conf
->compress_type
;
1353 if (compress_type
&& compress_type
1354 != codec
->compress_type
)
1358 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1360 mutex_unlock(&card
->mutex
);
1365 /* card bind complete so register a sound card */
1366 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1367 card
->owner
, 0, &card
->snd_card
);
1369 printk(KERN_ERR
"asoc: can't create sound card for card %s\n",
1371 mutex_unlock(&card
->mutex
);
1374 card
->snd_card
->dev
= card
->dev
;
1376 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1377 card
->dapm
.dev
= card
->dev
;
1378 card
->dapm
.card
= card
;
1379 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1381 #ifdef CONFIG_DEBUG_FS
1382 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1385 #ifdef CONFIG_PM_SLEEP
1386 /* deferred resume work */
1387 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1390 if (card
->dapm_widgets
)
1391 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1392 card
->num_dapm_widgets
);
1394 /* initialise the sound card only once */
1396 ret
= card
->probe(card
);
1398 goto card_probe_error
;
1401 /* early DAI link probe */
1402 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1404 for (i
= 0; i
< card
->num_links
; i
++) {
1405 ret
= soc_probe_dai_link(card
, i
, order
);
1407 pr_err("asoc: failed to instantiate card %s: %d\n",
1414 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1415 ret
= soc_probe_aux_dev(card
, i
);
1417 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1419 goto probe_aux_dev_err
;
1423 /* We should have a non-codec control add function but we don't */
1425 snd_soc_add_controls(list_first_entry(&card
->codec_dev_list
,
1426 struct snd_soc_codec
,
1429 card
->num_controls
);
1431 if (card
->dapm_routes
)
1432 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1433 card
->num_dapm_routes
);
1435 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1437 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1438 "%s", card
->long_name
? card
->long_name
: card
->name
);
1439 if (card
->driver_name
)
1440 strlcpy(card
->snd_card
->driver
, card
->driver_name
,
1441 sizeof(card
->snd_card
->driver
));
1443 if (card
->late_probe
) {
1444 ret
= card
->late_probe(card
);
1446 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1448 goto probe_aux_dev_err
;
1452 ret
= snd_card_register(card
->snd_card
);
1454 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n", card
->name
);
1455 goto probe_aux_dev_err
;
1458 #ifdef CONFIG_SND_SOC_AC97_BUS
1459 /* register any AC97 codecs */
1460 for (i
= 0; i
< card
->num_rtd
; i
++) {
1461 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1463 printk(KERN_ERR
"asoc: failed to register AC97 %s\n", card
->name
);
1465 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1466 goto probe_aux_dev_err
;
1471 card
->instantiated
= 1;
1472 mutex_unlock(&card
->mutex
);
1476 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1477 soc_remove_aux_dev(card
, i
);
1480 soc_remove_dai_links(card
);
1486 snd_card_free(card
->snd_card
);
1488 mutex_unlock(&card
->mutex
);
1492 * Attempt to initialise any uninitialised cards. Must be called with
1495 static void snd_soc_instantiate_cards(void)
1497 struct snd_soc_card
*card
;
1498 list_for_each_entry(card
, &card_list
, list
)
1499 snd_soc_instantiate_card(card
);
1502 /* probes a new socdev */
1503 static int soc_probe(struct platform_device
*pdev
)
1505 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1509 * no card, so machine driver should be registering card
1510 * we should not be here in that case so ret error
1515 /* Bodge while we unpick instantiation */
1516 card
->dev
= &pdev
->dev
;
1518 ret
= snd_soc_register_card(card
);
1520 dev_err(&pdev
->dev
, "Failed to register card\n");
1527 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1531 /* make sure any delayed work runs */
1532 for (i
= 0; i
< card
->num_rtd
; i
++) {
1533 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1534 flush_delayed_work_sync(&rtd
->delayed_work
);
1537 /* remove auxiliary devices */
1538 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1539 soc_remove_aux_dev(card
, i
);
1541 /* remove and free each DAI */
1542 soc_remove_dai_links(card
);
1544 soc_cleanup_card_debugfs(card
);
1546 /* remove the card */
1550 snd_soc_dapm_free(&card
->dapm
);
1553 snd_card_free(card
->snd_card
);
1558 /* removes a socdev */
1559 static int soc_remove(struct platform_device
*pdev
)
1561 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1563 snd_soc_unregister_card(card
);
1567 int snd_soc_poweroff(struct device
*dev
)
1569 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1572 if (!card
->instantiated
)
1575 /* Flush out pmdown_time work - we actually do want to run it
1576 * now, we're shutting down so no imminent restart. */
1577 for (i
= 0; i
< card
->num_rtd
; i
++) {
1578 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1579 flush_delayed_work_sync(&rtd
->delayed_work
);
1582 snd_soc_dapm_shutdown(card
);
1586 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1588 const struct dev_pm_ops snd_soc_pm_ops
= {
1589 .suspend
= snd_soc_suspend
,
1590 .resume
= snd_soc_resume
,
1591 .poweroff
= snd_soc_poweroff
,
1593 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1595 /* ASoC platform driver */
1596 static struct platform_driver soc_driver
= {
1598 .name
= "soc-audio",
1599 .owner
= THIS_MODULE
,
1600 .pm
= &snd_soc_pm_ops
,
1603 .remove
= soc_remove
,
1607 * snd_soc_codec_volatile_register: Report if a register is volatile.
1609 * @codec: CODEC to query.
1610 * @reg: Register to query.
1612 * Boolean function indiciating if a CODEC register is volatile.
1614 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1617 if (codec
->volatile_register
)
1618 return codec
->volatile_register(codec
, reg
);
1622 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1625 * snd_soc_codec_readable_register: Report if a register is readable.
1627 * @codec: CODEC to query.
1628 * @reg: Register to query.
1630 * Boolean function indicating if a CODEC register is readable.
1632 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1635 if (codec
->readable_register
)
1636 return codec
->readable_register(codec
, reg
);
1640 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1643 * snd_soc_codec_writable_register: Report if a register is writable.
1645 * @codec: CODEC to query.
1646 * @reg: Register to query.
1648 * Boolean function indicating if a CODEC register is writable.
1650 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1653 if (codec
->writable_register
)
1654 return codec
->writable_register(codec
, reg
);
1658 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1660 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1665 if (!platform
->driver
->read
) {
1666 dev_err(platform
->dev
, "platform has no read back\n");
1670 ret
= platform
->driver
->read(platform
, reg
);
1671 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1672 trace_snd_soc_preg_read(platform
, reg
, ret
);
1676 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1678 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1679 unsigned int reg
, unsigned int val
)
1681 if (!platform
->driver
->write
) {
1682 dev_err(platform
->dev
, "platform has no write back\n");
1686 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1687 trace_snd_soc_preg_write(platform
, reg
, val
);
1688 return platform
->driver
->write(platform
, reg
, val
);
1690 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1693 * snd_soc_new_ac97_codec - initailise AC97 device
1694 * @codec: audio codec
1695 * @ops: AC97 bus operations
1696 * @num: AC97 codec number
1698 * Initialises AC97 codec resources for use by ad-hoc devices only.
1700 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1701 struct snd_ac97_bus_ops
*ops
, int num
)
1703 mutex_lock(&codec
->mutex
);
1705 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1706 if (codec
->ac97
== NULL
) {
1707 mutex_unlock(&codec
->mutex
);
1711 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1712 if (codec
->ac97
->bus
== NULL
) {
1715 mutex_unlock(&codec
->mutex
);
1719 codec
->ac97
->bus
->ops
= ops
;
1720 codec
->ac97
->num
= num
;
1723 * Mark the AC97 device to be created by us. This way we ensure that the
1724 * device will be registered with the device subsystem later on.
1726 codec
->ac97_created
= 1;
1728 mutex_unlock(&codec
->mutex
);
1731 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1734 * snd_soc_free_ac97_codec - free AC97 codec device
1735 * @codec: audio codec
1737 * Frees AC97 codec device resources.
1739 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1741 mutex_lock(&codec
->mutex
);
1742 #ifdef CONFIG_SND_SOC_AC97_BUS
1743 soc_unregister_ac97_dai_link(codec
);
1745 kfree(codec
->ac97
->bus
);
1748 codec
->ac97_created
= 0;
1749 mutex_unlock(&codec
->mutex
);
1751 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1753 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1757 ret
= codec
->read(codec
, reg
);
1758 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1759 trace_snd_soc_reg_read(codec
, reg
, ret
);
1763 EXPORT_SYMBOL_GPL(snd_soc_read
);
1765 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
1766 unsigned int reg
, unsigned int val
)
1768 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
1769 trace_snd_soc_reg_write(codec
, reg
, val
);
1770 return codec
->write(codec
, reg
, val
);
1772 EXPORT_SYMBOL_GPL(snd_soc_write
);
1774 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
1775 unsigned int reg
, const void *data
, size_t len
)
1777 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
1779 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
1782 * snd_soc_update_bits - update codec register bits
1783 * @codec: audio codec
1784 * @reg: codec register
1785 * @mask: register mask
1788 * Writes new register value.
1790 * Returns 1 for change, 0 for no change, or negative error code.
1792 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1793 unsigned int mask
, unsigned int value
)
1796 unsigned int old
, new;
1799 ret
= snd_soc_read(codec
, reg
);
1804 new = (old
& ~mask
) | (value
& mask
);
1805 change
= old
!= new;
1807 ret
= snd_soc_write(codec
, reg
, new);
1814 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1817 * snd_soc_update_bits_locked - update codec register bits
1818 * @codec: audio codec
1819 * @reg: codec register
1820 * @mask: register mask
1823 * Writes new register value, and takes the codec mutex.
1825 * Returns 1 for change else 0.
1827 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
1828 unsigned short reg
, unsigned int mask
,
1833 mutex_lock(&codec
->mutex
);
1834 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
1835 mutex_unlock(&codec
->mutex
);
1839 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
1842 * snd_soc_test_bits - test register for change
1843 * @codec: audio codec
1844 * @reg: codec register
1845 * @mask: register mask
1848 * Tests a register with a new value and checks if the new value is
1849 * different from the old value.
1851 * Returns 1 for change else 0.
1853 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1854 unsigned int mask
, unsigned int value
)
1857 unsigned int old
, new;
1859 old
= snd_soc_read(codec
, reg
);
1860 new = (old
& ~mask
) | value
;
1861 change
= old
!= new;
1865 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1868 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1869 * @substream: the pcm substream
1870 * @hw: the hardware parameters
1872 * Sets the substream runtime hardware parameters.
1874 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1875 const struct snd_pcm_hardware
*hw
)
1877 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1878 runtime
->hw
.info
= hw
->info
;
1879 runtime
->hw
.formats
= hw
->formats
;
1880 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1881 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1882 runtime
->hw
.periods_min
= hw
->periods_min
;
1883 runtime
->hw
.periods_max
= hw
->periods_max
;
1884 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1885 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1888 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1891 * snd_soc_cnew - create new control
1892 * @_template: control template
1893 * @data: control private data
1894 * @long_name: control long name
1895 * @prefix: control name prefix
1897 * Create a new mixer control from a template control.
1899 * Returns 0 for success, else error.
1901 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1902 void *data
, char *long_name
,
1905 struct snd_kcontrol_new
template;
1906 struct snd_kcontrol
*kcontrol
;
1910 memcpy(&template, _template
, sizeof(template));
1914 long_name
= template.name
;
1917 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
1918 name
= kmalloc(name_len
, GFP_KERNEL
);
1922 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
1924 template.name
= name
;
1926 template.name
= long_name
;
1929 kcontrol
= snd_ctl_new1(&template, data
);
1935 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
1938 * snd_soc_add_controls - add an array of controls to a codec.
1939 * Convienience function to add a list of controls. Many codecs were
1940 * duplicating this code.
1942 * @codec: codec to add controls to
1943 * @controls: array of controls to add
1944 * @num_controls: number of elements in the array
1946 * Return 0 for success, else error.
1948 int snd_soc_add_controls(struct snd_soc_codec
*codec
,
1949 const struct snd_kcontrol_new
*controls
, int num_controls
)
1951 struct snd_card
*card
= codec
->card
->snd_card
;
1954 for (i
= 0; i
< num_controls
; i
++) {
1955 const struct snd_kcontrol_new
*control
= &controls
[i
];
1956 err
= snd_ctl_add(card
, snd_soc_cnew(control
, codec
,
1958 codec
->name_prefix
));
1960 dev_err(codec
->dev
, "%s: Failed to add %s: %d\n",
1961 codec
->name
, control
->name
, err
);
1968 EXPORT_SYMBOL_GPL(snd_soc_add_controls
);
1971 * snd_soc_add_platform_controls - add an array of controls to a platform.
1972 * Convienience function to add a list of controls.
1974 * @platform: platform to add controls to
1975 * @controls: array of controls to add
1976 * @num_controls: number of elements in the array
1978 * Return 0 for success, else error.
1980 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
1981 const struct snd_kcontrol_new
*controls
, int num_controls
)
1983 struct snd_card
*card
= platform
->card
->snd_card
;
1986 for (i
= 0; i
< num_controls
; i
++) {
1987 const struct snd_kcontrol_new
*control
= &controls
[i
];
1988 err
= snd_ctl_add(card
, snd_soc_cnew(control
, platform
,
1989 control
->name
, NULL
));
1991 dev_err(platform
->dev
, "Failed to add %s %d\n",control
->name
, err
);
1998 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2001 * snd_soc_info_enum_double - enumerated double mixer info callback
2002 * @kcontrol: mixer control
2003 * @uinfo: control element information
2005 * Callback to provide information about a double enumerated
2008 * Returns 0 for success.
2010 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2011 struct snd_ctl_elem_info
*uinfo
)
2013 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2015 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2016 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2017 uinfo
->value
.enumerated
.items
= e
->max
;
2019 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2020 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2021 strcpy(uinfo
->value
.enumerated
.name
,
2022 e
->texts
[uinfo
->value
.enumerated
.item
]);
2025 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2028 * snd_soc_get_enum_double - enumerated double mixer get callback
2029 * @kcontrol: mixer control
2030 * @ucontrol: control element information
2032 * Callback to get the value of a double enumerated mixer.
2034 * Returns 0 for success.
2036 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2037 struct snd_ctl_elem_value
*ucontrol
)
2039 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2040 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2041 unsigned int val
, bitmask
;
2043 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2045 val
= snd_soc_read(codec
, e
->reg
);
2046 ucontrol
->value
.enumerated
.item
[0]
2047 = (val
>> e
->shift_l
) & (bitmask
- 1);
2048 if (e
->shift_l
!= e
->shift_r
)
2049 ucontrol
->value
.enumerated
.item
[1] =
2050 (val
>> e
->shift_r
) & (bitmask
- 1);
2054 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2057 * snd_soc_put_enum_double - enumerated double mixer put callback
2058 * @kcontrol: mixer control
2059 * @ucontrol: control element information
2061 * Callback to set the value of a double enumerated mixer.
2063 * Returns 0 for success.
2065 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2066 struct snd_ctl_elem_value
*ucontrol
)
2068 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2069 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2071 unsigned int mask
, bitmask
;
2073 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2075 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2077 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2078 mask
= (bitmask
- 1) << e
->shift_l
;
2079 if (e
->shift_l
!= e
->shift_r
) {
2080 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2082 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2083 mask
|= (bitmask
- 1) << e
->shift_r
;
2086 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2088 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2091 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2092 * @kcontrol: mixer control
2093 * @ucontrol: control element information
2095 * Callback to get the value of a double semi enumerated mixer.
2097 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2098 * used for handling bitfield coded enumeration for example.
2100 * Returns 0 for success.
2102 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2103 struct snd_ctl_elem_value
*ucontrol
)
2105 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2106 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2107 unsigned int reg_val
, val
, mux
;
2109 reg_val
= snd_soc_read(codec
, e
->reg
);
2110 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2111 for (mux
= 0; mux
< e
->max
; mux
++) {
2112 if (val
== e
->values
[mux
])
2115 ucontrol
->value
.enumerated
.item
[0] = mux
;
2116 if (e
->shift_l
!= e
->shift_r
) {
2117 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2118 for (mux
= 0; mux
< e
->max
; mux
++) {
2119 if (val
== e
->values
[mux
])
2122 ucontrol
->value
.enumerated
.item
[1] = mux
;
2127 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2130 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2131 * @kcontrol: mixer control
2132 * @ucontrol: control element information
2134 * Callback to set the value of a double semi enumerated mixer.
2136 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2137 * used for handling bitfield coded enumeration for example.
2139 * Returns 0 for success.
2141 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2142 struct snd_ctl_elem_value
*ucontrol
)
2144 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2145 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2149 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2151 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2152 mask
= e
->mask
<< e
->shift_l
;
2153 if (e
->shift_l
!= e
->shift_r
) {
2154 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2156 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2157 mask
|= e
->mask
<< e
->shift_r
;
2160 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2162 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2165 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2166 * @kcontrol: mixer control
2167 * @uinfo: control element information
2169 * Callback to provide information about an external enumerated
2172 * Returns 0 for success.
2174 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2175 struct snd_ctl_elem_info
*uinfo
)
2177 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2179 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2181 uinfo
->value
.enumerated
.items
= e
->max
;
2183 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2184 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2185 strcpy(uinfo
->value
.enumerated
.name
,
2186 e
->texts
[uinfo
->value
.enumerated
.item
]);
2189 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2192 * snd_soc_info_volsw_ext - external single mixer info callback
2193 * @kcontrol: mixer control
2194 * @uinfo: control element information
2196 * Callback to provide information about a single external mixer control.
2198 * Returns 0 for success.
2200 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2201 struct snd_ctl_elem_info
*uinfo
)
2203 int max
= kcontrol
->private_value
;
2205 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2206 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2208 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2211 uinfo
->value
.integer
.min
= 0;
2212 uinfo
->value
.integer
.max
= max
;
2215 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2218 * snd_soc_info_volsw - single mixer info callback
2219 * @kcontrol: mixer control
2220 * @uinfo: control element information
2222 * Callback to provide information about a single mixer control.
2224 * Returns 0 for success.
2226 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2227 struct snd_ctl_elem_info
*uinfo
)
2229 struct soc_mixer_control
*mc
=
2230 (struct soc_mixer_control
*)kcontrol
->private_value
;
2232 unsigned int shift
= mc
->shift
;
2233 unsigned int rshift
= mc
->rshift
;
2235 if (!mc
->platform_max
)
2236 mc
->platform_max
= mc
->max
;
2237 platform_max
= mc
->platform_max
;
2239 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2240 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2242 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2244 uinfo
->count
= shift
== rshift
? 1 : 2;
2245 uinfo
->value
.integer
.min
= 0;
2246 uinfo
->value
.integer
.max
= platform_max
;
2249 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2252 * snd_soc_get_volsw - single mixer get callback
2253 * @kcontrol: mixer control
2254 * @ucontrol: control element information
2256 * Callback to get the value of a single mixer control.
2258 * Returns 0 for success.
2260 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2261 struct snd_ctl_elem_value
*ucontrol
)
2263 struct soc_mixer_control
*mc
=
2264 (struct soc_mixer_control
*)kcontrol
->private_value
;
2265 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2266 unsigned int reg
= mc
->reg
;
2267 unsigned int shift
= mc
->shift
;
2268 unsigned int rshift
= mc
->rshift
;
2270 unsigned int mask
= (1 << fls(max
)) - 1;
2271 unsigned int invert
= mc
->invert
;
2273 ucontrol
->value
.integer
.value
[0] =
2274 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2275 if (shift
!= rshift
)
2276 ucontrol
->value
.integer
.value
[1] =
2277 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2279 ucontrol
->value
.integer
.value
[0] =
2280 max
- ucontrol
->value
.integer
.value
[0];
2281 if (shift
!= rshift
)
2282 ucontrol
->value
.integer
.value
[1] =
2283 max
- ucontrol
->value
.integer
.value
[1];
2288 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2291 * snd_soc_put_volsw - single mixer put callback
2292 * @kcontrol: mixer control
2293 * @ucontrol: control element information
2295 * Callback to set the value of a single mixer control.
2297 * Returns 0 for success.
2299 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2300 struct snd_ctl_elem_value
*ucontrol
)
2302 struct soc_mixer_control
*mc
=
2303 (struct soc_mixer_control
*)kcontrol
->private_value
;
2304 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2305 unsigned int reg
= mc
->reg
;
2306 unsigned int shift
= mc
->shift
;
2307 unsigned int rshift
= mc
->rshift
;
2309 unsigned int mask
= (1 << fls(max
)) - 1;
2310 unsigned int invert
= mc
->invert
;
2311 unsigned int val
, val2
, val_mask
;
2313 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2316 val_mask
= mask
<< shift
;
2318 if (shift
!= rshift
) {
2319 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2322 val_mask
|= mask
<< rshift
;
2323 val
|= val2
<< rshift
;
2325 return snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2327 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2330 * snd_soc_info_volsw_2r - double mixer info callback
2331 * @kcontrol: mixer control
2332 * @uinfo: control element information
2334 * Callback to provide information about a double mixer control that
2335 * spans 2 codec registers.
2337 * Returns 0 for success.
2339 int snd_soc_info_volsw_2r(struct snd_kcontrol
*kcontrol
,
2340 struct snd_ctl_elem_info
*uinfo
)
2342 struct soc_mixer_control
*mc
=
2343 (struct soc_mixer_control
*)kcontrol
->private_value
;
2346 if (!mc
->platform_max
)
2347 mc
->platform_max
= mc
->max
;
2348 platform_max
= mc
->platform_max
;
2350 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2351 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2353 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2356 uinfo
->value
.integer
.min
= 0;
2357 uinfo
->value
.integer
.max
= platform_max
;
2360 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r
);
2363 * snd_soc_get_volsw_2r - double mixer get callback
2364 * @kcontrol: mixer control
2365 * @ucontrol: control element information
2367 * Callback to get the value of a double mixer control that spans 2 registers.
2369 * Returns 0 for success.
2371 int snd_soc_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
2372 struct snd_ctl_elem_value
*ucontrol
)
2374 struct soc_mixer_control
*mc
=
2375 (struct soc_mixer_control
*)kcontrol
->private_value
;
2376 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2377 unsigned int reg
= mc
->reg
;
2378 unsigned int reg2
= mc
->rreg
;
2379 unsigned int shift
= mc
->shift
;
2381 unsigned int mask
= (1 << fls(max
)) - 1;
2382 unsigned int invert
= mc
->invert
;
2384 ucontrol
->value
.integer
.value
[0] =
2385 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2386 ucontrol
->value
.integer
.value
[1] =
2387 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2389 ucontrol
->value
.integer
.value
[0] =
2390 max
- ucontrol
->value
.integer
.value
[0];
2391 ucontrol
->value
.integer
.value
[1] =
2392 max
- ucontrol
->value
.integer
.value
[1];
2397 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r
);
2400 * snd_soc_put_volsw_2r - double mixer set callback
2401 * @kcontrol: mixer control
2402 * @ucontrol: control element information
2404 * Callback to set the value of a double mixer control that spans 2 registers.
2406 * Returns 0 for success.
2408 int snd_soc_put_volsw_2r(struct snd_kcontrol
*kcontrol
,
2409 struct snd_ctl_elem_value
*ucontrol
)
2411 struct soc_mixer_control
*mc
=
2412 (struct soc_mixer_control
*)kcontrol
->private_value
;
2413 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2414 unsigned int reg
= mc
->reg
;
2415 unsigned int reg2
= mc
->rreg
;
2416 unsigned int shift
= mc
->shift
;
2418 unsigned int mask
= (1 << fls(max
)) - 1;
2419 unsigned int invert
= mc
->invert
;
2421 unsigned int val
, val2
, val_mask
;
2423 val_mask
= mask
<< shift
;
2424 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2425 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2433 val2
= val2
<< shift
;
2435 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2439 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2442 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r
);
2445 * snd_soc_info_volsw_s8 - signed mixer info callback
2446 * @kcontrol: mixer control
2447 * @uinfo: control element information
2449 * Callback to provide information about a signed mixer control.
2451 * Returns 0 for success.
2453 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2454 struct snd_ctl_elem_info
*uinfo
)
2456 struct soc_mixer_control
*mc
=
2457 (struct soc_mixer_control
*)kcontrol
->private_value
;
2461 if (!mc
->platform_max
)
2462 mc
->platform_max
= mc
->max
;
2463 platform_max
= mc
->platform_max
;
2465 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2467 uinfo
->value
.integer
.min
= 0;
2468 uinfo
->value
.integer
.max
= platform_max
- min
;
2471 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2474 * snd_soc_get_volsw_s8 - signed mixer get callback
2475 * @kcontrol: mixer control
2476 * @ucontrol: control element information
2478 * Callback to get the value of a signed mixer control.
2480 * Returns 0 for success.
2482 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2483 struct snd_ctl_elem_value
*ucontrol
)
2485 struct soc_mixer_control
*mc
=
2486 (struct soc_mixer_control
*)kcontrol
->private_value
;
2487 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2488 unsigned int reg
= mc
->reg
;
2490 int val
= snd_soc_read(codec
, reg
);
2492 ucontrol
->value
.integer
.value
[0] =
2493 ((signed char)(val
& 0xff))-min
;
2494 ucontrol
->value
.integer
.value
[1] =
2495 ((signed char)((val
>> 8) & 0xff))-min
;
2498 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2501 * snd_soc_put_volsw_sgn - signed mixer put callback
2502 * @kcontrol: mixer control
2503 * @ucontrol: control element information
2505 * Callback to set the value of a signed mixer control.
2507 * Returns 0 for success.
2509 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2510 struct snd_ctl_elem_value
*ucontrol
)
2512 struct soc_mixer_control
*mc
=
2513 (struct soc_mixer_control
*)kcontrol
->private_value
;
2514 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2515 unsigned int reg
= mc
->reg
;
2519 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2520 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2522 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2524 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2527 * snd_soc_limit_volume - Set new limit to an existing volume control.
2529 * @codec: where to look for the control
2530 * @name: Name of the control
2531 * @max: new maximum limit
2533 * Return 0 for success, else error.
2535 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2536 const char *name
, int max
)
2538 struct snd_card
*card
= codec
->card
->snd_card
;
2539 struct snd_kcontrol
*kctl
;
2540 struct soc_mixer_control
*mc
;
2544 /* Sanity check for name and max */
2545 if (unlikely(!name
|| max
<= 0))
2548 list_for_each_entry(kctl
, &card
->controls
, list
) {
2549 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2555 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2556 if (max
<= mc
->max
) {
2557 mc
->platform_max
= max
;
2563 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2566 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2567 * mixer info callback
2568 * @kcontrol: mixer control
2569 * @uinfo: control element information
2571 * Returns 0 for success.
2573 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2574 struct snd_ctl_elem_info
*uinfo
)
2576 struct soc_mixer_control
*mc
=
2577 (struct soc_mixer_control
*)kcontrol
->private_value
;
2581 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2583 uinfo
->value
.integer
.min
= 0;
2584 uinfo
->value
.integer
.max
= max
-min
;
2588 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx
);
2591 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2592 * mixer get callback
2593 * @kcontrol: mixer control
2594 * @uinfo: control element information
2596 * Returns 0 for success.
2598 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2599 struct snd_ctl_elem_value
*ucontrol
)
2601 struct soc_mixer_control
*mc
=
2602 (struct soc_mixer_control
*)kcontrol
->private_value
;
2603 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2604 unsigned int mask
= (1<<mc
->shift
)-1;
2606 int val
= snd_soc_read(codec
, mc
->reg
) & mask
;
2607 int valr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2609 ucontrol
->value
.integer
.value
[0] = ((val
& 0xff)-min
) & mask
;
2610 ucontrol
->value
.integer
.value
[1] = ((valr
& 0xff)-min
) & mask
;
2613 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx
);
2616 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2617 * mixer put callback
2618 * @kcontrol: mixer control
2619 * @uinfo: control element information
2621 * Returns 0 for success.
2623 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2624 struct snd_ctl_elem_value
*ucontrol
)
2626 struct soc_mixer_control
*mc
=
2627 (struct soc_mixer_control
*)kcontrol
->private_value
;
2628 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2629 unsigned int mask
= (1<<mc
->shift
)-1;
2632 unsigned int val
, valr
, oval
, ovalr
;
2634 val
= ((ucontrol
->value
.integer
.value
[0]+min
) & 0xff);
2636 valr
= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff);
2639 oval
= snd_soc_read(codec
, mc
->reg
) & mask
;
2640 ovalr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2644 ret
= snd_soc_write(codec
, mc
->reg
, val
);
2648 if (ovalr
!= valr
) {
2649 ret
= snd_soc_write(codec
, mc
->rreg
, valr
);
2656 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx
);
2659 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2661 * @clk_id: DAI specific clock ID
2662 * @freq: new clock frequency in Hz
2663 * @dir: new clock direction - input/output.
2665 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2667 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2668 unsigned int freq
, int dir
)
2670 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
2671 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
2672 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
2673 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
,
2678 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2681 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2683 * @clk_id: DAI specific clock ID
2684 * @freq: new clock frequency in Hz
2685 * @dir: new clock direction - input/output.
2687 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2689 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
2690 unsigned int freq
, int dir
)
2692 if (codec
->driver
->set_sysclk
)
2693 return codec
->driver
->set_sysclk(codec
, clk_id
, freq
, dir
);
2697 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
2700 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2702 * @div_id: DAI specific clock divider ID
2703 * @div: new clock divisor.
2705 * Configures the clock dividers. This is used to derive the best DAI bit and
2706 * frame clocks from the system or master clock. It's best to set the DAI bit
2707 * and frame clocks as low as possible to save system power.
2709 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2710 int div_id
, int div
)
2712 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
2713 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
2717 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2720 * snd_soc_dai_set_pll - configure DAI PLL.
2722 * @pll_id: DAI specific PLL ID
2723 * @source: DAI specific source for the PLL
2724 * @freq_in: PLL input clock frequency in Hz
2725 * @freq_out: requested PLL output clock frequency in Hz
2727 * Configures and enables PLL to generate output clock based on input clock.
2729 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2730 unsigned int freq_in
, unsigned int freq_out
)
2732 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
2733 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
2735 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
2736 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
2741 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2744 * snd_soc_codec_set_pll - configure codec PLL.
2746 * @pll_id: DAI specific PLL ID
2747 * @source: DAI specific source for the PLL
2748 * @freq_in: PLL input clock frequency in Hz
2749 * @freq_out: requested PLL output clock frequency in Hz
2751 * Configures and enables PLL to generate output clock based on input clock.
2753 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
2754 unsigned int freq_in
, unsigned int freq_out
)
2756 if (codec
->driver
->set_pll
)
2757 return codec
->driver
->set_pll(codec
, pll_id
, source
,
2762 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
2765 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2767 * @fmt: SND_SOC_DAIFMT_ format value.
2769 * Configures the DAI hardware format and clocking.
2771 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2773 if (dai
->driver
&& dai
->driver
->ops
->set_fmt
)
2774 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
2778 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2781 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2783 * @tx_mask: bitmask representing active TX slots.
2784 * @rx_mask: bitmask representing active RX slots.
2785 * @slots: Number of slots in use.
2786 * @slot_width: Width in bits for each slot.
2788 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2791 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2792 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
2794 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
2795 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
2800 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
2803 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2805 * @tx_num: how many TX channels
2806 * @tx_slot: pointer to an array which imply the TX slot number channel
2808 * @rx_num: how many RX channels
2809 * @rx_slot: pointer to an array which imply the RX slot number channel
2812 * configure the relationship between channel number and TDM slot number.
2814 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
2815 unsigned int tx_num
, unsigned int *tx_slot
,
2816 unsigned int rx_num
, unsigned int *rx_slot
)
2818 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
2819 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
2824 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
2827 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2829 * @tristate: tristate enable
2831 * Tristates the DAI so that others can use it.
2833 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2835 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
2836 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
2840 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
2843 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2845 * @mute: mute enable
2847 * Mutes the DAI DAC.
2849 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
2851 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
2852 return dai
->driver
->ops
->digital_mute(dai
, mute
);
2856 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
2859 * snd_soc_register_card - Register a card with the ASoC core
2861 * @card: Card to register
2864 int snd_soc_register_card(struct snd_soc_card
*card
)
2868 if (!card
->name
|| !card
->dev
)
2871 dev_set_drvdata(card
->dev
, card
);
2873 snd_soc_initialize_card_lists(card
);
2875 soc_init_card_debugfs(card
);
2877 card
->rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
) *
2878 (card
->num_links
+ card
->num_aux_devs
),
2880 if (card
->rtd
== NULL
)
2882 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
2884 for (i
= 0; i
< card
->num_links
; i
++)
2885 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
2887 INIT_LIST_HEAD(&card
->list
);
2888 card
->instantiated
= 0;
2889 mutex_init(&card
->mutex
);
2891 mutex_lock(&client_mutex
);
2892 list_add(&card
->list
, &card_list
);
2893 snd_soc_instantiate_cards();
2894 mutex_unlock(&client_mutex
);
2896 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
2900 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
2903 * snd_soc_unregister_card - Unregister a card with the ASoC core
2905 * @card: Card to unregister
2908 int snd_soc_unregister_card(struct snd_soc_card
*card
)
2910 if (card
->instantiated
)
2911 soc_cleanup_card_resources(card
);
2912 mutex_lock(&client_mutex
);
2913 list_del(&card
->list
);
2914 mutex_unlock(&client_mutex
);
2915 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
2919 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
2922 * Simplify DAI link configuration by removing ".-1" from device names
2923 * and sanitizing names.
2925 static char *fmt_single_name(struct device
*dev
, int *id
)
2927 char *found
, name
[NAME_SIZE
];
2930 if (dev_name(dev
) == NULL
)
2933 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
2935 /* are we a "%s.%d" name (platform and SPI components) */
2936 found
= strstr(name
, dev
->driver
->name
);
2939 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
2941 /* discard ID from name if ID == -1 */
2943 found
[strlen(dev
->driver
->name
)] = '\0';
2947 /* I2C component devices are named "bus-addr" */
2948 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
2949 char tmp
[NAME_SIZE
];
2951 /* create unique ID number from I2C addr and bus */
2952 *id
= ((id1
& 0xffff) << 16) + id2
;
2954 /* sanitize component name for DAI link creation */
2955 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
2956 strlcpy(name
, tmp
, NAME_SIZE
);
2961 return kstrdup(name
, GFP_KERNEL
);
2965 * Simplify DAI link naming for single devices with multiple DAIs by removing
2966 * any ".-1" and using the DAI name (instead of device name).
2968 static inline char *fmt_multiple_name(struct device
*dev
,
2969 struct snd_soc_dai_driver
*dai_drv
)
2971 if (dai_drv
->name
== NULL
) {
2972 printk(KERN_ERR
"asoc: error - multiple DAI %s registered with no name\n",
2977 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
2981 * snd_soc_register_dai - Register a DAI with the ASoC core
2983 * @dai: DAI to register
2985 int snd_soc_register_dai(struct device
*dev
,
2986 struct snd_soc_dai_driver
*dai_drv
)
2988 struct snd_soc_dai
*dai
;
2990 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
2992 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
2996 /* create DAI component name */
2997 dai
->name
= fmt_single_name(dev
, &dai
->id
);
2998 if (dai
->name
== NULL
) {
3004 dai
->driver
= dai_drv
;
3005 if (!dai
->driver
->ops
)
3006 dai
->driver
->ops
= &null_dai_ops
;
3008 mutex_lock(&client_mutex
);
3009 list_add(&dai
->list
, &dai_list
);
3010 snd_soc_instantiate_cards();
3011 mutex_unlock(&client_mutex
);
3013 pr_debug("Registered DAI '%s'\n", dai
->name
);
3017 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3020 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3022 * @dai: DAI to unregister
3024 void snd_soc_unregister_dai(struct device
*dev
)
3026 struct snd_soc_dai
*dai
;
3028 list_for_each_entry(dai
, &dai_list
, list
) {
3029 if (dev
== dai
->dev
)
3035 mutex_lock(&client_mutex
);
3036 list_del(&dai
->list
);
3037 mutex_unlock(&client_mutex
);
3039 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3043 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3046 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3048 * @dai: Array of DAIs to register
3049 * @count: Number of DAIs
3051 int snd_soc_register_dais(struct device
*dev
,
3052 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3054 struct snd_soc_dai
*dai
;
3057 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3059 for (i
= 0; i
< count
; i
++) {
3061 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3067 /* create DAI component name */
3068 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3069 if (dai
->name
== NULL
) {
3076 dai
->driver
= &dai_drv
[i
];
3077 if (dai
->driver
->id
)
3078 dai
->id
= dai
->driver
->id
;
3081 if (!dai
->driver
->ops
)
3082 dai
->driver
->ops
= &null_dai_ops
;
3084 mutex_lock(&client_mutex
);
3085 list_add(&dai
->list
, &dai_list
);
3086 mutex_unlock(&client_mutex
);
3088 pr_debug("Registered DAI '%s'\n", dai
->name
);
3091 mutex_lock(&client_mutex
);
3092 snd_soc_instantiate_cards();
3093 mutex_unlock(&client_mutex
);
3097 for (i
--; i
>= 0; i
--)
3098 snd_soc_unregister_dai(dev
);
3102 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3105 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3107 * @dai: Array of DAIs to unregister
3108 * @count: Number of DAIs
3110 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3114 for (i
= 0; i
< count
; i
++)
3115 snd_soc_unregister_dai(dev
);
3117 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3120 * snd_soc_register_platform - Register a platform with the ASoC core
3122 * @platform: platform to register
3124 int snd_soc_register_platform(struct device
*dev
,
3125 struct snd_soc_platform_driver
*platform_drv
)
3127 struct snd_soc_platform
*platform
;
3129 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3131 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3132 if (platform
== NULL
)
3135 /* create platform component name */
3136 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3137 if (platform
->name
== NULL
) {
3142 platform
->dev
= dev
;
3143 platform
->driver
= platform_drv
;
3144 platform
->dapm
.dev
= dev
;
3145 platform
->dapm
.platform
= platform
;
3146 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3148 mutex_lock(&client_mutex
);
3149 list_add(&platform
->list
, &platform_list
);
3150 snd_soc_instantiate_cards();
3151 mutex_unlock(&client_mutex
);
3153 pr_debug("Registered platform '%s'\n", platform
->name
);
3157 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3160 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3162 * @platform: platform to unregister
3164 void snd_soc_unregister_platform(struct device
*dev
)
3166 struct snd_soc_platform
*platform
;
3168 list_for_each_entry(platform
, &platform_list
, list
) {
3169 if (dev
== platform
->dev
)
3175 mutex_lock(&client_mutex
);
3176 list_del(&platform
->list
);
3177 mutex_unlock(&client_mutex
);
3179 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3180 kfree(platform
->name
);
3183 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3185 static u64 codec_format_map
[] = {
3186 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3187 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3188 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3189 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3190 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3191 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3192 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3193 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3194 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3195 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3196 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3197 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3198 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3199 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3200 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3201 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3204 /* Fix up the DAI formats for endianness: codecs don't actually see
3205 * the endianness of the data but we're using the CPU format
3206 * definitions which do need to include endianness so we ensure that
3207 * codec DAIs always have both big and little endian variants set.
3209 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3213 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3214 if (stream
->formats
& codec_format_map
[i
])
3215 stream
->formats
|= codec_format_map
[i
];
3219 * snd_soc_register_codec - Register a codec with the ASoC core
3221 * @codec: codec to register
3223 int snd_soc_register_codec(struct device
*dev
,
3224 const struct snd_soc_codec_driver
*codec_drv
,
3225 struct snd_soc_dai_driver
*dai_drv
,
3229 struct snd_soc_codec
*codec
;
3232 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3234 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3238 /* create CODEC component name */
3239 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3240 if (codec
->name
== NULL
) {
3245 if (codec_drv
->compress_type
)
3246 codec
->compress_type
= codec_drv
->compress_type
;
3248 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3250 codec
->write
= codec_drv
->write
;
3251 codec
->read
= codec_drv
->read
;
3252 codec
->volatile_register
= codec_drv
->volatile_register
;
3253 codec
->readable_register
= codec_drv
->readable_register
;
3254 codec
->writable_register
= codec_drv
->writable_register
;
3255 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3256 codec
->dapm
.dev
= dev
;
3257 codec
->dapm
.codec
= codec
;
3258 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3259 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3261 codec
->driver
= codec_drv
;
3262 codec
->num_dai
= num_dai
;
3263 mutex_init(&codec
->mutex
);
3265 /* allocate CODEC register cache */
3266 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3267 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3268 codec
->reg_size
= reg_size
;
3269 /* it is necessary to make a copy of the default register cache
3270 * because in the case of using a compression type that requires
3271 * the default register cache to be marked as __devinitconst the
3272 * kernel might have freed the array by the time we initialize
3275 if (codec_drv
->reg_cache_default
) {
3276 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3277 reg_size
, GFP_KERNEL
);
3278 if (!codec
->reg_def_copy
) {
3285 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3286 if (!codec
->volatile_register
)
3287 codec
->volatile_register
= snd_soc_default_volatile_register
;
3288 if (!codec
->readable_register
)
3289 codec
->readable_register
= snd_soc_default_readable_register
;
3290 if (!codec
->writable_register
)
3291 codec
->writable_register
= snd_soc_default_writable_register
;
3294 for (i
= 0; i
< num_dai
; i
++) {
3295 fixup_codec_formats(&dai_drv
[i
].playback
);
3296 fixup_codec_formats(&dai_drv
[i
].capture
);
3299 /* register any DAIs */
3301 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3306 mutex_lock(&client_mutex
);
3307 list_add(&codec
->list
, &codec_list
);
3308 snd_soc_instantiate_cards();
3309 mutex_unlock(&client_mutex
);
3311 pr_debug("Registered codec '%s'\n", codec
->name
);
3315 kfree(codec
->reg_def_copy
);
3316 codec
->reg_def_copy
= NULL
;
3321 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3324 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3326 * @codec: codec to unregister
3328 void snd_soc_unregister_codec(struct device
*dev
)
3330 struct snd_soc_codec
*codec
;
3333 list_for_each_entry(codec
, &codec_list
, list
) {
3334 if (dev
== codec
->dev
)
3341 for (i
= 0; i
< codec
->num_dai
; i
++)
3342 snd_soc_unregister_dai(dev
);
3344 mutex_lock(&client_mutex
);
3345 list_del(&codec
->list
);
3346 mutex_unlock(&client_mutex
);
3348 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3350 snd_soc_cache_exit(codec
);
3351 kfree(codec
->reg_def_copy
);
3355 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3357 static int __init
snd_soc_init(void)
3359 #ifdef CONFIG_DEBUG_FS
3360 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3361 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3363 "ASoC: Failed to create debugfs directory\n");
3364 snd_soc_debugfs_root
= NULL
;
3367 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3369 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3371 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3373 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3375 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3376 &platform_list_fops
))
3377 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3380 snd_soc_util_init();
3382 return platform_driver_register(&soc_driver
);
3384 module_init(snd_soc_init
);
3386 static void __exit
snd_soc_exit(void)
3388 snd_soc_util_exit();
3390 #ifdef CONFIG_DEBUG_FS
3391 debugfs_remove_recursive(snd_soc_debugfs_root
);
3393 platform_driver_unregister(&soc_driver
);
3395 module_exit(snd_soc_exit
);
3397 /* Module information */
3398 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3399 MODULE_DESCRIPTION("ALSA SoC Core");
3400 MODULE_LICENSE("GPL");
3401 MODULE_ALIAS("platform:soc-audio");