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 /* If the initialization of this soc device failed, there is no codec
713 * associated with it. Just bail out in this case.
715 if (list_empty(&card
->codec_dev_list
))
718 /* AC97 devices might have other drivers hanging off them so
719 * need to resume immediately. Other drivers don't have that
720 * problem and may take a substantial amount of time to resume
721 * due to I/O costs and anti-pop so handle them out of line.
723 for (i
= 0; i
< card
->num_rtd
; i
++) {
724 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
725 ac97_control
|= cpu_dai
->driver
->ac97_control
;
728 dev_dbg(dev
, "Resuming AC97 immediately\n");
729 soc_resume_deferred(&card
->deferred_resume_work
);
731 dev_dbg(dev
, "Scheduling resume work\n");
732 if (!schedule_work(&card
->deferred_resume_work
))
733 dev_err(dev
, "resume work item may be lost\n");
738 EXPORT_SYMBOL_GPL(snd_soc_resume
);
740 #define snd_soc_suspend NULL
741 #define snd_soc_resume NULL
744 static struct snd_soc_dai_ops null_dai_ops
= {
747 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
749 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
750 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
751 struct snd_soc_codec
*codec
;
752 struct snd_soc_platform
*platform
;
753 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
754 const char *platform_name
;
758 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
760 /* do we already have the CPU DAI for this link ? */
764 /* no, then find CPU DAI from registered DAIs*/
765 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
766 if (!strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
)) {
767 rtd
->cpu_dai
= cpu_dai
;
771 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
772 dai_link
->cpu_dai_name
);
775 /* do we already have the CODEC for this link ? */
780 /* no, then find CODEC from registered CODECs*/
781 list_for_each_entry(codec
, &codec_list
, list
) {
782 if (!strcmp(codec
->name
, dai_link
->codec_name
)) {
785 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
786 list_for_each_entry(codec_dai
, &dai_list
, list
) {
787 if (codec
->dev
== codec_dai
->dev
&&
788 !strcmp(codec_dai
->name
, dai_link
->codec_dai_name
)) {
789 rtd
->codec_dai
= codec_dai
;
793 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
794 dai_link
->codec_dai_name
);
799 dev_dbg(card
->dev
, "CODEC %s not registered\n",
800 dai_link
->codec_name
);
803 /* do we need a platform? */
807 /* if there's no platform we match on the empty platform */
808 platform_name
= dai_link
->platform_name
;
810 platform_name
= "snd-soc-dummy";
812 /* no, then find one from the set of registered platforms */
813 list_for_each_entry(platform
, &platform_list
, list
) {
814 if (!strcmp(platform
->name
, platform_name
)) {
815 rtd
->platform
= platform
;
820 dev_dbg(card
->dev
, "platform %s not registered\n",
821 dai_link
->platform_name
);
825 /* mark rtd as complete if we found all 4 of our client devices */
826 if (rtd
->codec
&& rtd
->codec_dai
&& rtd
->platform
&& rtd
->cpu_dai
) {
833 static void soc_remove_codec(struct snd_soc_codec
*codec
)
837 if (codec
->driver
->remove
) {
838 err
= codec
->driver
->remove(codec
);
841 "asoc: failed to remove %s: %d\n",
845 /* Make sure all DAPM widgets are freed */
846 snd_soc_dapm_free(&codec
->dapm
);
848 soc_cleanup_codec_debugfs(codec
);
850 list_del(&codec
->card_list
);
851 module_put(codec
->dev
->driver
->owner
);
854 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
856 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
857 struct snd_soc_codec
*codec
= rtd
->codec
;
858 struct snd_soc_platform
*platform
= rtd
->platform
;
859 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
862 /* unregister the rtd device */
863 if (rtd
->dev_registered
) {
864 device_remove_file(&rtd
->dev
, &dev_attr_pmdown_time
);
865 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
866 device_unregister(&rtd
->dev
);
867 rtd
->dev_registered
= 0;
870 /* remove the CODEC DAI */
871 if (codec_dai
&& codec_dai
->probed
&&
872 codec_dai
->driver
->remove_order
== order
) {
873 if (codec_dai
->driver
->remove
) {
874 err
= codec_dai
->driver
->remove(codec_dai
);
876 printk(KERN_ERR
"asoc: failed to remove %s\n", codec_dai
->name
);
878 codec_dai
->probed
= 0;
879 list_del(&codec_dai
->card_list
);
882 /* remove the platform */
883 if (platform
&& platform
->probed
&&
884 platform
->driver
->remove_order
== order
) {
885 if (platform
->driver
->remove
) {
886 err
= platform
->driver
->remove(platform
);
888 printk(KERN_ERR
"asoc: failed to remove %s\n", platform
->name
);
890 platform
->probed
= 0;
891 list_del(&platform
->card_list
);
892 module_put(platform
->dev
->driver
->owner
);
895 /* remove the CODEC */
896 if (codec
&& codec
->probed
&&
897 codec
->driver
->remove_order
== order
)
898 soc_remove_codec(codec
);
900 /* remove the cpu_dai */
901 if (cpu_dai
&& cpu_dai
->probed
&&
902 cpu_dai
->driver
->remove_order
== order
) {
903 if (cpu_dai
->driver
->remove
) {
904 err
= cpu_dai
->driver
->remove(cpu_dai
);
906 printk(KERN_ERR
"asoc: failed to remove %s\n", cpu_dai
->name
);
909 list_del(&cpu_dai
->card_list
);
910 module_put(cpu_dai
->dev
->driver
->owner
);
914 static void soc_remove_dai_links(struct snd_soc_card
*card
)
918 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
920 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
921 soc_remove_dai_link(card
, dai
, order
);
926 static void soc_set_name_prefix(struct snd_soc_card
*card
,
927 struct snd_soc_codec
*codec
)
931 if (card
->codec_conf
== NULL
)
934 for (i
= 0; i
< card
->num_configs
; i
++) {
935 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
936 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
937 codec
->name_prefix
= map
->name_prefix
;
943 static int soc_probe_codec(struct snd_soc_card
*card
,
944 struct snd_soc_codec
*codec
)
947 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
950 codec
->dapm
.card
= card
;
951 soc_set_name_prefix(card
, codec
);
953 if (!try_module_get(codec
->dev
->driver
->owner
))
956 soc_init_codec_debugfs(codec
);
958 if (driver
->dapm_widgets
)
959 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
960 driver
->num_dapm_widgets
);
962 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
965 ret
= driver
->probe(codec
);
968 "asoc: failed to probe CODEC %s: %d\n",
974 if (driver
->controls
)
975 snd_soc_add_controls(codec
, driver
->controls
,
976 driver
->num_controls
);
977 if (driver
->dapm_routes
)
978 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
979 driver
->num_dapm_routes
);
981 /* mark codec as probed and add to card codec list */
983 list_add(&codec
->card_list
, &card
->codec_dev_list
);
984 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
989 soc_cleanup_codec_debugfs(codec
);
990 module_put(codec
->dev
->driver
->owner
);
995 static int soc_probe_platform(struct snd_soc_card
*card
,
996 struct snd_soc_platform
*platform
)
999 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1001 platform
->card
= card
;
1002 platform
->dapm
.card
= card
;
1004 if (!try_module_get(platform
->dev
->driver
->owner
))
1007 if (driver
->dapm_widgets
)
1008 snd_soc_dapm_new_controls(&platform
->dapm
,
1009 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1011 if (driver
->probe
) {
1012 ret
= driver
->probe(platform
);
1014 dev_err(platform
->dev
,
1015 "asoc: failed to probe platform %s: %d\n",
1016 platform
->name
, ret
);
1021 if (driver
->controls
)
1022 snd_soc_add_platform_controls(platform
, driver
->controls
,
1023 driver
->num_controls
);
1024 if (driver
->dapm_routes
)
1025 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1026 driver
->num_dapm_routes
);
1028 /* mark platform as probed and add to card platform list */
1029 platform
->probed
= 1;
1030 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1031 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1036 module_put(platform
->dev
->driver
->owner
);
1041 static void rtd_release(struct device
*dev
) {}
1043 static int soc_post_component_init(struct snd_soc_card
*card
,
1044 struct snd_soc_codec
*codec
,
1045 int num
, int dailess
)
1047 struct snd_soc_dai_link
*dai_link
= NULL
;
1048 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1049 struct snd_soc_pcm_runtime
*rtd
;
1050 const char *temp
, *name
;
1054 dai_link
= &card
->dai_link
[num
];
1055 rtd
= &card
->rtd
[num
];
1056 name
= dai_link
->name
;
1058 aux_dev
= &card
->aux_dev
[num
];
1059 rtd
= &card
->rtd_aux
[num
];
1060 name
= aux_dev
->name
;
1064 /* Make sure all DAPM widgets are instantiated */
1065 snd_soc_dapm_new_widgets(&codec
->dapm
);
1067 /* machine controls, routes and widgets are not prefixed */
1068 temp
= codec
->name_prefix
;
1069 codec
->name_prefix
= NULL
;
1071 /* do machine specific initialization */
1072 if (!dailess
&& dai_link
->init
)
1073 ret
= dai_link
->init(rtd
);
1074 else if (dailess
&& aux_dev
->init
)
1075 ret
= aux_dev
->init(&codec
->dapm
);
1077 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1080 codec
->name_prefix
= temp
;
1082 /* register the rtd device */
1084 rtd
->dev
.parent
= card
->dev
;
1085 rtd
->dev
.release
= rtd_release
;
1086 rtd
->dev
.init_name
= name
;
1087 mutex_init(&rtd
->pcm_mutex
);
1088 ret
= device_register(&rtd
->dev
);
1091 "asoc: failed to register runtime device: %d\n", ret
);
1094 rtd
->dev_registered
= 1;
1096 /* add DAPM sysfs entries for this codec */
1097 ret
= snd_soc_dapm_sys_add(&rtd
->dev
);
1100 "asoc: failed to add codec dapm sysfs entries: %d\n",
1103 /* add codec sysfs entries */
1104 ret
= device_create_file(&rtd
->dev
, &dev_attr_codec_reg
);
1107 "asoc: failed to add codec sysfs files: %d\n", ret
);
1112 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1114 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1115 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1116 struct snd_soc_codec
*codec
= rtd
->codec
;
1117 struct snd_soc_platform
*platform
= rtd
->platform
;
1118 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
1121 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1122 card
->name
, num
, order
);
1124 /* config components */
1125 codec_dai
->codec
= codec
;
1126 cpu_dai
->platform
= platform
;
1127 codec_dai
->card
= card
;
1128 cpu_dai
->card
= card
;
1130 /* set default power off timeout */
1131 rtd
->pmdown_time
= pmdown_time
;
1133 /* probe the cpu_dai */
1134 if (!cpu_dai
->probed
&&
1135 cpu_dai
->driver
->probe_order
== order
) {
1136 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1139 if (cpu_dai
->driver
->probe
) {
1140 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1142 printk(KERN_ERR
"asoc: failed to probe CPU DAI %s\n",
1144 module_put(cpu_dai
->dev
->driver
->owner
);
1148 cpu_dai
->probed
= 1;
1149 /* mark cpu_dai as probed and add to card dai list */
1150 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1153 /* probe the CODEC */
1154 if (!codec
->probed
&&
1155 codec
->driver
->probe_order
== order
) {
1156 ret
= soc_probe_codec(card
, codec
);
1161 /* probe the platform */
1162 if (!platform
->probed
&&
1163 platform
->driver
->probe_order
== order
) {
1164 ret
= soc_probe_platform(card
, platform
);
1169 /* probe the CODEC DAI */
1170 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1171 if (codec_dai
->driver
->probe
) {
1172 ret
= codec_dai
->driver
->probe(codec_dai
);
1174 printk(KERN_ERR
"asoc: failed to probe CODEC DAI %s\n",
1180 /* mark codec_dai as probed and add to card dai list */
1181 codec_dai
->probed
= 1;
1182 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1185 /* complete DAI probe during last probe */
1186 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1189 ret
= soc_post_component_init(card
, codec
, num
, 0);
1193 ret
= device_create_file(&rtd
->dev
, &dev_attr_pmdown_time
);
1195 printk(KERN_WARNING
"asoc: failed to add pmdown_time sysfs\n");
1197 /* create the pcm */
1198 ret
= soc_new_pcm(rtd
, num
);
1200 printk(KERN_ERR
"asoc: can't create pcm %s\n", dai_link
->stream_name
);
1204 /* add platform data for AC97 devices */
1205 if (rtd
->codec_dai
->driver
->ac97_control
)
1206 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1211 #ifdef CONFIG_SND_SOC_AC97_BUS
1212 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1216 /* Only instantiate AC97 if not already done by the adaptor
1217 * for the generic AC97 subsystem.
1219 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1221 * It is possible that the AC97 device is already registered to
1222 * the device subsystem. This happens when the device is created
1223 * via snd_ac97_mixer(). Currently only SoC codec that does so
1224 * is the generic AC97 glue but others migh emerge.
1226 * In those cases we don't try to register the device again.
1228 if (!rtd
->codec
->ac97_created
)
1231 ret
= soc_ac97_dev_register(rtd
->codec
);
1233 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1237 rtd
->codec
->ac97_registered
= 1;
1242 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1244 if (codec
->ac97_registered
) {
1245 soc_ac97_dev_unregister(codec
);
1246 codec
->ac97_registered
= 0;
1251 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1253 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1254 struct snd_soc_codec
*codec
;
1257 /* find CODEC from registered CODECs*/
1258 list_for_each_entry(codec
, &codec_list
, list
) {
1259 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1260 if (codec
->probed
) {
1262 "asoc: codec already probed");
1269 /* codec not found */
1270 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1274 ret
= soc_probe_codec(card
, codec
);
1278 ret
= soc_post_component_init(card
, codec
, num
, 1);
1284 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1286 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1287 struct snd_soc_codec
*codec
= rtd
->codec
;
1289 /* unregister the rtd device */
1290 if (rtd
->dev_registered
) {
1291 device_remove_file(&rtd
->dev
, &dev_attr_codec_reg
);
1292 device_unregister(&rtd
->dev
);
1293 rtd
->dev_registered
= 0;
1296 if (codec
&& codec
->probed
)
1297 soc_remove_codec(codec
);
1300 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1301 enum snd_soc_compress_type compress_type
)
1305 if (codec
->cache_init
)
1308 /* override the compress_type if necessary */
1309 if (compress_type
&& codec
->compress_type
!= compress_type
)
1310 codec
->compress_type
= compress_type
;
1311 ret
= snd_soc_cache_init(codec
);
1313 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1317 codec
->cache_init
= 1;
1321 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
1323 struct snd_soc_codec
*codec
;
1324 struct snd_soc_codec_conf
*codec_conf
;
1325 enum snd_soc_compress_type compress_type
;
1326 struct snd_soc_dai_link
*dai_link
;
1329 mutex_lock(&card
->mutex
);
1331 if (card
->instantiated
) {
1332 mutex_unlock(&card
->mutex
);
1337 for (i
= 0; i
< card
->num_links
; i
++)
1338 soc_bind_dai_link(card
, i
);
1340 /* bind completed ? */
1341 if (card
->num_rtd
!= card
->num_links
) {
1342 mutex_unlock(&card
->mutex
);
1346 /* initialize the register cache for each available codec */
1347 list_for_each_entry(codec
, &codec_list
, list
) {
1348 if (codec
->cache_init
)
1350 /* by default we don't override the compress_type */
1352 /* check to see if we need to override the compress_type */
1353 for (i
= 0; i
< card
->num_configs
; ++i
) {
1354 codec_conf
= &card
->codec_conf
[i
];
1355 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1356 compress_type
= codec_conf
->compress_type
;
1357 if (compress_type
&& compress_type
1358 != codec
->compress_type
)
1362 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1364 mutex_unlock(&card
->mutex
);
1369 /* card bind complete so register a sound card */
1370 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1371 card
->owner
, 0, &card
->snd_card
);
1373 printk(KERN_ERR
"asoc: can't create sound card for card %s\n",
1375 mutex_unlock(&card
->mutex
);
1378 card
->snd_card
->dev
= card
->dev
;
1380 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1381 card
->dapm
.dev
= card
->dev
;
1382 card
->dapm
.card
= card
;
1383 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1385 #ifdef CONFIG_DEBUG_FS
1386 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1389 #ifdef CONFIG_PM_SLEEP
1390 /* deferred resume work */
1391 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1394 if (card
->dapm_widgets
)
1395 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1396 card
->num_dapm_widgets
);
1398 /* initialise the sound card only once */
1400 ret
= card
->probe(card
);
1402 goto card_probe_error
;
1405 /* early DAI link probe */
1406 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1408 for (i
= 0; i
< card
->num_links
; i
++) {
1409 ret
= soc_probe_dai_link(card
, i
, order
);
1411 pr_err("asoc: failed to instantiate card %s: %d\n",
1418 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1419 ret
= soc_probe_aux_dev(card
, i
);
1421 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1423 goto probe_aux_dev_err
;
1427 /* We should have a non-codec control add function but we don't */
1429 snd_soc_add_controls(list_first_entry(&card
->codec_dev_list
,
1430 struct snd_soc_codec
,
1433 card
->num_controls
);
1435 if (card
->dapm_routes
)
1436 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1437 card
->num_dapm_routes
);
1439 snd_soc_dapm_new_widgets(&card
->dapm
);
1441 for (i
= 0; i
< card
->num_links
; i
++) {
1442 dai_link
= &card
->dai_link
[i
];
1444 if (dai_link
->dai_fmt
) {
1445 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1448 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1449 "Failed to set DAI format: %d\n",
1452 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1455 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1456 "Failed to set DAI format: %d\n",
1461 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1463 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1464 "%s", card
->long_name
? card
->long_name
: card
->name
);
1465 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1466 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1467 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1468 switch (card
->snd_card
->driver
[i
]) {
1474 if (!isalnum(card
->snd_card
->driver
[i
]))
1475 card
->snd_card
->driver
[i
] = '_';
1480 if (card
->late_probe
) {
1481 ret
= card
->late_probe(card
);
1483 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1485 goto probe_aux_dev_err
;
1489 snd_soc_dapm_new_widgets(&card
->dapm
);
1491 ret
= snd_card_register(card
->snd_card
);
1493 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n", card
->name
);
1494 goto probe_aux_dev_err
;
1497 #ifdef CONFIG_SND_SOC_AC97_BUS
1498 /* register any AC97 codecs */
1499 for (i
= 0; i
< card
->num_rtd
; i
++) {
1500 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1502 printk(KERN_ERR
"asoc: failed to register AC97 %s\n", card
->name
);
1504 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1505 goto probe_aux_dev_err
;
1510 card
->instantiated
= 1;
1511 snd_soc_dapm_sync(&card
->dapm
);
1512 mutex_unlock(&card
->mutex
);
1516 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1517 soc_remove_aux_dev(card
, i
);
1520 soc_remove_dai_links(card
);
1526 snd_card_free(card
->snd_card
);
1528 mutex_unlock(&card
->mutex
);
1532 * Attempt to initialise any uninitialised cards. Must be called with
1535 static void snd_soc_instantiate_cards(void)
1537 struct snd_soc_card
*card
;
1538 list_for_each_entry(card
, &card_list
, list
)
1539 snd_soc_instantiate_card(card
);
1542 /* probes a new socdev */
1543 static int soc_probe(struct platform_device
*pdev
)
1545 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1549 * no card, so machine driver should be registering card
1550 * we should not be here in that case so ret error
1555 /* Bodge while we unpick instantiation */
1556 card
->dev
= &pdev
->dev
;
1558 ret
= snd_soc_register_card(card
);
1560 dev_err(&pdev
->dev
, "Failed to register card\n");
1567 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1571 /* make sure any delayed work runs */
1572 for (i
= 0; i
< card
->num_rtd
; i
++) {
1573 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1574 flush_delayed_work_sync(&rtd
->delayed_work
);
1577 /* remove auxiliary devices */
1578 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1579 soc_remove_aux_dev(card
, i
);
1581 /* remove and free each DAI */
1582 soc_remove_dai_links(card
);
1584 soc_cleanup_card_debugfs(card
);
1586 /* remove the card */
1590 snd_soc_dapm_free(&card
->dapm
);
1593 snd_card_free(card
->snd_card
);
1598 /* removes a socdev */
1599 static int soc_remove(struct platform_device
*pdev
)
1601 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1603 snd_soc_unregister_card(card
);
1607 int snd_soc_poweroff(struct device
*dev
)
1609 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1612 if (!card
->instantiated
)
1615 /* Flush out pmdown_time work - we actually do want to run it
1616 * now, we're shutting down so no imminent restart. */
1617 for (i
= 0; i
< card
->num_rtd
; i
++) {
1618 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1619 flush_delayed_work_sync(&rtd
->delayed_work
);
1622 snd_soc_dapm_shutdown(card
);
1626 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1628 const struct dev_pm_ops snd_soc_pm_ops
= {
1629 .suspend
= snd_soc_suspend
,
1630 .resume
= snd_soc_resume
,
1631 .poweroff
= snd_soc_poweroff
,
1633 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1635 /* ASoC platform driver */
1636 static struct platform_driver soc_driver
= {
1638 .name
= "soc-audio",
1639 .owner
= THIS_MODULE
,
1640 .pm
= &snd_soc_pm_ops
,
1643 .remove
= soc_remove
,
1647 * snd_soc_codec_volatile_register: Report if a register is volatile.
1649 * @codec: CODEC to query.
1650 * @reg: Register to query.
1652 * Boolean function indiciating if a CODEC register is volatile.
1654 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1657 if (codec
->volatile_register
)
1658 return codec
->volatile_register(codec
, reg
);
1662 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1665 * snd_soc_codec_readable_register: Report if a register is readable.
1667 * @codec: CODEC to query.
1668 * @reg: Register to query.
1670 * Boolean function indicating if a CODEC register is readable.
1672 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1675 if (codec
->readable_register
)
1676 return codec
->readable_register(codec
, reg
);
1680 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1683 * snd_soc_codec_writable_register: Report if a register is writable.
1685 * @codec: CODEC to query.
1686 * @reg: Register to query.
1688 * Boolean function indicating if a CODEC register is writable.
1690 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1693 if (codec
->writable_register
)
1694 return codec
->writable_register(codec
, reg
);
1698 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1700 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1705 if (!platform
->driver
->read
) {
1706 dev_err(platform
->dev
, "platform has no read back\n");
1710 ret
= platform
->driver
->read(platform
, reg
);
1711 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1712 trace_snd_soc_preg_read(platform
, reg
, ret
);
1716 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1718 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1719 unsigned int reg
, unsigned int val
)
1721 if (!platform
->driver
->write
) {
1722 dev_err(platform
->dev
, "platform has no write back\n");
1726 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1727 trace_snd_soc_preg_write(platform
, reg
, val
);
1728 return platform
->driver
->write(platform
, reg
, val
);
1730 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1733 * snd_soc_new_ac97_codec - initailise AC97 device
1734 * @codec: audio codec
1735 * @ops: AC97 bus operations
1736 * @num: AC97 codec number
1738 * Initialises AC97 codec resources for use by ad-hoc devices only.
1740 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1741 struct snd_ac97_bus_ops
*ops
, int num
)
1743 mutex_lock(&codec
->mutex
);
1745 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1746 if (codec
->ac97
== NULL
) {
1747 mutex_unlock(&codec
->mutex
);
1751 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1752 if (codec
->ac97
->bus
== NULL
) {
1755 mutex_unlock(&codec
->mutex
);
1759 codec
->ac97
->bus
->ops
= ops
;
1760 codec
->ac97
->num
= num
;
1763 * Mark the AC97 device to be created by us. This way we ensure that the
1764 * device will be registered with the device subsystem later on.
1766 codec
->ac97_created
= 1;
1768 mutex_unlock(&codec
->mutex
);
1771 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1774 * snd_soc_free_ac97_codec - free AC97 codec device
1775 * @codec: audio codec
1777 * Frees AC97 codec device resources.
1779 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1781 mutex_lock(&codec
->mutex
);
1782 #ifdef CONFIG_SND_SOC_AC97_BUS
1783 soc_unregister_ac97_dai_link(codec
);
1785 kfree(codec
->ac97
->bus
);
1788 codec
->ac97_created
= 0;
1789 mutex_unlock(&codec
->mutex
);
1791 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1793 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1797 ret
= codec
->read(codec
, reg
);
1798 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1799 trace_snd_soc_reg_read(codec
, reg
, ret
);
1803 EXPORT_SYMBOL_GPL(snd_soc_read
);
1805 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
1806 unsigned int reg
, unsigned int val
)
1808 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
1809 trace_snd_soc_reg_write(codec
, reg
, val
);
1810 return codec
->write(codec
, reg
, val
);
1812 EXPORT_SYMBOL_GPL(snd_soc_write
);
1814 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
1815 unsigned int reg
, const void *data
, size_t len
)
1817 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
1819 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
1822 * snd_soc_update_bits - update codec register bits
1823 * @codec: audio codec
1824 * @reg: codec register
1825 * @mask: register mask
1828 * Writes new register value.
1830 * Returns 1 for change, 0 for no change, or negative error code.
1832 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1833 unsigned int mask
, unsigned int value
)
1836 unsigned int old
, new;
1839 ret
= snd_soc_read(codec
, reg
);
1844 new = (old
& ~mask
) | (value
& mask
);
1845 change
= old
!= new;
1847 ret
= snd_soc_write(codec
, reg
, new);
1854 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1857 * snd_soc_update_bits_locked - update codec register bits
1858 * @codec: audio codec
1859 * @reg: codec register
1860 * @mask: register mask
1863 * Writes new register value, and takes the codec mutex.
1865 * Returns 1 for change else 0.
1867 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
1868 unsigned short reg
, unsigned int mask
,
1873 mutex_lock(&codec
->mutex
);
1874 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
1875 mutex_unlock(&codec
->mutex
);
1879 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
1882 * snd_soc_test_bits - test register for change
1883 * @codec: audio codec
1884 * @reg: codec register
1885 * @mask: register mask
1888 * Tests a register with a new value and checks if the new value is
1889 * different from the old value.
1891 * Returns 1 for change else 0.
1893 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1894 unsigned int mask
, unsigned int value
)
1897 unsigned int old
, new;
1899 old
= snd_soc_read(codec
, reg
);
1900 new = (old
& ~mask
) | value
;
1901 change
= old
!= new;
1905 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1908 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1909 * @substream: the pcm substream
1910 * @hw: the hardware parameters
1912 * Sets the substream runtime hardware parameters.
1914 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1915 const struct snd_pcm_hardware
*hw
)
1917 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1918 runtime
->hw
.info
= hw
->info
;
1919 runtime
->hw
.formats
= hw
->formats
;
1920 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1921 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1922 runtime
->hw
.periods_min
= hw
->periods_min
;
1923 runtime
->hw
.periods_max
= hw
->periods_max
;
1924 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1925 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1928 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1931 * snd_soc_cnew - create new control
1932 * @_template: control template
1933 * @data: control private data
1934 * @long_name: control long name
1935 * @prefix: control name prefix
1937 * Create a new mixer control from a template control.
1939 * Returns 0 for success, else error.
1941 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1942 void *data
, char *long_name
,
1945 struct snd_kcontrol_new
template;
1946 struct snd_kcontrol
*kcontrol
;
1950 memcpy(&template, _template
, sizeof(template));
1954 long_name
= template.name
;
1957 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
1958 name
= kmalloc(name_len
, GFP_KERNEL
);
1962 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
1964 template.name
= name
;
1966 template.name
= long_name
;
1969 kcontrol
= snd_ctl_new1(&template, data
);
1975 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
1978 * snd_soc_add_controls - add an array of controls to a codec.
1979 * Convienience function to add a list of controls. Many codecs were
1980 * duplicating this code.
1982 * @codec: codec 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_controls(struct snd_soc_codec
*codec
,
1989 const struct snd_kcontrol_new
*controls
, int num_controls
)
1991 struct snd_card
*card
= codec
->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
, codec
,
1998 codec
->name_prefix
));
2000 dev_err(codec
->dev
, "%s: Failed to add %s: %d\n",
2001 codec
->name
, control
->name
, err
);
2008 EXPORT_SYMBOL_GPL(snd_soc_add_controls
);
2011 * snd_soc_add_platform_controls - add an array of controls to a platform.
2012 * Convienience function to add a list of controls.
2014 * @platform: platform to add controls to
2015 * @controls: array of controls to add
2016 * @num_controls: number of elements in the array
2018 * Return 0 for success, else error.
2020 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2021 const struct snd_kcontrol_new
*controls
, int num_controls
)
2023 struct snd_card
*card
= platform
->card
->snd_card
;
2026 for (i
= 0; i
< num_controls
; i
++) {
2027 const struct snd_kcontrol_new
*control
= &controls
[i
];
2028 err
= snd_ctl_add(card
, snd_soc_cnew(control
, platform
,
2029 control
->name
, NULL
));
2031 dev_err(platform
->dev
, "Failed to add %s %d\n",control
->name
, err
);
2038 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2041 * snd_soc_info_enum_double - enumerated double mixer info callback
2042 * @kcontrol: mixer control
2043 * @uinfo: control element information
2045 * Callback to provide information about a double enumerated
2048 * Returns 0 for success.
2050 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2051 struct snd_ctl_elem_info
*uinfo
)
2053 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2055 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2056 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2057 uinfo
->value
.enumerated
.items
= e
->max
;
2059 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2060 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2061 strcpy(uinfo
->value
.enumerated
.name
,
2062 e
->texts
[uinfo
->value
.enumerated
.item
]);
2065 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2068 * snd_soc_get_enum_double - enumerated double mixer get callback
2069 * @kcontrol: mixer control
2070 * @ucontrol: control element information
2072 * Callback to get the value of a double enumerated mixer.
2074 * Returns 0 for success.
2076 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2077 struct snd_ctl_elem_value
*ucontrol
)
2079 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2080 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2081 unsigned int val
, bitmask
;
2083 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2085 val
= snd_soc_read(codec
, e
->reg
);
2086 ucontrol
->value
.enumerated
.item
[0]
2087 = (val
>> e
->shift_l
) & (bitmask
- 1);
2088 if (e
->shift_l
!= e
->shift_r
)
2089 ucontrol
->value
.enumerated
.item
[1] =
2090 (val
>> e
->shift_r
) & (bitmask
- 1);
2094 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2097 * snd_soc_put_enum_double - enumerated double mixer put callback
2098 * @kcontrol: mixer control
2099 * @ucontrol: control element information
2101 * Callback to set the value of a double enumerated mixer.
2103 * Returns 0 for success.
2105 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2106 struct snd_ctl_elem_value
*ucontrol
)
2108 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2109 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2111 unsigned int mask
, bitmask
;
2113 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2115 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2117 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2118 mask
= (bitmask
- 1) << e
->shift_l
;
2119 if (e
->shift_l
!= e
->shift_r
) {
2120 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2122 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2123 mask
|= (bitmask
- 1) << e
->shift_r
;
2126 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2128 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2131 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2132 * @kcontrol: mixer control
2133 * @ucontrol: control element information
2135 * Callback to get the value of a double semi enumerated mixer.
2137 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2138 * used for handling bitfield coded enumeration for example.
2140 * Returns 0 for success.
2142 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2143 struct snd_ctl_elem_value
*ucontrol
)
2145 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2146 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2147 unsigned int reg_val
, val
, mux
;
2149 reg_val
= snd_soc_read(codec
, e
->reg
);
2150 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2151 for (mux
= 0; mux
< e
->max
; mux
++) {
2152 if (val
== e
->values
[mux
])
2155 ucontrol
->value
.enumerated
.item
[0] = mux
;
2156 if (e
->shift_l
!= e
->shift_r
) {
2157 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2158 for (mux
= 0; mux
< e
->max
; mux
++) {
2159 if (val
== e
->values
[mux
])
2162 ucontrol
->value
.enumerated
.item
[1] = mux
;
2167 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2170 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2171 * @kcontrol: mixer control
2172 * @ucontrol: control element information
2174 * Callback to set the value of a double semi enumerated mixer.
2176 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2177 * used for handling bitfield coded enumeration for example.
2179 * Returns 0 for success.
2181 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2182 struct snd_ctl_elem_value
*ucontrol
)
2184 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2185 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2189 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2191 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2192 mask
= e
->mask
<< e
->shift_l
;
2193 if (e
->shift_l
!= e
->shift_r
) {
2194 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2196 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2197 mask
|= e
->mask
<< e
->shift_r
;
2200 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2202 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2205 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2206 * @kcontrol: mixer control
2207 * @uinfo: control element information
2209 * Callback to provide information about an external enumerated
2212 * Returns 0 for success.
2214 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2215 struct snd_ctl_elem_info
*uinfo
)
2217 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2219 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2221 uinfo
->value
.enumerated
.items
= e
->max
;
2223 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2224 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2225 strcpy(uinfo
->value
.enumerated
.name
,
2226 e
->texts
[uinfo
->value
.enumerated
.item
]);
2229 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2232 * snd_soc_info_volsw_ext - external single mixer info callback
2233 * @kcontrol: mixer control
2234 * @uinfo: control element information
2236 * Callback to provide information about a single external mixer control.
2238 * Returns 0 for success.
2240 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2241 struct snd_ctl_elem_info
*uinfo
)
2243 int max
= kcontrol
->private_value
;
2245 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2246 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2248 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2251 uinfo
->value
.integer
.min
= 0;
2252 uinfo
->value
.integer
.max
= max
;
2255 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2258 * snd_soc_info_volsw - single mixer info callback
2259 * @kcontrol: mixer control
2260 * @uinfo: control element information
2262 * Callback to provide information about a single mixer control, or a double
2263 * mixer control that spans 2 registers.
2265 * Returns 0 for success.
2267 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2268 struct snd_ctl_elem_info
*uinfo
)
2270 struct soc_mixer_control
*mc
=
2271 (struct soc_mixer_control
*)kcontrol
->private_value
;
2274 if (!mc
->platform_max
)
2275 mc
->platform_max
= mc
->max
;
2276 platform_max
= mc
->platform_max
;
2278 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2279 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2281 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2283 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2284 uinfo
->value
.integer
.min
= 0;
2285 uinfo
->value
.integer
.max
= platform_max
;
2288 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2291 * snd_soc_get_volsw - single mixer get callback
2292 * @kcontrol: mixer control
2293 * @ucontrol: control element information
2295 * Callback to get the value of a single mixer control, or a double mixer
2296 * control that spans 2 registers.
2298 * Returns 0 for success.
2300 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2301 struct snd_ctl_elem_value
*ucontrol
)
2303 struct soc_mixer_control
*mc
=
2304 (struct soc_mixer_control
*)kcontrol
->private_value
;
2305 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2306 unsigned int reg
= mc
->reg
;
2307 unsigned int reg2
= mc
->rreg
;
2308 unsigned int shift
= mc
->shift
;
2309 unsigned int rshift
= mc
->rshift
;
2311 unsigned int mask
= (1 << fls(max
)) - 1;
2312 unsigned int invert
= mc
->invert
;
2314 ucontrol
->value
.integer
.value
[0] =
2315 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2317 ucontrol
->value
.integer
.value
[0] =
2318 max
- ucontrol
->value
.integer
.value
[0];
2320 if (snd_soc_volsw_is_stereo(mc
)) {
2322 ucontrol
->value
.integer
.value
[1] =
2323 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2325 ucontrol
->value
.integer
.value
[1] =
2326 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2328 ucontrol
->value
.integer
.value
[1] =
2329 max
- ucontrol
->value
.integer
.value
[1];
2334 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2337 * snd_soc_put_volsw - single mixer put callback
2338 * @kcontrol: mixer control
2339 * @ucontrol: control element information
2341 * Callback to set the value of a single mixer control, or a double mixer
2342 * control that spans 2 registers.
2344 * Returns 0 for success.
2346 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2347 struct snd_ctl_elem_value
*ucontrol
)
2349 struct soc_mixer_control
*mc
=
2350 (struct soc_mixer_control
*)kcontrol
->private_value
;
2351 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2352 unsigned int reg
= mc
->reg
;
2353 unsigned int reg2
= mc
->rreg
;
2354 unsigned int shift
= mc
->shift
;
2355 unsigned int rshift
= mc
->rshift
;
2357 unsigned int mask
= (1 << fls(max
)) - 1;
2358 unsigned int invert
= mc
->invert
;
2361 unsigned int val2
= 0;
2362 unsigned int val
, val_mask
;
2364 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2367 val_mask
= mask
<< shift
;
2369 if (snd_soc_volsw_is_stereo(mc
)) {
2370 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2374 val_mask
|= mask
<< rshift
;
2375 val
|= val2
<< rshift
;
2377 val2
= val2
<< shift
;
2381 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2386 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2390 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2393 * snd_soc_info_volsw_s8 - signed mixer info callback
2394 * @kcontrol: mixer control
2395 * @uinfo: control element information
2397 * Callback to provide information about a signed mixer control.
2399 * Returns 0 for success.
2401 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2402 struct snd_ctl_elem_info
*uinfo
)
2404 struct soc_mixer_control
*mc
=
2405 (struct soc_mixer_control
*)kcontrol
->private_value
;
2409 if (!mc
->platform_max
)
2410 mc
->platform_max
= mc
->max
;
2411 platform_max
= mc
->platform_max
;
2413 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2415 uinfo
->value
.integer
.min
= 0;
2416 uinfo
->value
.integer
.max
= platform_max
- min
;
2419 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2422 * snd_soc_get_volsw_s8 - signed mixer get callback
2423 * @kcontrol: mixer control
2424 * @ucontrol: control element information
2426 * Callback to get the value of a signed mixer control.
2428 * Returns 0 for success.
2430 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2431 struct snd_ctl_elem_value
*ucontrol
)
2433 struct soc_mixer_control
*mc
=
2434 (struct soc_mixer_control
*)kcontrol
->private_value
;
2435 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2436 unsigned int reg
= mc
->reg
;
2438 int val
= snd_soc_read(codec
, reg
);
2440 ucontrol
->value
.integer
.value
[0] =
2441 ((signed char)(val
& 0xff))-min
;
2442 ucontrol
->value
.integer
.value
[1] =
2443 ((signed char)((val
>> 8) & 0xff))-min
;
2446 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2449 * snd_soc_put_volsw_sgn - signed mixer put callback
2450 * @kcontrol: mixer control
2451 * @ucontrol: control element information
2453 * Callback to set the value of a signed mixer control.
2455 * Returns 0 for success.
2457 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2458 struct snd_ctl_elem_value
*ucontrol
)
2460 struct soc_mixer_control
*mc
=
2461 (struct soc_mixer_control
*)kcontrol
->private_value
;
2462 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2463 unsigned int reg
= mc
->reg
;
2467 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2468 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2470 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2472 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2475 * snd_soc_limit_volume - Set new limit to an existing volume control.
2477 * @codec: where to look for the control
2478 * @name: Name of the control
2479 * @max: new maximum limit
2481 * Return 0 for success, else error.
2483 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2484 const char *name
, int max
)
2486 struct snd_card
*card
= codec
->card
->snd_card
;
2487 struct snd_kcontrol
*kctl
;
2488 struct soc_mixer_control
*mc
;
2492 /* Sanity check for name and max */
2493 if (unlikely(!name
|| max
<= 0))
2496 list_for_each_entry(kctl
, &card
->controls
, list
) {
2497 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2503 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2504 if (max
<= mc
->max
) {
2505 mc
->platform_max
= max
;
2511 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2514 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2515 * mixer info callback
2516 * @kcontrol: mixer control
2517 * @uinfo: control element information
2519 * Returns 0 for success.
2521 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2522 struct snd_ctl_elem_info
*uinfo
)
2524 struct soc_mixer_control
*mc
=
2525 (struct soc_mixer_control
*)kcontrol
->private_value
;
2529 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2531 uinfo
->value
.integer
.min
= 0;
2532 uinfo
->value
.integer
.max
= max
-min
;
2536 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx
);
2539 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2540 * mixer get callback
2541 * @kcontrol: mixer control
2542 * @uinfo: control element information
2544 * Returns 0 for success.
2546 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2547 struct snd_ctl_elem_value
*ucontrol
)
2549 struct soc_mixer_control
*mc
=
2550 (struct soc_mixer_control
*)kcontrol
->private_value
;
2551 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2552 unsigned int mask
= (1<<mc
->shift
)-1;
2554 int val
= snd_soc_read(codec
, mc
->reg
) & mask
;
2555 int valr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2557 ucontrol
->value
.integer
.value
[0] = ((val
& 0xff)-min
) & mask
;
2558 ucontrol
->value
.integer
.value
[1] = ((valr
& 0xff)-min
) & mask
;
2561 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx
);
2564 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2565 * mixer put callback
2566 * @kcontrol: mixer control
2567 * @uinfo: control element information
2569 * Returns 0 for success.
2571 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol
*kcontrol
,
2572 struct snd_ctl_elem_value
*ucontrol
)
2574 struct soc_mixer_control
*mc
=
2575 (struct soc_mixer_control
*)kcontrol
->private_value
;
2576 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2577 unsigned int mask
= (1<<mc
->shift
)-1;
2580 unsigned int val
, valr
, oval
, ovalr
;
2582 val
= ((ucontrol
->value
.integer
.value
[0]+min
) & 0xff);
2584 valr
= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff);
2587 oval
= snd_soc_read(codec
, mc
->reg
) & mask
;
2588 ovalr
= snd_soc_read(codec
, mc
->rreg
) & mask
;
2592 ret
= snd_soc_write(codec
, mc
->reg
, val
);
2596 if (ovalr
!= valr
) {
2597 ret
= snd_soc_write(codec
, mc
->rreg
, valr
);
2604 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx
);
2607 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2609 * @clk_id: DAI specific clock ID
2610 * @freq: new clock frequency in Hz
2611 * @dir: new clock direction - input/output.
2613 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2615 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2616 unsigned int freq
, int dir
)
2618 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
2619 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
2620 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
2621 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
2626 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2629 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2631 * @clk_id: DAI specific clock ID
2632 * @source: Source for the clock
2633 * @freq: new clock frequency in Hz
2634 * @dir: new clock direction - input/output.
2636 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2638 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
2639 int source
, unsigned int freq
, int dir
)
2641 if (codec
->driver
->set_sysclk
)
2642 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
2647 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
2650 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2652 * @div_id: DAI specific clock divider ID
2653 * @div: new clock divisor.
2655 * Configures the clock dividers. This is used to derive the best DAI bit and
2656 * frame clocks from the system or master clock. It's best to set the DAI bit
2657 * and frame clocks as low as possible to save system power.
2659 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2660 int div_id
, int div
)
2662 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
2663 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
2667 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2670 * snd_soc_dai_set_pll - configure DAI PLL.
2672 * @pll_id: DAI specific PLL ID
2673 * @source: DAI specific source for the PLL
2674 * @freq_in: PLL input clock frequency in Hz
2675 * @freq_out: requested PLL output clock frequency in Hz
2677 * Configures and enables PLL to generate output clock based on input clock.
2679 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
2680 unsigned int freq_in
, unsigned int freq_out
)
2682 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
2683 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
2685 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
2686 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
2691 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2694 * snd_soc_codec_set_pll - configure codec PLL.
2696 * @pll_id: DAI specific PLL ID
2697 * @source: DAI specific source for the PLL
2698 * @freq_in: PLL input clock frequency in Hz
2699 * @freq_out: requested PLL output clock frequency in Hz
2701 * Configures and enables PLL to generate output clock based on input clock.
2703 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
2704 unsigned int freq_in
, unsigned int freq_out
)
2706 if (codec
->driver
->set_pll
)
2707 return codec
->driver
->set_pll(codec
, pll_id
, source
,
2712 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
2715 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2717 * @fmt: SND_SOC_DAIFMT_ format value.
2719 * Configures the DAI hardware format and clocking.
2721 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2723 if (dai
->driver
&& dai
->driver
->ops
->set_fmt
)
2724 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
2728 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2731 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2733 * @tx_mask: bitmask representing active TX slots.
2734 * @rx_mask: bitmask representing active RX slots.
2735 * @slots: Number of slots in use.
2736 * @slot_width: Width in bits for each slot.
2738 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2741 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2742 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
2744 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
2745 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
2750 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
2753 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2755 * @tx_num: how many TX channels
2756 * @tx_slot: pointer to an array which imply the TX slot number channel
2758 * @rx_num: how many RX channels
2759 * @rx_slot: pointer to an array which imply the RX slot number channel
2762 * configure the relationship between channel number and TDM slot number.
2764 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
2765 unsigned int tx_num
, unsigned int *tx_slot
,
2766 unsigned int rx_num
, unsigned int *rx_slot
)
2768 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
2769 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
2774 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
2777 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2779 * @tristate: tristate enable
2781 * Tristates the DAI so that others can use it.
2783 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2785 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
2786 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
2790 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
2793 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2795 * @mute: mute enable
2797 * Mutes the DAI DAC.
2799 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
2801 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
2802 return dai
->driver
->ops
->digital_mute(dai
, mute
);
2806 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
2809 * snd_soc_register_card - Register a card with the ASoC core
2811 * @card: Card to register
2814 int snd_soc_register_card(struct snd_soc_card
*card
)
2818 if (!card
->name
|| !card
->dev
)
2821 dev_set_drvdata(card
->dev
, card
);
2823 snd_soc_initialize_card_lists(card
);
2825 soc_init_card_debugfs(card
);
2827 card
->rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
) *
2828 (card
->num_links
+ card
->num_aux_devs
),
2830 if (card
->rtd
== NULL
)
2832 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
2834 for (i
= 0; i
< card
->num_links
; i
++)
2835 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
2837 INIT_LIST_HEAD(&card
->list
);
2838 INIT_LIST_HEAD(&card
->dapm_dirty
);
2839 card
->instantiated
= 0;
2840 mutex_init(&card
->mutex
);
2842 mutex_lock(&client_mutex
);
2843 list_add(&card
->list
, &card_list
);
2844 snd_soc_instantiate_cards();
2845 mutex_unlock(&client_mutex
);
2847 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
2851 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
2854 * snd_soc_unregister_card - Unregister a card with the ASoC core
2856 * @card: Card to unregister
2859 int snd_soc_unregister_card(struct snd_soc_card
*card
)
2861 if (card
->instantiated
)
2862 soc_cleanup_card_resources(card
);
2863 mutex_lock(&client_mutex
);
2864 list_del(&card
->list
);
2865 mutex_unlock(&client_mutex
);
2866 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
2870 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
2873 * Simplify DAI link configuration by removing ".-1" from device names
2874 * and sanitizing names.
2876 static char *fmt_single_name(struct device
*dev
, int *id
)
2878 char *found
, name
[NAME_SIZE
];
2881 if (dev_name(dev
) == NULL
)
2884 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
2886 /* are we a "%s.%d" name (platform and SPI components) */
2887 found
= strstr(name
, dev
->driver
->name
);
2890 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
2892 /* discard ID from name if ID == -1 */
2894 found
[strlen(dev
->driver
->name
)] = '\0';
2898 /* I2C component devices are named "bus-addr" */
2899 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
2900 char tmp
[NAME_SIZE
];
2902 /* create unique ID number from I2C addr and bus */
2903 *id
= ((id1
& 0xffff) << 16) + id2
;
2905 /* sanitize component name for DAI link creation */
2906 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
2907 strlcpy(name
, tmp
, NAME_SIZE
);
2912 return kstrdup(name
, GFP_KERNEL
);
2916 * Simplify DAI link naming for single devices with multiple DAIs by removing
2917 * any ".-1" and using the DAI name (instead of device name).
2919 static inline char *fmt_multiple_name(struct device
*dev
,
2920 struct snd_soc_dai_driver
*dai_drv
)
2922 if (dai_drv
->name
== NULL
) {
2923 printk(KERN_ERR
"asoc: error - multiple DAI %s registered with no name\n",
2928 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
2932 * snd_soc_register_dai - Register a DAI with the ASoC core
2934 * @dai: DAI to register
2936 int snd_soc_register_dai(struct device
*dev
,
2937 struct snd_soc_dai_driver
*dai_drv
)
2939 struct snd_soc_dai
*dai
;
2941 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
2943 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
2947 /* create DAI component name */
2948 dai
->name
= fmt_single_name(dev
, &dai
->id
);
2949 if (dai
->name
== NULL
) {
2955 dai
->driver
= dai_drv
;
2956 if (!dai
->driver
->ops
)
2957 dai
->driver
->ops
= &null_dai_ops
;
2959 mutex_lock(&client_mutex
);
2960 list_add(&dai
->list
, &dai_list
);
2961 snd_soc_instantiate_cards();
2962 mutex_unlock(&client_mutex
);
2964 pr_debug("Registered DAI '%s'\n", dai
->name
);
2968 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
2971 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2973 * @dai: DAI to unregister
2975 void snd_soc_unregister_dai(struct device
*dev
)
2977 struct snd_soc_dai
*dai
;
2979 list_for_each_entry(dai
, &dai_list
, list
) {
2980 if (dev
== dai
->dev
)
2986 mutex_lock(&client_mutex
);
2987 list_del(&dai
->list
);
2988 mutex_unlock(&client_mutex
);
2990 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
2994 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
2997 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
2999 * @dai: Array of DAIs to register
3000 * @count: Number of DAIs
3002 int snd_soc_register_dais(struct device
*dev
,
3003 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3005 struct snd_soc_dai
*dai
;
3008 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3010 for (i
= 0; i
< count
; i
++) {
3012 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3018 /* create DAI component name */
3019 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3020 if (dai
->name
== NULL
) {
3027 dai
->driver
= &dai_drv
[i
];
3028 if (dai
->driver
->id
)
3029 dai
->id
= dai
->driver
->id
;
3032 if (!dai
->driver
->ops
)
3033 dai
->driver
->ops
= &null_dai_ops
;
3035 mutex_lock(&client_mutex
);
3036 list_add(&dai
->list
, &dai_list
);
3037 mutex_unlock(&client_mutex
);
3039 pr_debug("Registered DAI '%s'\n", dai
->name
);
3042 mutex_lock(&client_mutex
);
3043 snd_soc_instantiate_cards();
3044 mutex_unlock(&client_mutex
);
3048 for (i
--; i
>= 0; i
--)
3049 snd_soc_unregister_dai(dev
);
3053 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3056 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3058 * @dai: Array of DAIs to unregister
3059 * @count: Number of DAIs
3061 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3065 for (i
= 0; i
< count
; i
++)
3066 snd_soc_unregister_dai(dev
);
3068 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3071 * snd_soc_register_platform - Register a platform with the ASoC core
3073 * @platform: platform to register
3075 int snd_soc_register_platform(struct device
*dev
,
3076 struct snd_soc_platform_driver
*platform_drv
)
3078 struct snd_soc_platform
*platform
;
3080 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3082 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3083 if (platform
== NULL
)
3086 /* create platform component name */
3087 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3088 if (platform
->name
== NULL
) {
3093 platform
->dev
= dev
;
3094 platform
->driver
= platform_drv
;
3095 platform
->dapm
.dev
= dev
;
3096 platform
->dapm
.platform
= platform
;
3097 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3099 mutex_lock(&client_mutex
);
3100 list_add(&platform
->list
, &platform_list
);
3101 snd_soc_instantiate_cards();
3102 mutex_unlock(&client_mutex
);
3104 pr_debug("Registered platform '%s'\n", platform
->name
);
3108 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3111 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3113 * @platform: platform to unregister
3115 void snd_soc_unregister_platform(struct device
*dev
)
3117 struct snd_soc_platform
*platform
;
3119 list_for_each_entry(platform
, &platform_list
, list
) {
3120 if (dev
== platform
->dev
)
3126 mutex_lock(&client_mutex
);
3127 list_del(&platform
->list
);
3128 mutex_unlock(&client_mutex
);
3130 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3131 kfree(platform
->name
);
3134 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3136 static u64 codec_format_map
[] = {
3137 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3138 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3139 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3140 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3141 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3142 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3143 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3144 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3145 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3146 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3147 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3148 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3149 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3150 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3151 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3152 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3155 /* Fix up the DAI formats for endianness: codecs don't actually see
3156 * the endianness of the data but we're using the CPU format
3157 * definitions which do need to include endianness so we ensure that
3158 * codec DAIs always have both big and little endian variants set.
3160 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3164 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3165 if (stream
->formats
& codec_format_map
[i
])
3166 stream
->formats
|= codec_format_map
[i
];
3170 * snd_soc_register_codec - Register a codec with the ASoC core
3172 * @codec: codec to register
3174 int snd_soc_register_codec(struct device
*dev
,
3175 const struct snd_soc_codec_driver
*codec_drv
,
3176 struct snd_soc_dai_driver
*dai_drv
,
3180 struct snd_soc_codec
*codec
;
3183 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3185 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3189 /* create CODEC component name */
3190 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3191 if (codec
->name
== NULL
) {
3196 if (codec_drv
->compress_type
)
3197 codec
->compress_type
= codec_drv
->compress_type
;
3199 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3201 codec
->write
= codec_drv
->write
;
3202 codec
->read
= codec_drv
->read
;
3203 codec
->volatile_register
= codec_drv
->volatile_register
;
3204 codec
->readable_register
= codec_drv
->readable_register
;
3205 codec
->writable_register
= codec_drv
->writable_register
;
3206 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3207 codec
->dapm
.dev
= dev
;
3208 codec
->dapm
.codec
= codec
;
3209 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3210 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3212 codec
->driver
= codec_drv
;
3213 codec
->num_dai
= num_dai
;
3214 mutex_init(&codec
->mutex
);
3216 /* allocate CODEC register cache */
3217 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3218 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3219 codec
->reg_size
= reg_size
;
3220 /* it is necessary to make a copy of the default register cache
3221 * because in the case of using a compression type that requires
3222 * the default register cache to be marked as __devinitconst the
3223 * kernel might have freed the array by the time we initialize
3226 if (codec_drv
->reg_cache_default
) {
3227 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3228 reg_size
, GFP_KERNEL
);
3229 if (!codec
->reg_def_copy
) {
3236 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3237 if (!codec
->volatile_register
)
3238 codec
->volatile_register
= snd_soc_default_volatile_register
;
3239 if (!codec
->readable_register
)
3240 codec
->readable_register
= snd_soc_default_readable_register
;
3241 if (!codec
->writable_register
)
3242 codec
->writable_register
= snd_soc_default_writable_register
;
3245 for (i
= 0; i
< num_dai
; i
++) {
3246 fixup_codec_formats(&dai_drv
[i
].playback
);
3247 fixup_codec_formats(&dai_drv
[i
].capture
);
3250 /* register any DAIs */
3252 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3257 mutex_lock(&client_mutex
);
3258 list_add(&codec
->list
, &codec_list
);
3259 snd_soc_instantiate_cards();
3260 mutex_unlock(&client_mutex
);
3262 pr_debug("Registered codec '%s'\n", codec
->name
);
3266 kfree(codec
->reg_def_copy
);
3267 codec
->reg_def_copy
= NULL
;
3272 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3275 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3277 * @codec: codec to unregister
3279 void snd_soc_unregister_codec(struct device
*dev
)
3281 struct snd_soc_codec
*codec
;
3284 list_for_each_entry(codec
, &codec_list
, list
) {
3285 if (dev
== codec
->dev
)
3292 for (i
= 0; i
< codec
->num_dai
; i
++)
3293 snd_soc_unregister_dai(dev
);
3295 mutex_lock(&client_mutex
);
3296 list_del(&codec
->list
);
3297 mutex_unlock(&client_mutex
);
3299 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3301 snd_soc_cache_exit(codec
);
3302 kfree(codec
->reg_def_copy
);
3306 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3308 static int __init
snd_soc_init(void)
3310 #ifdef CONFIG_DEBUG_FS
3311 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3312 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3314 "ASoC: Failed to create debugfs directory\n");
3315 snd_soc_debugfs_root
= NULL
;
3318 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3320 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3322 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3324 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3326 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3327 &platform_list_fops
))
3328 pr_warn("ASoC: Failed to create platform list debugfs file\n");
3331 snd_soc_util_init();
3333 return platform_driver_register(&soc_driver
);
3335 module_init(snd_soc_init
);
3337 static void __exit
snd_soc_exit(void)
3339 snd_soc_util_exit();
3341 #ifdef CONFIG_DEBUG_FS
3342 debugfs_remove_recursive(snd_soc_debugfs_root
);
3344 platform_driver_unregister(&soc_driver
);
3346 module_exit(snd_soc_exit
);
3348 /* Module information */
3349 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3350 MODULE_DESCRIPTION("ALSA SoC Core");
3351 MODULE_LICENSE("GPL");
3352 MODULE_ALIAS("platform:soc-audio");