2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 * o Add hw rules to enforce rates, etc.
20 * o More testing with other codecs/machines.
21 * o Add more codecs and platforms to ensure good API coverage.
22 * o Support TDM on PCM and I2S
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
30 #include <linux/bitops.h>
31 #include <linux/debugfs.h>
32 #include <linux/platform_device.h>
33 #include <linux/ctype.h>
34 #include <linux/slab.h>
36 #include <sound/ac97_codec.h>
37 #include <sound/core.h>
38 #include <sound/jack.h>
39 #include <sound/pcm.h>
40 #include <sound/pcm_params.h>
41 #include <sound/soc.h>
42 #include <sound/soc-dpcm.h>
43 #include <sound/initval.h>
45 #define CREATE_TRACE_POINTS
46 #include <trace/events/asoc.h>
50 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
52 #ifdef CONFIG_DEBUG_FS
53 struct dentry
*snd_soc_debugfs_root
;
54 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
57 static DEFINE_MUTEX(client_mutex
);
58 static LIST_HEAD(dai_list
);
59 static LIST_HEAD(platform_list
);
60 static LIST_HEAD(codec_list
);
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
67 static int pmdown_time
= 5000;
68 module_param(pmdown_time
, int, 0);
69 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
71 /* returns the minimum number of bytes needed to represent
72 * a particular given value */
73 static int min_bytes_needed(unsigned long val
)
78 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
81 c
= (sizeof val
* 8) - c
;
89 /* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91 static int format_register_str(struct snd_soc_codec
*codec
,
92 unsigned int reg
, char *buf
, size_t len
)
94 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
95 int regsize
= codec
->driver
->reg_word_size
* 2;
98 char regbuf
[regsize
+ 1];
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize
+ regsize
+ 2 + 1 != len
)
108 ret
= snd_soc_read(codec
, reg
);
110 memset(regbuf
, 'X', regsize
);
111 regbuf
[regsize
] = '\0';
113 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
116 /* prepare the buffer */
117 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf
, tmpbuf
, len
);
124 /* codec register dump */
125 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
126 size_t count
, loff_t pos
)
129 int wordsize
, regsize
;
134 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
135 regsize
= codec
->driver
->reg_word_size
* 2;
137 len
= wordsize
+ regsize
+ 2 + 1;
139 if (!codec
->driver
->reg_cache_size
)
142 if (codec
->driver
->reg_cache_step
)
143 step
= codec
->driver
->reg_cache_step
;
145 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
146 if (!snd_soc_codec_readable_register(codec
, i
))
148 if (codec
->driver
->display_register
) {
149 count
+= codec
->driver
->display_register(codec
, buf
+ count
,
150 PAGE_SIZE
- count
, i
);
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
155 if (total
+ len
>= count
- 1)
157 format_register_str(codec
, i
, buf
+ total
, len
);
164 total
= min(total
, count
- 1);
169 static ssize_t
codec_reg_show(struct device
*dev
,
170 struct device_attribute
*attr
, char *buf
)
172 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
174 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
177 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
179 static ssize_t
pmdown_time_show(struct device
*dev
,
180 struct device_attribute
*attr
, char *buf
)
182 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
184 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
187 static ssize_t
pmdown_time_set(struct device
*dev
,
188 struct device_attribute
*attr
,
189 const char *buf
, size_t count
)
191 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
194 ret
= strict_strtol(buf
, 10, &rtd
->pmdown_time
);
201 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
203 #ifdef CONFIG_DEBUG_FS
204 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
205 size_t count
, loff_t
*ppos
)
208 struct snd_soc_codec
*codec
= file
->private_data
;
211 if (*ppos
< 0 || !count
)
214 buf
= kmalloc(count
, GFP_KERNEL
);
218 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
220 if (copy_to_user(user_buf
, buf
, ret
)) {
231 static ssize_t
codec_reg_write_file(struct file
*file
,
232 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
237 unsigned long reg
, value
;
238 struct snd_soc_codec
*codec
= file
->private_data
;
240 buf_size
= min(count
, (sizeof(buf
)-1));
241 if (copy_from_user(buf
, user_buf
, buf_size
))
245 while (*start
== ' ')
247 reg
= simple_strtoul(start
, &start
, 16);
248 while (*start
== ' ')
250 if (strict_strtoul(start
, 16, &value
))
253 /* Userspace has been fiddling around behind the kernel's back */
254 add_taint(TAINT_USER
);
256 snd_soc_write(codec
, reg
, value
);
260 static const struct file_operations codec_reg_fops
= {
262 .read
= codec_reg_read_file
,
263 .write
= codec_reg_write_file
,
264 .llseek
= default_llseek
,
267 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
269 struct dentry
*debugfs_card_root
= codec
->card
->debugfs_card_root
;
271 codec
->debugfs_codec_root
= debugfs_create_dir(codec
->name
,
273 if (!codec
->debugfs_codec_root
) {
274 dev_warn(codec
->dev
, "Failed to create codec debugfs directory\n");
278 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
280 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
283 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
284 codec
->debugfs_codec_root
,
285 codec
, &codec_reg_fops
);
286 if (!codec
->debugfs_reg
)
287 dev_warn(codec
->dev
, "Failed to create codec register debugfs file\n");
289 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
292 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
294 debugfs_remove_recursive(codec
->debugfs_codec_root
);
297 static void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
299 struct dentry
*debugfs_card_root
= platform
->card
->debugfs_card_root
;
301 platform
->debugfs_platform_root
= debugfs_create_dir(platform
->name
,
303 if (!platform
->debugfs_platform_root
) {
304 dev_warn(platform
->dev
,
305 "Failed to create platform debugfs directory\n");
309 snd_soc_dapm_debugfs_init(&platform
->dapm
,
310 platform
->debugfs_platform_root
);
313 static void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
315 debugfs_remove_recursive(platform
->debugfs_platform_root
);
318 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
319 size_t count
, loff_t
*ppos
)
321 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
322 ssize_t len
, ret
= 0;
323 struct snd_soc_codec
*codec
;
328 list_for_each_entry(codec
, &codec_list
, list
) {
329 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
333 if (ret
> PAGE_SIZE
) {
340 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
347 static const struct file_operations codec_list_fops
= {
348 .read
= codec_list_read_file
,
349 .llseek
= default_llseek
,/* read accesses f_pos */
352 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
353 size_t count
, loff_t
*ppos
)
355 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
356 ssize_t len
, ret
= 0;
357 struct snd_soc_dai
*dai
;
362 list_for_each_entry(dai
, &dai_list
, list
) {
363 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
366 if (ret
> PAGE_SIZE
) {
372 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
379 static const struct file_operations dai_list_fops
= {
380 .read
= dai_list_read_file
,
381 .llseek
= default_llseek
,/* read accesses f_pos */
384 static ssize_t
platform_list_read_file(struct file
*file
,
385 char __user
*user_buf
,
386 size_t count
, loff_t
*ppos
)
388 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
389 ssize_t len
, ret
= 0;
390 struct snd_soc_platform
*platform
;
395 list_for_each_entry(platform
, &platform_list
, list
) {
396 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
400 if (ret
> PAGE_SIZE
) {
406 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
413 static const struct file_operations platform_list_fops
= {
414 .read
= platform_list_read_file
,
415 .llseek
= default_llseek
,/* read accesses f_pos */
418 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
420 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
421 snd_soc_debugfs_root
);
422 if (!card
->debugfs_card_root
) {
424 "ASoC: Failed to create card debugfs directory\n");
428 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
429 card
->debugfs_card_root
,
431 if (!card
->debugfs_pop_time
)
433 "Failed to create pop time debugfs file\n");
436 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
438 debugfs_remove_recursive(card
->debugfs_card_root
);
443 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
447 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
451 static inline void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
455 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
459 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
463 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
468 struct snd_pcm_substream
*snd_soc_get_dai_substream(struct snd_soc_card
*card
,
469 const char *dai_link
, int stream
)
473 for (i
= 0; i
< card
->num_links
; i
++) {
474 if (card
->rtd
[i
].dai_link
->no_pcm
&&
475 !strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
476 return card
->rtd
[i
].pcm
->streams
[stream
].substream
;
478 dev_dbg(card
->dev
, "failed to find dai link %s\n", dai_link
);
481 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream
);
483 struct snd_soc_pcm_runtime
*snd_soc_get_pcm_runtime(struct snd_soc_card
*card
,
484 const char *dai_link
)
488 for (i
= 0; i
< card
->num_links
; i
++) {
489 if (!strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
490 return &card
->rtd
[i
];
492 dev_dbg(card
->dev
, "failed to find rtd %s\n", dai_link
);
495 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime
);
497 #ifdef CONFIG_SND_SOC_AC97_BUS
498 /* unregister ac97 codec */
499 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
501 if (codec
->ac97
->dev
.bus
)
502 device_unregister(&codec
->ac97
->dev
);
506 /* stop no dev release warning */
507 static void soc_ac97_device_release(struct device
*dev
){}
509 /* register ac97 codec to bus */
510 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
514 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
515 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
516 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
518 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
519 codec
->card
->snd_card
->number
, 0, codec
->name
);
520 err
= device_register(&codec
->ac97
->dev
);
522 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
523 codec
->ac97
->dev
.bus
= NULL
;
530 #ifdef CONFIG_PM_SLEEP
531 /* powers down audio subsystem for suspend */
532 int snd_soc_suspend(struct device
*dev
)
534 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
535 struct snd_soc_codec
*codec
;
538 /* If the initialization of this soc device failed, there is no codec
539 * associated with it. Just bail out in this case.
541 if (list_empty(&card
->codec_dev_list
))
544 /* Due to the resume being scheduled into a workqueue we could
545 * suspend before that's finished - wait for it to complete.
547 snd_power_lock(card
->snd_card
);
548 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
549 snd_power_unlock(card
->snd_card
);
551 /* we're going to block userspace touching us until resume completes */
552 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
554 /* mute any active DACs */
555 for (i
= 0; i
< card
->num_rtd
; i
++) {
556 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
557 struct snd_soc_dai_driver
*drv
= dai
->driver
;
559 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
562 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
563 drv
->ops
->digital_mute(dai
, 1);
566 /* suspend all pcms */
567 for (i
= 0; i
< card
->num_rtd
; i
++) {
568 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
571 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
574 if (card
->suspend_pre
)
575 card
->suspend_pre(card
);
577 for (i
= 0; i
< card
->num_rtd
; i
++) {
578 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
579 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
581 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
584 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
585 cpu_dai
->driver
->suspend(cpu_dai
);
586 if (platform
->driver
->suspend
&& !platform
->suspended
) {
587 platform
->driver
->suspend(cpu_dai
);
588 platform
->suspended
= 1;
592 /* close any waiting streams and save state */
593 for (i
= 0; i
< card
->num_rtd
; i
++) {
594 flush_delayed_work_sync(&card
->rtd
[i
].delayed_work
);
595 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
598 for (i
= 0; i
< card
->num_rtd
; i
++) {
600 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
603 snd_soc_dapm_stream_event(&card
->rtd
[i
],
604 SNDRV_PCM_STREAM_PLAYBACK
,
605 SND_SOC_DAPM_STREAM_SUSPEND
);
607 snd_soc_dapm_stream_event(&card
->rtd
[i
],
608 SNDRV_PCM_STREAM_CAPTURE
,
609 SND_SOC_DAPM_STREAM_SUSPEND
);
612 /* suspend all CODECs */
613 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
614 /* If there are paths active then the CODEC will be held with
615 * bias _ON and should not be suspended. */
616 if (!codec
->suspended
&& codec
->driver
->suspend
) {
617 switch (codec
->dapm
.bias_level
) {
618 case SND_SOC_BIAS_STANDBY
:
620 * If the CODEC is capable of idle
621 * bias off then being in STANDBY
622 * means it's doing something,
623 * otherwise fall through.
625 if (codec
->dapm
.idle_bias_off
) {
627 "idle_bias_off CODEC on over suspend\n");
630 case SND_SOC_BIAS_OFF
:
631 codec
->driver
->suspend(codec
);
632 codec
->suspended
= 1;
633 codec
->cache_sync
= 1;
636 dev_dbg(codec
->dev
, "CODEC is on over suspend\n");
642 for (i
= 0; i
< card
->num_rtd
; i
++) {
643 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
645 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
648 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
649 cpu_dai
->driver
->suspend(cpu_dai
);
652 if (card
->suspend_post
)
653 card
->suspend_post(card
);
657 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
659 /* deferred resume work, so resume can complete before we finished
660 * setting our codec back up, which can be very slow on I2C
662 static void soc_resume_deferred(struct work_struct
*work
)
664 struct snd_soc_card
*card
=
665 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
666 struct snd_soc_codec
*codec
;
669 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
670 * so userspace apps are blocked from touching us
673 dev_dbg(card
->dev
, "starting resume work\n");
675 /* Bring us up into D2 so that DAPM starts enabling things */
676 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
678 if (card
->resume_pre
)
679 card
->resume_pre(card
);
681 /* resume AC97 DAIs */
682 for (i
= 0; i
< card
->num_rtd
; i
++) {
683 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
685 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
688 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
689 cpu_dai
->driver
->resume(cpu_dai
);
692 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
693 /* If the CODEC was idle over suspend then it will have been
694 * left with bias OFF or STANDBY and suspended so we must now
695 * resume. Otherwise the suspend was suppressed.
697 if (codec
->driver
->resume
&& codec
->suspended
) {
698 switch (codec
->dapm
.bias_level
) {
699 case SND_SOC_BIAS_STANDBY
:
700 case SND_SOC_BIAS_OFF
:
701 codec
->driver
->resume(codec
);
702 codec
->suspended
= 0;
705 dev_dbg(codec
->dev
, "CODEC was on over suspend\n");
711 for (i
= 0; i
< card
->num_rtd
; i
++) {
713 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
716 snd_soc_dapm_stream_event(&card
->rtd
[i
],
717 SNDRV_PCM_STREAM_PLAYBACK
,
718 SND_SOC_DAPM_STREAM_RESUME
);
720 snd_soc_dapm_stream_event(&card
->rtd
[i
],
721 SNDRV_PCM_STREAM_CAPTURE
,
722 SND_SOC_DAPM_STREAM_RESUME
);
725 /* unmute any active DACs */
726 for (i
= 0; i
< card
->num_rtd
; i
++) {
727 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
728 struct snd_soc_dai_driver
*drv
= dai
->driver
;
730 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
733 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
734 drv
->ops
->digital_mute(dai
, 0);
737 for (i
= 0; i
< card
->num_rtd
; i
++) {
738 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
739 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
741 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
744 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
745 cpu_dai
->driver
->resume(cpu_dai
);
746 if (platform
->driver
->resume
&& platform
->suspended
) {
747 platform
->driver
->resume(cpu_dai
);
748 platform
->suspended
= 0;
752 if (card
->resume_post
)
753 card
->resume_post(card
);
755 dev_dbg(card
->dev
, "resume work completed\n");
757 /* userspace can access us now we are back as we were before */
758 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
761 /* powers up audio subsystem after a suspend */
762 int snd_soc_resume(struct device
*dev
)
764 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
765 int i
, ac97_control
= 0;
767 /* If the initialization of this soc device failed, there is no codec
768 * associated with it. Just bail out in this case.
770 if (list_empty(&card
->codec_dev_list
))
773 /* AC97 devices might have other drivers hanging off them so
774 * need to resume immediately. Other drivers don't have that
775 * problem and may take a substantial amount of time to resume
776 * due to I/O costs and anti-pop so handle them out of line.
778 for (i
= 0; i
< card
->num_rtd
; i
++) {
779 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
780 ac97_control
|= cpu_dai
->driver
->ac97_control
;
783 dev_dbg(dev
, "Resuming AC97 immediately\n");
784 soc_resume_deferred(&card
->deferred_resume_work
);
786 dev_dbg(dev
, "Scheduling resume work\n");
787 if (!schedule_work(&card
->deferred_resume_work
))
788 dev_err(dev
, "resume work item may be lost\n");
793 EXPORT_SYMBOL_GPL(snd_soc_resume
);
795 #define snd_soc_suspend NULL
796 #define snd_soc_resume NULL
799 static const struct snd_soc_dai_ops null_dai_ops
= {
802 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
804 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
805 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
806 struct snd_soc_codec
*codec
;
807 struct snd_soc_platform
*platform
;
808 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
809 const char *platform_name
;
811 dev_dbg(card
->dev
, "binding %s at idx %d\n", dai_link
->name
, num
);
813 /* Find CPU DAI from registered DAIs*/
814 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
815 if (dai_link
->cpu_of_node
&&
816 (cpu_dai
->dev
->of_node
!= dai_link
->cpu_of_node
))
818 if (dai_link
->cpu_name
&&
819 strcmp(dev_name(cpu_dai
->dev
), dai_link
->cpu_name
))
821 if (dai_link
->cpu_dai_name
&&
822 strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
))
825 rtd
->cpu_dai
= cpu_dai
;
829 dev_dbg(card
->dev
, "CPU DAI %s not registered\n",
830 dai_link
->cpu_dai_name
);
831 return -EPROBE_DEFER
;
834 /* Find CODEC from registered CODECs */
835 list_for_each_entry(codec
, &codec_list
, list
) {
836 if (dai_link
->codec_of_node
) {
837 if (codec
->dev
->of_node
!= dai_link
->codec_of_node
)
840 if (strcmp(codec
->name
, dai_link
->codec_name
))
847 * CODEC found, so find CODEC DAI from registered DAIs from
850 list_for_each_entry(codec_dai
, &dai_list
, list
) {
851 if (codec
->dev
== codec_dai
->dev
&&
852 !strcmp(codec_dai
->name
,
853 dai_link
->codec_dai_name
)) {
855 rtd
->codec_dai
= codec_dai
;
859 if (!rtd
->codec_dai
) {
860 dev_dbg(card
->dev
, "CODEC DAI %s not registered\n",
861 dai_link
->codec_dai_name
);
862 return -EPROBE_DEFER
;
867 dev_dbg(card
->dev
, "CODEC %s not registered\n",
868 dai_link
->codec_name
);
869 return -EPROBE_DEFER
;
872 /* if there's no platform we match on the empty platform */
873 platform_name
= dai_link
->platform_name
;
874 if (!platform_name
&& !dai_link
->platform_of_node
)
875 platform_name
= "snd-soc-dummy";
877 /* find one from the set of registered platforms */
878 list_for_each_entry(platform
, &platform_list
, list
) {
879 if (dai_link
->platform_of_node
) {
880 if (platform
->dev
->of_node
!=
881 dai_link
->platform_of_node
)
884 if (strcmp(platform
->name
, platform_name
))
888 rtd
->platform
= platform
;
890 if (!rtd
->platform
) {
891 dev_dbg(card
->dev
, "platform %s not registered\n",
892 dai_link
->platform_name
);
893 return -EPROBE_DEFER
;
901 static void soc_remove_codec(struct snd_soc_codec
*codec
)
905 if (codec
->driver
->remove
) {
906 err
= codec
->driver
->remove(codec
);
909 "asoc: failed to remove %s: %d\n",
913 /* Make sure all DAPM widgets are freed */
914 snd_soc_dapm_free(&codec
->dapm
);
916 soc_cleanup_codec_debugfs(codec
);
918 list_del(&codec
->card_list
);
919 module_put(codec
->dev
->driver
->owner
);
922 static void soc_remove_dai_link(struct snd_soc_card
*card
, int num
, int order
)
924 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
925 struct snd_soc_codec
*codec
= rtd
->codec
;
926 struct snd_soc_platform
*platform
= rtd
->platform
;
927 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
930 /* unregister the rtd device */
931 if (rtd
->dev_registered
) {
932 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
933 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
934 device_unregister(rtd
->dev
);
935 rtd
->dev_registered
= 0;
938 /* remove the CODEC DAI */
939 if (codec_dai
&& codec_dai
->probed
&&
940 codec_dai
->driver
->remove_order
== order
) {
941 if (codec_dai
->driver
->remove
) {
942 err
= codec_dai
->driver
->remove(codec_dai
);
944 pr_err("asoc: failed to remove %s: %d\n",
945 codec_dai
->name
, err
);
947 codec_dai
->probed
= 0;
948 list_del(&codec_dai
->card_list
);
951 /* remove the platform */
952 if (platform
&& platform
->probed
&&
953 platform
->driver
->remove_order
== order
) {
954 if (platform
->driver
->remove
) {
955 err
= platform
->driver
->remove(platform
);
957 pr_err("asoc: failed to remove %s: %d\n",
958 platform
->name
, err
);
961 /* Make sure all DAPM widgets are freed */
962 snd_soc_dapm_free(&platform
->dapm
);
964 soc_cleanup_platform_debugfs(platform
);
965 platform
->probed
= 0;
966 list_del(&platform
->card_list
);
967 module_put(platform
->dev
->driver
->owner
);
970 /* remove the CODEC */
971 if (codec
&& codec
->probed
&&
972 codec
->driver
->remove_order
== order
)
973 soc_remove_codec(codec
);
975 /* remove the cpu_dai */
976 if (cpu_dai
&& cpu_dai
->probed
&&
977 cpu_dai
->driver
->remove_order
== order
) {
978 if (cpu_dai
->driver
->remove
) {
979 err
= cpu_dai
->driver
->remove(cpu_dai
);
981 pr_err("asoc: failed to remove %s: %d\n",
985 list_del(&cpu_dai
->card_list
);
986 module_put(cpu_dai
->dev
->driver
->owner
);
990 static void soc_remove_dai_links(struct snd_soc_card
*card
)
994 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
996 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
997 soc_remove_dai_link(card
, dai
, order
);
1002 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1003 struct snd_soc_codec
*codec
)
1007 if (card
->codec_conf
== NULL
)
1010 for (i
= 0; i
< card
->num_configs
; i
++) {
1011 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1012 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
1013 codec
->name_prefix
= map
->name_prefix
;
1019 static int soc_probe_codec(struct snd_soc_card
*card
,
1020 struct snd_soc_codec
*codec
)
1023 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
1024 struct snd_soc_dai
*dai
;
1027 codec
->dapm
.card
= card
;
1028 soc_set_name_prefix(card
, codec
);
1030 if (!try_module_get(codec
->dev
->driver
->owner
))
1033 soc_init_codec_debugfs(codec
);
1035 if (driver
->dapm_widgets
)
1036 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
1037 driver
->num_dapm_widgets
);
1039 /* Create DAPM widgets for each DAI stream */
1040 list_for_each_entry(dai
, &dai_list
, list
) {
1041 if (dai
->dev
!= codec
->dev
)
1044 snd_soc_dapm_new_dai_widgets(&codec
->dapm
, dai
);
1047 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
1049 if (driver
->probe
) {
1050 ret
= driver
->probe(codec
);
1053 "asoc: failed to probe CODEC %s: %d\n",
1059 if (driver
->controls
)
1060 snd_soc_add_codec_controls(codec
, driver
->controls
,
1061 driver
->num_controls
);
1062 if (driver
->dapm_routes
)
1063 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1064 driver
->num_dapm_routes
);
1066 /* mark codec as probed and add to card codec list */
1068 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1069 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1074 soc_cleanup_codec_debugfs(codec
);
1075 module_put(codec
->dev
->driver
->owner
);
1080 static int soc_probe_platform(struct snd_soc_card
*card
,
1081 struct snd_soc_platform
*platform
)
1084 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1085 struct snd_soc_dai
*dai
;
1087 platform
->card
= card
;
1088 platform
->dapm
.card
= card
;
1090 if (!try_module_get(platform
->dev
->driver
->owner
))
1093 soc_init_platform_debugfs(platform
);
1095 if (driver
->dapm_widgets
)
1096 snd_soc_dapm_new_controls(&platform
->dapm
,
1097 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1099 /* Create DAPM widgets for each DAI stream */
1100 list_for_each_entry(dai
, &dai_list
, list
) {
1101 if (dai
->dev
!= platform
->dev
)
1104 snd_soc_dapm_new_dai_widgets(&platform
->dapm
, dai
);
1107 platform
->dapm
.idle_bias_off
= 1;
1109 if (driver
->probe
) {
1110 ret
= driver
->probe(platform
);
1112 dev_err(platform
->dev
,
1113 "asoc: failed to probe platform %s: %d\n",
1114 platform
->name
, ret
);
1119 if (driver
->controls
)
1120 snd_soc_add_platform_controls(platform
, driver
->controls
,
1121 driver
->num_controls
);
1122 if (driver
->dapm_routes
)
1123 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1124 driver
->num_dapm_routes
);
1126 /* mark platform as probed and add to card platform list */
1127 platform
->probed
= 1;
1128 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1129 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1134 soc_cleanup_platform_debugfs(platform
);
1135 module_put(platform
->dev
->driver
->owner
);
1140 static void rtd_release(struct device
*dev
)
1145 static int soc_post_component_init(struct snd_soc_card
*card
,
1146 struct snd_soc_codec
*codec
,
1147 int num
, int dailess
)
1149 struct snd_soc_dai_link
*dai_link
= NULL
;
1150 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1151 struct snd_soc_pcm_runtime
*rtd
;
1152 const char *temp
, *name
;
1156 dai_link
= &card
->dai_link
[num
];
1157 rtd
= &card
->rtd
[num
];
1158 name
= dai_link
->name
;
1160 aux_dev
= &card
->aux_dev
[num
];
1161 rtd
= &card
->rtd_aux
[num
];
1162 name
= aux_dev
->name
;
1166 /* Make sure all DAPM widgets are instantiated */
1167 snd_soc_dapm_new_widgets(&codec
->dapm
);
1169 /* machine controls, routes and widgets are not prefixed */
1170 temp
= codec
->name_prefix
;
1171 codec
->name_prefix
= NULL
;
1173 /* do machine specific initialization */
1174 if (!dailess
&& dai_link
->init
)
1175 ret
= dai_link
->init(rtd
);
1176 else if (dailess
&& aux_dev
->init
)
1177 ret
= aux_dev
->init(&codec
->dapm
);
1179 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1182 codec
->name_prefix
= temp
;
1184 /* register the rtd device */
1187 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1190 device_initialize(rtd
->dev
);
1191 rtd
->dev
->parent
= card
->dev
;
1192 rtd
->dev
->release
= rtd_release
;
1193 rtd
->dev
->init_name
= name
;
1194 dev_set_drvdata(rtd
->dev
, rtd
);
1195 mutex_init(&rtd
->pcm_mutex
);
1196 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1197 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1198 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1199 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1200 ret
= device_add(rtd
->dev
);
1203 "asoc: failed to register runtime device: %d\n", ret
);
1206 rtd
->dev_registered
= 1;
1208 /* add DAPM sysfs entries for this codec */
1209 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1212 "asoc: failed to add codec dapm sysfs entries: %d\n",
1215 /* add codec sysfs entries */
1216 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1219 "asoc: failed to add codec sysfs files: %d\n", ret
);
1221 #ifdef CONFIG_DEBUG_FS
1222 /* add DPCM sysfs entries */
1223 if (!dailess
&& !dai_link
->dynamic
)
1226 ret
= soc_dpcm_debugfs_add(rtd
);
1228 dev_err(rtd
->dev
, "asoc: failed to add dpcm sysfs entries: %d\n", ret
);
1235 static int soc_probe_dai_link(struct snd_soc_card
*card
, int num
, int order
)
1237 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1238 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1239 struct snd_soc_codec
*codec
= rtd
->codec
;
1240 struct snd_soc_platform
*platform
= rtd
->platform
;
1241 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1242 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1243 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1246 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1247 card
->name
, num
, order
);
1249 /* config components */
1250 cpu_dai
->platform
= platform
;
1251 codec_dai
->card
= card
;
1252 cpu_dai
->card
= card
;
1254 /* set default power off timeout */
1255 rtd
->pmdown_time
= pmdown_time
;
1257 /* probe the cpu_dai */
1258 if (!cpu_dai
->probed
&&
1259 cpu_dai
->driver
->probe_order
== order
) {
1260 cpu_dai
->dapm
.card
= card
;
1261 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1264 snd_soc_dapm_new_dai_widgets(&cpu_dai
->dapm
, cpu_dai
);
1266 if (cpu_dai
->driver
->probe
) {
1267 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1269 pr_err("asoc: failed to probe CPU DAI %s: %d\n",
1270 cpu_dai
->name
, ret
);
1271 module_put(cpu_dai
->dev
->driver
->owner
);
1275 cpu_dai
->probed
= 1;
1276 /* mark cpu_dai as probed and add to card dai list */
1277 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1280 /* probe the CODEC */
1281 if (!codec
->probed
&&
1282 codec
->driver
->probe_order
== order
) {
1283 ret
= soc_probe_codec(card
, codec
);
1288 /* probe the platform */
1289 if (!platform
->probed
&&
1290 platform
->driver
->probe_order
== order
) {
1291 ret
= soc_probe_platform(card
, platform
);
1296 /* probe the CODEC DAI */
1297 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1298 if (codec_dai
->driver
->probe
) {
1299 ret
= codec_dai
->driver
->probe(codec_dai
);
1301 pr_err("asoc: failed to probe CODEC DAI %s: %d\n",
1302 codec_dai
->name
, ret
);
1307 /* mark codec_dai as probed and add to card dai list */
1308 codec_dai
->probed
= 1;
1309 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1312 /* complete DAI probe during last probe */
1313 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1316 ret
= soc_post_component_init(card
, codec
, num
, 0);
1320 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1322 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret
);
1324 if (!dai_link
->params
) {
1325 /* create the pcm */
1326 ret
= soc_new_pcm(rtd
, num
);
1328 pr_err("asoc: can't create pcm %s :%d\n",
1329 dai_link
->stream_name
, ret
);
1333 /* link the DAI widgets */
1334 play_w
= codec_dai
->playback_widget
;
1335 capture_w
= cpu_dai
->capture_widget
;
1336 if (play_w
&& capture_w
) {
1337 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1340 dev_err(card
->dev
, "Can't link %s to %s: %d\n",
1341 play_w
->name
, capture_w
->name
, ret
);
1346 play_w
= cpu_dai
->playback_widget
;
1347 capture_w
= codec_dai
->capture_widget
;
1348 if (play_w
&& capture_w
) {
1349 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1352 dev_err(card
->dev
, "Can't link %s to %s: %d\n",
1353 play_w
->name
, capture_w
->name
, ret
);
1359 /* add platform data for AC97 devices */
1360 if (rtd
->codec_dai
->driver
->ac97_control
)
1361 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1366 #ifdef CONFIG_SND_SOC_AC97_BUS
1367 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1371 /* Only instantiate AC97 if not already done by the adaptor
1372 * for the generic AC97 subsystem.
1374 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1376 * It is possible that the AC97 device is already registered to
1377 * the device subsystem. This happens when the device is created
1378 * via snd_ac97_mixer(). Currently only SoC codec that does so
1379 * is the generic AC97 glue but others migh emerge.
1381 * In those cases we don't try to register the device again.
1383 if (!rtd
->codec
->ac97_created
)
1386 ret
= soc_ac97_dev_register(rtd
->codec
);
1388 pr_err("asoc: AC97 device register failed:%d\n", ret
);
1392 rtd
->codec
->ac97_registered
= 1;
1397 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1399 if (codec
->ac97_registered
) {
1400 soc_ac97_dev_unregister(codec
);
1401 codec
->ac97_registered
= 0;
1406 static int soc_check_aux_dev(struct snd_soc_card
*card
, int num
)
1408 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1409 struct snd_soc_codec
*codec
;
1411 /* find CODEC from registered CODECs*/
1412 list_for_each_entry(codec
, &codec_list
, list
) {
1413 if (!strcmp(codec
->name
, aux_dev
->codec_name
))
1417 return -EPROBE_DEFER
;
1420 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1422 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1423 struct snd_soc_codec
*codec
;
1426 /* find CODEC from registered CODECs*/
1427 list_for_each_entry(codec
, &codec_list
, list
) {
1428 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1429 if (codec
->probed
) {
1431 "asoc: codec already probed");
1438 /* codec not found */
1439 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1440 return -EPROBE_DEFER
;
1443 ret
= soc_probe_codec(card
, codec
);
1447 ret
= soc_post_component_init(card
, codec
, num
, 1);
1453 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1455 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1456 struct snd_soc_codec
*codec
= rtd
->codec
;
1458 /* unregister the rtd device */
1459 if (rtd
->dev_registered
) {
1460 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1461 device_del(rtd
->dev
);
1462 rtd
->dev_registered
= 0;
1465 if (codec
&& codec
->probed
)
1466 soc_remove_codec(codec
);
1469 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1470 enum snd_soc_compress_type compress_type
)
1474 if (codec
->cache_init
)
1477 /* override the compress_type if necessary */
1478 if (compress_type
&& codec
->compress_type
!= compress_type
)
1479 codec
->compress_type
= compress_type
;
1480 ret
= snd_soc_cache_init(codec
);
1482 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1486 codec
->cache_init
= 1;
1490 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1492 struct snd_soc_codec
*codec
;
1493 struct snd_soc_codec_conf
*codec_conf
;
1494 enum snd_soc_compress_type compress_type
;
1495 struct snd_soc_dai_link
*dai_link
;
1496 int ret
, i
, order
, dai_fmt
;
1498 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1501 for (i
= 0; i
< card
->num_links
; i
++) {
1502 ret
= soc_bind_dai_link(card
, i
);
1507 /* check aux_devs too */
1508 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1509 ret
= soc_check_aux_dev(card
, i
);
1514 /* initialize the register cache for each available codec */
1515 list_for_each_entry(codec
, &codec_list
, list
) {
1516 if (codec
->cache_init
)
1518 /* by default we don't override the compress_type */
1520 /* check to see if we need to override the compress_type */
1521 for (i
= 0; i
< card
->num_configs
; ++i
) {
1522 codec_conf
= &card
->codec_conf
[i
];
1523 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1524 compress_type
= codec_conf
->compress_type
;
1525 if (compress_type
&& compress_type
1526 != codec
->compress_type
)
1530 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1535 /* card bind complete so register a sound card */
1536 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1537 card
->owner
, 0, &card
->snd_card
);
1539 pr_err("asoc: can't create sound card for card %s: %d\n",
1543 card
->snd_card
->dev
= card
->dev
;
1545 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1546 card
->dapm
.dev
= card
->dev
;
1547 card
->dapm
.card
= card
;
1548 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1550 #ifdef CONFIG_DEBUG_FS
1551 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1554 #ifdef CONFIG_PM_SLEEP
1555 /* deferred resume work */
1556 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1559 if (card
->dapm_widgets
)
1560 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1561 card
->num_dapm_widgets
);
1563 /* initialise the sound card only once */
1565 ret
= card
->probe(card
);
1567 goto card_probe_error
;
1570 /* early DAI link probe */
1571 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1573 for (i
= 0; i
< card
->num_links
; i
++) {
1574 ret
= soc_probe_dai_link(card
, i
, order
);
1576 pr_err("asoc: failed to instantiate card %s: %d\n",
1583 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1584 ret
= soc_probe_aux_dev(card
, i
);
1586 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1588 goto probe_aux_dev_err
;
1592 snd_soc_dapm_link_dai_widgets(card
);
1595 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1597 if (card
->dapm_routes
)
1598 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1599 card
->num_dapm_routes
);
1601 snd_soc_dapm_new_widgets(&card
->dapm
);
1603 for (i
= 0; i
< card
->num_links
; i
++) {
1604 dai_link
= &card
->dai_link
[i
];
1605 dai_fmt
= dai_link
->dai_fmt
;
1608 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1610 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1611 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1612 "Failed to set DAI format: %d\n",
1616 /* If this is a regular CPU link there will be a platform */
1618 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1619 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1621 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1622 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1623 "Failed to set DAI format: %d\n",
1625 } else if (dai_fmt
) {
1626 /* Flip the polarity for the "CPU" end */
1627 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1628 switch (dai_link
->dai_fmt
&
1629 SND_SOC_DAIFMT_MASTER_MASK
) {
1630 case SND_SOC_DAIFMT_CBM_CFM
:
1631 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1633 case SND_SOC_DAIFMT_CBM_CFS
:
1634 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1636 case SND_SOC_DAIFMT_CBS_CFM
:
1637 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1639 case SND_SOC_DAIFMT_CBS_CFS
:
1640 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1644 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1646 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1647 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1648 "Failed to set DAI format: %d\n",
1653 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1655 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1656 "%s", card
->long_name
? card
->long_name
: card
->name
);
1657 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1658 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1659 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1660 switch (card
->snd_card
->driver
[i
]) {
1666 if (!isalnum(card
->snd_card
->driver
[i
]))
1667 card
->snd_card
->driver
[i
] = '_';
1672 if (card
->late_probe
) {
1673 ret
= card
->late_probe(card
);
1675 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1677 goto probe_aux_dev_err
;
1681 snd_soc_dapm_new_widgets(&card
->dapm
);
1683 if (card
->fully_routed
)
1684 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1685 snd_soc_dapm_auto_nc_codec_pins(codec
);
1687 ret
= snd_card_register(card
->snd_card
);
1689 pr_err("asoc: failed to register soundcard for %s: %d\n",
1691 goto probe_aux_dev_err
;
1694 #ifdef CONFIG_SND_SOC_AC97_BUS
1695 /* register any AC97 codecs */
1696 for (i
= 0; i
< card
->num_rtd
; i
++) {
1697 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1699 pr_err("asoc: failed to register AC97 %s: %d\n",
1702 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1703 goto probe_aux_dev_err
;
1708 card
->instantiated
= 1;
1709 snd_soc_dapm_sync(&card
->dapm
);
1710 mutex_unlock(&card
->mutex
);
1715 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1716 soc_remove_aux_dev(card
, i
);
1719 soc_remove_dai_links(card
);
1725 snd_card_free(card
->snd_card
);
1728 mutex_unlock(&card
->mutex
);
1733 /* probes a new socdev */
1734 static int soc_probe(struct platform_device
*pdev
)
1736 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1740 * no card, so machine driver should be registering card
1741 * we should not be here in that case so ret error
1746 dev_warn(&pdev
->dev
,
1747 "ASoC machine %s should use snd_soc_register_card()\n",
1750 /* Bodge while we unpick instantiation */
1751 card
->dev
= &pdev
->dev
;
1753 ret
= snd_soc_register_card(card
);
1755 dev_err(&pdev
->dev
, "Failed to register card\n");
1762 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1766 /* make sure any delayed work runs */
1767 for (i
= 0; i
< card
->num_rtd
; i
++) {
1768 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1769 flush_delayed_work_sync(&rtd
->delayed_work
);
1772 /* remove auxiliary devices */
1773 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1774 soc_remove_aux_dev(card
, i
);
1776 /* remove and free each DAI */
1777 soc_remove_dai_links(card
);
1779 soc_cleanup_card_debugfs(card
);
1781 /* remove the card */
1785 snd_soc_dapm_free(&card
->dapm
);
1787 snd_card_free(card
->snd_card
);
1792 /* removes a socdev */
1793 static int soc_remove(struct platform_device
*pdev
)
1795 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1797 snd_soc_unregister_card(card
);
1801 int snd_soc_poweroff(struct device
*dev
)
1803 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1806 if (!card
->instantiated
)
1809 /* Flush out pmdown_time work - we actually do want to run it
1810 * now, we're shutting down so no imminent restart. */
1811 for (i
= 0; i
< card
->num_rtd
; i
++) {
1812 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1813 flush_delayed_work_sync(&rtd
->delayed_work
);
1816 snd_soc_dapm_shutdown(card
);
1820 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1822 const struct dev_pm_ops snd_soc_pm_ops
= {
1823 .suspend
= snd_soc_suspend
,
1824 .resume
= snd_soc_resume
,
1825 .freeze
= snd_soc_suspend
,
1826 .thaw
= snd_soc_resume
,
1827 .poweroff
= snd_soc_poweroff
,
1828 .restore
= snd_soc_resume
,
1830 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1832 /* ASoC platform driver */
1833 static struct platform_driver soc_driver
= {
1835 .name
= "soc-audio",
1836 .owner
= THIS_MODULE
,
1837 .pm
= &snd_soc_pm_ops
,
1840 .remove
= soc_remove
,
1844 * snd_soc_codec_volatile_register: Report if a register is volatile.
1846 * @codec: CODEC to query.
1847 * @reg: Register to query.
1849 * Boolean function indiciating if a CODEC register is volatile.
1851 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1854 if (codec
->volatile_register
)
1855 return codec
->volatile_register(codec
, reg
);
1859 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1862 * snd_soc_codec_readable_register: Report if a register is readable.
1864 * @codec: CODEC to query.
1865 * @reg: Register to query.
1867 * Boolean function indicating if a CODEC register is readable.
1869 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1872 if (codec
->readable_register
)
1873 return codec
->readable_register(codec
, reg
);
1877 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1880 * snd_soc_codec_writable_register: Report if a register is writable.
1882 * @codec: CODEC to query.
1883 * @reg: Register to query.
1885 * Boolean function indicating if a CODEC register is writable.
1887 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1890 if (codec
->writable_register
)
1891 return codec
->writable_register(codec
, reg
);
1895 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1897 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1902 if (!platform
->driver
->read
) {
1903 dev_err(platform
->dev
, "platform has no read back\n");
1907 ret
= platform
->driver
->read(platform
, reg
);
1908 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1909 trace_snd_soc_preg_read(platform
, reg
, ret
);
1913 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1915 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1916 unsigned int reg
, unsigned int val
)
1918 if (!platform
->driver
->write
) {
1919 dev_err(platform
->dev
, "platform has no write back\n");
1923 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
1924 trace_snd_soc_preg_write(platform
, reg
, val
);
1925 return platform
->driver
->write(platform
, reg
, val
);
1927 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
1930 * snd_soc_new_ac97_codec - initailise AC97 device
1931 * @codec: audio codec
1932 * @ops: AC97 bus operations
1933 * @num: AC97 codec number
1935 * Initialises AC97 codec resources for use by ad-hoc devices only.
1937 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1938 struct snd_ac97_bus_ops
*ops
, int num
)
1940 mutex_lock(&codec
->mutex
);
1942 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1943 if (codec
->ac97
== NULL
) {
1944 mutex_unlock(&codec
->mutex
);
1948 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1949 if (codec
->ac97
->bus
== NULL
) {
1952 mutex_unlock(&codec
->mutex
);
1956 codec
->ac97
->bus
->ops
= ops
;
1957 codec
->ac97
->num
= num
;
1960 * Mark the AC97 device to be created by us. This way we ensure that the
1961 * device will be registered with the device subsystem later on.
1963 codec
->ac97_created
= 1;
1965 mutex_unlock(&codec
->mutex
);
1968 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1971 * snd_soc_free_ac97_codec - free AC97 codec device
1972 * @codec: audio codec
1974 * Frees AC97 codec device resources.
1976 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1978 mutex_lock(&codec
->mutex
);
1979 #ifdef CONFIG_SND_SOC_AC97_BUS
1980 soc_unregister_ac97_dai_link(codec
);
1982 kfree(codec
->ac97
->bus
);
1985 codec
->ac97_created
= 0;
1986 mutex_unlock(&codec
->mutex
);
1988 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1990 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
1994 ret
= codec
->read(codec
, reg
);
1995 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
1996 trace_snd_soc_reg_read(codec
, reg
, ret
);
2000 EXPORT_SYMBOL_GPL(snd_soc_read
);
2002 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
2003 unsigned int reg
, unsigned int val
)
2005 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
2006 trace_snd_soc_reg_write(codec
, reg
, val
);
2007 return codec
->write(codec
, reg
, val
);
2009 EXPORT_SYMBOL_GPL(snd_soc_write
);
2011 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
2012 unsigned int reg
, const void *data
, size_t len
)
2014 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
2016 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
2019 * snd_soc_update_bits - update codec register bits
2020 * @codec: audio codec
2021 * @reg: codec register
2022 * @mask: register mask
2025 * Writes new register value.
2027 * Returns 1 for change, 0 for no change, or negative error code.
2029 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2030 unsigned int mask
, unsigned int value
)
2033 unsigned int old
, new;
2036 if (codec
->using_regmap
) {
2037 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
2038 mask
, value
, &change
);
2040 ret
= snd_soc_read(codec
, reg
);
2045 new = (old
& ~mask
) | (value
& mask
);
2046 change
= old
!= new;
2048 ret
= snd_soc_write(codec
, reg
, new);
2056 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
2059 * snd_soc_update_bits_locked - update codec register bits
2060 * @codec: audio codec
2061 * @reg: codec register
2062 * @mask: register mask
2065 * Writes new register value, and takes the codec mutex.
2067 * Returns 1 for change else 0.
2069 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
2070 unsigned short reg
, unsigned int mask
,
2075 mutex_lock(&codec
->mutex
);
2076 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
2077 mutex_unlock(&codec
->mutex
);
2081 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
2084 * snd_soc_test_bits - test register for change
2085 * @codec: audio codec
2086 * @reg: codec register
2087 * @mask: register mask
2090 * Tests a register with a new value and checks if the new value is
2091 * different from the old value.
2093 * Returns 1 for change else 0.
2095 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2096 unsigned int mask
, unsigned int value
)
2099 unsigned int old
, new;
2101 old
= snd_soc_read(codec
, reg
);
2102 new = (old
& ~mask
) | value
;
2103 change
= old
!= new;
2107 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
2110 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
2111 * @substream: the pcm substream
2112 * @hw: the hardware parameters
2114 * Sets the substream runtime hardware parameters.
2116 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
2117 const struct snd_pcm_hardware
*hw
)
2119 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2120 runtime
->hw
.info
= hw
->info
;
2121 runtime
->hw
.formats
= hw
->formats
;
2122 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
2123 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
2124 runtime
->hw
.periods_min
= hw
->periods_min
;
2125 runtime
->hw
.periods_max
= hw
->periods_max
;
2126 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
2127 runtime
->hw
.fifo_size
= hw
->fifo_size
;
2130 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
2133 * snd_soc_cnew - create new control
2134 * @_template: control template
2135 * @data: control private data
2136 * @long_name: control long name
2137 * @prefix: control name prefix
2139 * Create a new mixer control from a template control.
2141 * Returns 0 for success, else error.
2143 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2144 void *data
, const char *long_name
,
2147 struct snd_kcontrol_new
template;
2148 struct snd_kcontrol
*kcontrol
;
2152 memcpy(&template, _template
, sizeof(template));
2156 long_name
= template.name
;
2159 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
2160 name
= kmalloc(name_len
, GFP_KERNEL
);
2164 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
2166 template.name
= name
;
2168 template.name
= long_name
;
2171 kcontrol
= snd_ctl_new1(&template, data
);
2177 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2179 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2180 const struct snd_kcontrol_new
*controls
, int num_controls
,
2181 const char *prefix
, void *data
)
2185 for (i
= 0; i
< num_controls
; i
++) {
2186 const struct snd_kcontrol_new
*control
= &controls
[i
];
2187 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2188 control
->name
, prefix
));
2190 dev_err(dev
, "Failed to add %s: %d\n", control
->name
, err
);
2199 * snd_soc_add_codec_controls - add an array of controls to a codec.
2200 * Convenience function to add a list of controls. Many codecs were
2201 * duplicating this code.
2203 * @codec: codec to add controls to
2204 * @controls: array of controls to add
2205 * @num_controls: number of elements in the array
2207 * Return 0 for success, else error.
2209 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2210 const struct snd_kcontrol_new
*controls
, int num_controls
)
2212 struct snd_card
*card
= codec
->card
->snd_card
;
2214 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2215 codec
->name_prefix
, codec
);
2217 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2220 * snd_soc_add_platform_controls - add an array of controls to a platform.
2221 * Convenience function to add a list of controls.
2223 * @platform: platform to add controls to
2224 * @controls: array of controls to add
2225 * @num_controls: number of elements in the array
2227 * Return 0 for success, else error.
2229 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2230 const struct snd_kcontrol_new
*controls
, int num_controls
)
2232 struct snd_card
*card
= platform
->card
->snd_card
;
2234 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2237 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2240 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2241 * Convenience function to add a list of controls.
2243 * @soc_card: SoC card to add controls to
2244 * @controls: array of controls to add
2245 * @num_controls: number of elements in the array
2247 * Return 0 for success, else error.
2249 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2250 const struct snd_kcontrol_new
*controls
, int num_controls
)
2252 struct snd_card
*card
= soc_card
->snd_card
;
2254 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2257 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2260 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2261 * Convienience function to add a list of controls.
2263 * @dai: DAI to add controls to
2264 * @controls: array of controls to add
2265 * @num_controls: number of elements in the array
2267 * Return 0 for success, else error.
2269 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2270 const struct snd_kcontrol_new
*controls
, int num_controls
)
2272 struct snd_card
*card
= dai
->card
->snd_card
;
2274 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2277 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2280 * snd_soc_info_enum_double - enumerated double mixer info callback
2281 * @kcontrol: mixer control
2282 * @uinfo: control element information
2284 * Callback to provide information about a double enumerated
2287 * Returns 0 for success.
2289 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2290 struct snd_ctl_elem_info
*uinfo
)
2292 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2294 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2295 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2296 uinfo
->value
.enumerated
.items
= e
->max
;
2298 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2299 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2300 strcpy(uinfo
->value
.enumerated
.name
,
2301 e
->texts
[uinfo
->value
.enumerated
.item
]);
2304 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2307 * snd_soc_get_enum_double - enumerated double mixer get callback
2308 * @kcontrol: mixer control
2309 * @ucontrol: control element information
2311 * Callback to get the value of a double enumerated mixer.
2313 * Returns 0 for success.
2315 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2316 struct snd_ctl_elem_value
*ucontrol
)
2318 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2319 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2320 unsigned int val
, bitmask
;
2322 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2324 val
= snd_soc_read(codec
, e
->reg
);
2325 ucontrol
->value
.enumerated
.item
[0]
2326 = (val
>> e
->shift_l
) & (bitmask
- 1);
2327 if (e
->shift_l
!= e
->shift_r
)
2328 ucontrol
->value
.enumerated
.item
[1] =
2329 (val
>> e
->shift_r
) & (bitmask
- 1);
2333 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2336 * snd_soc_put_enum_double - enumerated double mixer put callback
2337 * @kcontrol: mixer control
2338 * @ucontrol: control element information
2340 * Callback to set the value of a double enumerated mixer.
2342 * Returns 0 for success.
2344 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2345 struct snd_ctl_elem_value
*ucontrol
)
2347 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2348 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2350 unsigned int mask
, bitmask
;
2352 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2354 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2356 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2357 mask
= (bitmask
- 1) << e
->shift_l
;
2358 if (e
->shift_l
!= e
->shift_r
) {
2359 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2361 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2362 mask
|= (bitmask
- 1) << e
->shift_r
;
2365 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2367 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2370 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2371 * @kcontrol: mixer control
2372 * @ucontrol: control element information
2374 * Callback to get the value of a double semi enumerated mixer.
2376 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2377 * used for handling bitfield coded enumeration for example.
2379 * Returns 0 for success.
2381 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2382 struct snd_ctl_elem_value
*ucontrol
)
2384 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2385 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2386 unsigned int reg_val
, val
, mux
;
2388 reg_val
= snd_soc_read(codec
, e
->reg
);
2389 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2390 for (mux
= 0; mux
< e
->max
; mux
++) {
2391 if (val
== e
->values
[mux
])
2394 ucontrol
->value
.enumerated
.item
[0] = mux
;
2395 if (e
->shift_l
!= e
->shift_r
) {
2396 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2397 for (mux
= 0; mux
< e
->max
; mux
++) {
2398 if (val
== e
->values
[mux
])
2401 ucontrol
->value
.enumerated
.item
[1] = mux
;
2406 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2409 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2410 * @kcontrol: mixer control
2411 * @ucontrol: control element information
2413 * Callback to set the value of a double semi enumerated mixer.
2415 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2416 * used for handling bitfield coded enumeration for example.
2418 * Returns 0 for success.
2420 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2421 struct snd_ctl_elem_value
*ucontrol
)
2423 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2424 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2428 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2430 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2431 mask
= e
->mask
<< e
->shift_l
;
2432 if (e
->shift_l
!= e
->shift_r
) {
2433 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2435 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2436 mask
|= e
->mask
<< e
->shift_r
;
2439 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2441 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2444 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2445 * @kcontrol: mixer control
2446 * @uinfo: control element information
2448 * Callback to provide information about an external enumerated
2451 * Returns 0 for success.
2453 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2454 struct snd_ctl_elem_info
*uinfo
)
2456 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2458 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2460 uinfo
->value
.enumerated
.items
= e
->max
;
2462 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2463 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2464 strcpy(uinfo
->value
.enumerated
.name
,
2465 e
->texts
[uinfo
->value
.enumerated
.item
]);
2468 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2471 * snd_soc_info_volsw_ext - external single mixer info callback
2472 * @kcontrol: mixer control
2473 * @uinfo: control element information
2475 * Callback to provide information about a single external mixer control.
2477 * Returns 0 for success.
2479 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2480 struct snd_ctl_elem_info
*uinfo
)
2482 int max
= kcontrol
->private_value
;
2484 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2485 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2487 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2490 uinfo
->value
.integer
.min
= 0;
2491 uinfo
->value
.integer
.max
= max
;
2494 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2497 * snd_soc_info_volsw - single mixer info callback
2498 * @kcontrol: mixer control
2499 * @uinfo: control element information
2501 * Callback to provide information about a single mixer control, or a double
2502 * mixer control that spans 2 registers.
2504 * Returns 0 for success.
2506 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2507 struct snd_ctl_elem_info
*uinfo
)
2509 struct soc_mixer_control
*mc
=
2510 (struct soc_mixer_control
*)kcontrol
->private_value
;
2513 if (!mc
->platform_max
)
2514 mc
->platform_max
= mc
->max
;
2515 platform_max
= mc
->platform_max
;
2517 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2518 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2520 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2522 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2523 uinfo
->value
.integer
.min
= 0;
2524 uinfo
->value
.integer
.max
= platform_max
;
2527 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2530 * snd_soc_get_volsw - single mixer get callback
2531 * @kcontrol: mixer control
2532 * @ucontrol: control element information
2534 * Callback to get the value of a single mixer control, or a double mixer
2535 * control that spans 2 registers.
2537 * Returns 0 for success.
2539 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2540 struct snd_ctl_elem_value
*ucontrol
)
2542 struct soc_mixer_control
*mc
=
2543 (struct soc_mixer_control
*)kcontrol
->private_value
;
2544 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2545 unsigned int reg
= mc
->reg
;
2546 unsigned int reg2
= mc
->rreg
;
2547 unsigned int shift
= mc
->shift
;
2548 unsigned int rshift
= mc
->rshift
;
2550 unsigned int mask
= (1 << fls(max
)) - 1;
2551 unsigned int invert
= mc
->invert
;
2553 ucontrol
->value
.integer
.value
[0] =
2554 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2556 ucontrol
->value
.integer
.value
[0] =
2557 max
- ucontrol
->value
.integer
.value
[0];
2559 if (snd_soc_volsw_is_stereo(mc
)) {
2561 ucontrol
->value
.integer
.value
[1] =
2562 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2564 ucontrol
->value
.integer
.value
[1] =
2565 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2567 ucontrol
->value
.integer
.value
[1] =
2568 max
- ucontrol
->value
.integer
.value
[1];
2573 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2576 * snd_soc_put_volsw - single mixer put callback
2577 * @kcontrol: mixer control
2578 * @ucontrol: control element information
2580 * Callback to set the value of a single mixer control, or a double mixer
2581 * control that spans 2 registers.
2583 * Returns 0 for success.
2585 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2586 struct snd_ctl_elem_value
*ucontrol
)
2588 struct soc_mixer_control
*mc
=
2589 (struct soc_mixer_control
*)kcontrol
->private_value
;
2590 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2591 unsigned int reg
= mc
->reg
;
2592 unsigned int reg2
= mc
->rreg
;
2593 unsigned int shift
= mc
->shift
;
2594 unsigned int rshift
= mc
->rshift
;
2596 unsigned int mask
= (1 << fls(max
)) - 1;
2597 unsigned int invert
= mc
->invert
;
2600 unsigned int val2
= 0;
2601 unsigned int val
, val_mask
;
2603 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2606 val_mask
= mask
<< shift
;
2608 if (snd_soc_volsw_is_stereo(mc
)) {
2609 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2613 val_mask
|= mask
<< rshift
;
2614 val
|= val2
<< rshift
;
2616 val2
= val2
<< shift
;
2620 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2625 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2629 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2632 * snd_soc_get_volsw_sx - single mixer get callback
2633 * @kcontrol: mixer control
2634 * @ucontrol: control element information
2636 * Callback to get the value of a single mixer control, or a double mixer
2637 * control that spans 2 registers.
2639 * Returns 0 for success.
2641 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2642 struct snd_ctl_elem_value
*ucontrol
)
2644 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2645 struct soc_mixer_control
*mc
=
2646 (struct soc_mixer_control
*)kcontrol
->private_value
;
2648 unsigned int reg
= mc
->reg
;
2649 unsigned int reg2
= mc
->rreg
;
2650 unsigned int shift
= mc
->shift
;
2651 unsigned int rshift
= mc
->rshift
;
2654 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2656 ucontrol
->value
.integer
.value
[0] =
2657 ((snd_soc_read(codec
, reg
) >> shift
) - min
) & mask
;
2659 if (snd_soc_volsw_is_stereo(mc
))
2660 ucontrol
->value
.integer
.value
[1] =
2661 ((snd_soc_read(codec
, reg2
) >> rshift
) - min
) & mask
;
2665 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2668 * snd_soc_put_volsw_sx - double mixer set callback
2669 * @kcontrol: mixer control
2670 * @uinfo: control element information
2672 * Callback to set the value of a double mixer control that spans 2 registers.
2674 * Returns 0 for success.
2676 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2677 struct snd_ctl_elem_value
*ucontrol
)
2679 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2680 struct soc_mixer_control
*mc
=
2681 (struct soc_mixer_control
*)kcontrol
->private_value
;
2683 unsigned int reg
= mc
->reg
;
2684 unsigned int reg2
= mc
->rreg
;
2685 unsigned int shift
= mc
->shift
;
2686 unsigned int rshift
= mc
->rshift
;
2689 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2691 unsigned short val
, val_mask
, val2
= 0;
2693 val_mask
= mask
<< shift
;
2694 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2697 if (snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
))
2700 if (snd_soc_volsw_is_stereo(mc
)) {
2701 val_mask
= mask
<< rshift
;
2702 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2703 val2
= val2
<< rshift
;
2705 if (snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
))
2710 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2713 * snd_soc_info_volsw_s8 - signed mixer info callback
2714 * @kcontrol: mixer control
2715 * @uinfo: control element information
2717 * Callback to provide information about a signed mixer control.
2719 * Returns 0 for success.
2721 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2722 struct snd_ctl_elem_info
*uinfo
)
2724 struct soc_mixer_control
*mc
=
2725 (struct soc_mixer_control
*)kcontrol
->private_value
;
2729 if (!mc
->platform_max
)
2730 mc
->platform_max
= mc
->max
;
2731 platform_max
= mc
->platform_max
;
2733 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2735 uinfo
->value
.integer
.min
= 0;
2736 uinfo
->value
.integer
.max
= platform_max
- min
;
2739 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2742 * snd_soc_get_volsw_s8 - signed mixer get callback
2743 * @kcontrol: mixer control
2744 * @ucontrol: control element information
2746 * Callback to get the value of a signed mixer control.
2748 * Returns 0 for success.
2750 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2751 struct snd_ctl_elem_value
*ucontrol
)
2753 struct soc_mixer_control
*mc
=
2754 (struct soc_mixer_control
*)kcontrol
->private_value
;
2755 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2756 unsigned int reg
= mc
->reg
;
2758 int val
= snd_soc_read(codec
, reg
);
2760 ucontrol
->value
.integer
.value
[0] =
2761 ((signed char)(val
& 0xff))-min
;
2762 ucontrol
->value
.integer
.value
[1] =
2763 ((signed char)((val
>> 8) & 0xff))-min
;
2766 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2769 * snd_soc_put_volsw_sgn - signed mixer put callback
2770 * @kcontrol: mixer control
2771 * @ucontrol: control element information
2773 * Callback to set the value of a signed mixer control.
2775 * Returns 0 for success.
2777 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2778 struct snd_ctl_elem_value
*ucontrol
)
2780 struct soc_mixer_control
*mc
=
2781 (struct soc_mixer_control
*)kcontrol
->private_value
;
2782 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2783 unsigned int reg
= mc
->reg
;
2787 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2788 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2790 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2792 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2795 * snd_soc_limit_volume - Set new limit to an existing volume control.
2797 * @codec: where to look for the control
2798 * @name: Name of the control
2799 * @max: new maximum limit
2801 * Return 0 for success, else error.
2803 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2804 const char *name
, int max
)
2806 struct snd_card
*card
= codec
->card
->snd_card
;
2807 struct snd_kcontrol
*kctl
;
2808 struct soc_mixer_control
*mc
;
2812 /* Sanity check for name and max */
2813 if (unlikely(!name
|| max
<= 0))
2816 list_for_each_entry(kctl
, &card
->controls
, list
) {
2817 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2823 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2824 if (max
<= mc
->max
) {
2825 mc
->platform_max
= max
;
2831 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2833 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
2834 struct snd_ctl_elem_info
*uinfo
)
2836 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2837 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2839 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
2840 uinfo
->count
= params
->num_regs
* codec
->val_bytes
;
2844 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
2846 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
2847 struct snd_ctl_elem_value
*ucontrol
)
2849 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2850 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2853 if (codec
->using_regmap
)
2854 ret
= regmap_raw_read(codec
->control_data
, params
->base
,
2855 ucontrol
->value
.bytes
.data
,
2856 params
->num_regs
* codec
->val_bytes
);
2860 /* Hide any masked bytes to ensure consistent data reporting */
2861 if (ret
== 0 && params
->mask
) {
2862 switch (codec
->val_bytes
) {
2864 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
2867 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
2871 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
2881 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
2883 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
2884 struct snd_ctl_elem_value
*ucontrol
)
2886 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
2887 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2892 if (!codec
->using_regmap
)
2895 data
= ucontrol
->value
.bytes
.data
;
2896 len
= params
->num_regs
* codec
->val_bytes
;
2899 * If we've got a mask then we need to preserve the register
2900 * bits. We shouldn't modify the incoming data so take a
2904 ret
= regmap_read(codec
->control_data
, params
->base
, &val
);
2908 val
&= params
->mask
;
2910 data
= kmemdup(data
, len
, GFP_KERNEL
);
2914 switch (codec
->val_bytes
) {
2916 ((u8
*)data
)[0] &= ~params
->mask
;
2917 ((u8
*)data
)[0] |= val
;
2920 ((u16
*)data
)[0] &= cpu_to_be16(~params
->mask
);
2921 ((u16
*)data
)[0] |= cpu_to_be16(val
);
2924 ((u32
*)data
)[0] &= cpu_to_be32(~params
->mask
);
2925 ((u32
*)data
)[0] |= cpu_to_be32(val
);
2932 ret
= regmap_raw_write(codec
->control_data
, params
->base
,
2940 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
2943 * snd_soc_info_xr_sx - signed multi register info callback
2944 * @kcontrol: mreg control
2945 * @uinfo: control element information
2947 * Callback to provide information of a control that can
2948 * span multiple codec registers which together
2949 * forms a single signed value in a MSB/LSB manner.
2951 * Returns 0 for success.
2953 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
2954 struct snd_ctl_elem_info
*uinfo
)
2956 struct soc_mreg_control
*mc
=
2957 (struct soc_mreg_control
*)kcontrol
->private_value
;
2958 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2960 uinfo
->value
.integer
.min
= mc
->min
;
2961 uinfo
->value
.integer
.max
= mc
->max
;
2965 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
2968 * snd_soc_get_xr_sx - signed multi register get callback
2969 * @kcontrol: mreg control
2970 * @ucontrol: control element information
2972 * Callback to get the value of a control that can span
2973 * multiple codec registers which together forms a single
2974 * signed value in a MSB/LSB manner. The control supports
2975 * specifying total no of bits used to allow for bitfields
2976 * across the multiple codec registers.
2978 * Returns 0 for success.
2980 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
2981 struct snd_ctl_elem_value
*ucontrol
)
2983 struct soc_mreg_control
*mc
=
2984 (struct soc_mreg_control
*)kcontrol
->private_value
;
2985 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2986 unsigned int regbase
= mc
->regbase
;
2987 unsigned int regcount
= mc
->regcount
;
2988 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
2989 unsigned int regwmask
= (1<<regwshift
)-1;
2990 unsigned int invert
= mc
->invert
;
2991 unsigned long mask
= (1UL<<mc
->nbits
)-1;
2995 unsigned long regval
;
2998 for (i
= 0; i
< regcount
; i
++) {
2999 regval
= snd_soc_read(codec
, regbase
+i
) & regwmask
;
3000 val
|= regval
<< (regwshift
*(regcount
-i
-1));
3003 if (min
< 0 && val
> max
)
3007 ucontrol
->value
.integer
.value
[0] = val
;
3011 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3014 * snd_soc_put_xr_sx - signed multi register get callback
3015 * @kcontrol: mreg control
3016 * @ucontrol: control element information
3018 * Callback to set the value of a control that can span
3019 * multiple codec registers which together forms a single
3020 * signed value in a MSB/LSB manner. The control supports
3021 * specifying total no of bits used to allow for bitfields
3022 * across the multiple codec registers.
3024 * Returns 0 for success.
3026 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3027 struct snd_ctl_elem_value
*ucontrol
)
3029 struct soc_mreg_control
*mc
=
3030 (struct soc_mreg_control
*)kcontrol
->private_value
;
3031 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3032 unsigned int regbase
= mc
->regbase
;
3033 unsigned int regcount
= mc
->regcount
;
3034 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3035 unsigned int regwmask
= (1<<regwshift
)-1;
3036 unsigned int invert
= mc
->invert
;
3037 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3039 long val
= ucontrol
->value
.integer
.value
[0];
3040 unsigned int i
, regval
, regmask
;
3046 for (i
= 0; i
< regcount
; i
++) {
3047 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3048 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3049 err
= snd_soc_update_bits_locked(codec
, regbase
+i
,
3057 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3060 * snd_soc_get_strobe - strobe get callback
3061 * @kcontrol: mixer control
3062 * @ucontrol: control element information
3064 * Callback get the value of a strobe mixer control.
3066 * Returns 0 for success.
3068 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3069 struct snd_ctl_elem_value
*ucontrol
)
3071 struct soc_mixer_control
*mc
=
3072 (struct soc_mixer_control
*)kcontrol
->private_value
;
3073 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3074 unsigned int reg
= mc
->reg
;
3075 unsigned int shift
= mc
->shift
;
3076 unsigned int mask
= 1 << shift
;
3077 unsigned int invert
= mc
->invert
!= 0;
3078 unsigned int val
= snd_soc_read(codec
, reg
) & mask
;
3080 if (shift
!= 0 && val
!= 0)
3082 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3086 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3089 * snd_soc_put_strobe - strobe put callback
3090 * @kcontrol: mixer control
3091 * @ucontrol: control element information
3093 * Callback strobe a register bit to high then low (or the inverse)
3094 * in one pass of a single mixer enum control.
3096 * Returns 1 for success.
3098 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3099 struct snd_ctl_elem_value
*ucontrol
)
3101 struct soc_mixer_control
*mc
=
3102 (struct soc_mixer_control
*)kcontrol
->private_value
;
3103 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3104 unsigned int reg
= mc
->reg
;
3105 unsigned int shift
= mc
->shift
;
3106 unsigned int mask
= 1 << shift
;
3107 unsigned int invert
= mc
->invert
!= 0;
3108 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3109 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3110 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3113 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val1
);
3117 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val2
);
3120 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3123 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3125 * @clk_id: DAI specific clock ID
3126 * @freq: new clock frequency in Hz
3127 * @dir: new clock direction - input/output.
3129 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3131 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3132 unsigned int freq
, int dir
)
3134 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3135 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3136 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3137 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3142 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3145 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3147 * @clk_id: DAI specific clock ID
3148 * @source: Source for the clock
3149 * @freq: new clock frequency in Hz
3150 * @dir: new clock direction - input/output.
3152 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3154 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3155 int source
, unsigned int freq
, int dir
)
3157 if (codec
->driver
->set_sysclk
)
3158 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3163 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3166 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3168 * @div_id: DAI specific clock divider ID
3169 * @div: new clock divisor.
3171 * Configures the clock dividers. This is used to derive the best DAI bit and
3172 * frame clocks from the system or master clock. It's best to set the DAI bit
3173 * and frame clocks as low as possible to save system power.
3175 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3176 int div_id
, int div
)
3178 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3179 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3183 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3186 * snd_soc_dai_set_pll - configure DAI PLL.
3188 * @pll_id: DAI specific PLL ID
3189 * @source: DAI specific source for the PLL
3190 * @freq_in: PLL input clock frequency in Hz
3191 * @freq_out: requested PLL output clock frequency in Hz
3193 * Configures and enables PLL to generate output clock based on input clock.
3195 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3196 unsigned int freq_in
, unsigned int freq_out
)
3198 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3199 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3201 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3202 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3207 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3210 * snd_soc_codec_set_pll - configure codec PLL.
3212 * @pll_id: DAI specific PLL ID
3213 * @source: DAI specific source for the PLL
3214 * @freq_in: PLL input clock frequency in Hz
3215 * @freq_out: requested PLL output clock frequency in Hz
3217 * Configures and enables PLL to generate output clock based on input clock.
3219 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3220 unsigned int freq_in
, unsigned int freq_out
)
3222 if (codec
->driver
->set_pll
)
3223 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3228 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3231 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3233 * @fmt: SND_SOC_DAIFMT_ format value.
3235 * Configures the DAI hardware format and clocking.
3237 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3239 if (dai
->driver
== NULL
)
3241 if (dai
->driver
->ops
->set_fmt
== NULL
)
3243 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3245 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3248 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3250 * @tx_mask: bitmask representing active TX slots.
3251 * @rx_mask: bitmask representing active RX slots.
3252 * @slots: Number of slots in use.
3253 * @slot_width: Width in bits for each slot.
3255 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3258 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3259 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3261 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3262 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3267 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3270 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3272 * @tx_num: how many TX channels
3273 * @tx_slot: pointer to an array which imply the TX slot number channel
3275 * @rx_num: how many RX channels
3276 * @rx_slot: pointer to an array which imply the RX slot number channel
3279 * configure the relationship between channel number and TDM slot number.
3281 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3282 unsigned int tx_num
, unsigned int *tx_slot
,
3283 unsigned int rx_num
, unsigned int *rx_slot
)
3285 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3286 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3291 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3294 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3296 * @tristate: tristate enable
3298 * Tristates the DAI so that others can use it.
3300 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3302 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3303 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3307 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3310 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3312 * @mute: mute enable
3314 * Mutes the DAI DAC.
3316 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
3318 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
3319 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3323 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3326 * snd_soc_register_card - Register a card with the ASoC core
3328 * @card: Card to register
3331 int snd_soc_register_card(struct snd_soc_card
*card
)
3335 if (!card
->name
|| !card
->dev
)
3338 for (i
= 0; i
< card
->num_links
; i
++) {
3339 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3342 * Codec must be specified by 1 of name or OF node,
3343 * not both or neither.
3345 if (!!link
->codec_name
== !!link
->codec_of_node
) {
3347 "Neither/both codec name/of_node are set for %s\n",
3351 /* Codec DAI name must be specified */
3352 if (!link
->codec_dai_name
) {
3353 dev_err(card
->dev
, "codec_dai_name not set for %s\n",
3359 * Platform may be specified by either name or OF node, but
3360 * can be left unspecified, and a dummy platform will be used.
3362 if (link
->platform_name
&& link
->platform_of_node
) {
3364 "Both platform name/of_node are set for %s\n", link
->name
);
3369 * CPU device may be specified by either name or OF node, but
3370 * can be left unspecified, and will be matched based on DAI
3373 if (link
->cpu_name
&& link
->cpu_of_node
) {
3375 "Neither/both cpu name/of_node are set for %s\n",
3380 * At least one of CPU DAI name or CPU device name/node must be
3383 if (!link
->cpu_dai_name
&&
3384 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3386 "Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3392 dev_set_drvdata(card
->dev
, card
);
3394 snd_soc_initialize_card_lists(card
);
3396 soc_init_card_debugfs(card
);
3398 card
->rtd
= devm_kzalloc(card
->dev
,
3399 sizeof(struct snd_soc_pcm_runtime
) *
3400 (card
->num_links
+ card
->num_aux_devs
),
3402 if (card
->rtd
== NULL
)
3405 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3407 for (i
= 0; i
< card
->num_links
; i
++)
3408 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3410 INIT_LIST_HEAD(&card
->list
);
3411 INIT_LIST_HEAD(&card
->dapm_dirty
);
3412 card
->instantiated
= 0;
3413 mutex_init(&card
->mutex
);
3414 mutex_init(&card
->dapm_mutex
);
3416 ret
= snd_soc_instantiate_card(card
);
3418 soc_cleanup_card_debugfs(card
);
3422 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3425 * snd_soc_unregister_card - Unregister a card with the ASoC core
3427 * @card: Card to unregister
3430 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3432 if (card
->instantiated
)
3433 soc_cleanup_card_resources(card
);
3434 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
3438 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3441 * Simplify DAI link configuration by removing ".-1" from device names
3442 * and sanitizing names.
3444 static char *fmt_single_name(struct device
*dev
, int *id
)
3446 char *found
, name
[NAME_SIZE
];
3449 if (dev_name(dev
) == NULL
)
3452 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3454 /* are we a "%s.%d" name (platform and SPI components) */
3455 found
= strstr(name
, dev
->driver
->name
);
3458 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3460 /* discard ID from name if ID == -1 */
3462 found
[strlen(dev
->driver
->name
)] = '\0';
3466 /* I2C component devices are named "bus-addr" */
3467 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3468 char tmp
[NAME_SIZE
];
3470 /* create unique ID number from I2C addr and bus */
3471 *id
= ((id1
& 0xffff) << 16) + id2
;
3473 /* sanitize component name for DAI link creation */
3474 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3475 strlcpy(name
, tmp
, NAME_SIZE
);
3480 return kstrdup(name
, GFP_KERNEL
);
3484 * Simplify DAI link naming for single devices with multiple DAIs by removing
3485 * any ".-1" and using the DAI name (instead of device name).
3487 static inline char *fmt_multiple_name(struct device
*dev
,
3488 struct snd_soc_dai_driver
*dai_drv
)
3490 if (dai_drv
->name
== NULL
) {
3491 pr_err("asoc: error - multiple DAI %s registered with no name\n",
3496 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3500 * snd_soc_register_dai - Register a DAI with the ASoC core
3502 * @dai: DAI to register
3504 int snd_soc_register_dai(struct device
*dev
,
3505 struct snd_soc_dai_driver
*dai_drv
)
3507 struct snd_soc_codec
*codec
;
3508 struct snd_soc_dai
*dai
;
3510 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
3512 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3516 /* create DAI component name */
3517 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3518 if (dai
->name
== NULL
) {
3524 dai
->driver
= dai_drv
;
3525 dai
->dapm
.dev
= dev
;
3526 if (!dai
->driver
->ops
)
3527 dai
->driver
->ops
= &null_dai_ops
;
3529 mutex_lock(&client_mutex
);
3531 list_for_each_entry(codec
, &codec_list
, list
) {
3532 if (codec
->dev
== dev
) {
3533 dev_dbg(dev
, "Mapped DAI %s to CODEC %s\n",
3534 dai
->name
, codec
->name
);
3540 list_add(&dai
->list
, &dai_list
);
3542 mutex_unlock(&client_mutex
);
3544 pr_debug("Registered DAI '%s'\n", dai
->name
);
3548 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3551 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3553 * @dai: DAI to unregister
3555 void snd_soc_unregister_dai(struct device
*dev
)
3557 struct snd_soc_dai
*dai
;
3559 list_for_each_entry(dai
, &dai_list
, list
) {
3560 if (dev
== dai
->dev
)
3566 mutex_lock(&client_mutex
);
3567 list_del(&dai
->list
);
3568 mutex_unlock(&client_mutex
);
3570 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3574 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3577 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3579 * @dai: Array of DAIs to register
3580 * @count: Number of DAIs
3582 int snd_soc_register_dais(struct device
*dev
,
3583 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3585 struct snd_soc_codec
*codec
;
3586 struct snd_soc_dai
*dai
;
3589 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3591 for (i
= 0; i
< count
; i
++) {
3593 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3599 /* create DAI component name */
3600 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3601 if (dai
->name
== NULL
) {
3608 dai
->driver
= &dai_drv
[i
];
3609 if (dai
->driver
->id
)
3610 dai
->id
= dai
->driver
->id
;
3613 dai
->dapm
.dev
= dev
;
3614 if (!dai
->driver
->ops
)
3615 dai
->driver
->ops
= &null_dai_ops
;
3617 mutex_lock(&client_mutex
);
3619 list_for_each_entry(codec
, &codec_list
, list
) {
3620 if (codec
->dev
== dev
) {
3621 dev_dbg(dev
, "Mapped DAI %s to CODEC %s\n",
3622 dai
->name
, codec
->name
);
3628 list_add(&dai
->list
, &dai_list
);
3630 mutex_unlock(&client_mutex
);
3632 pr_debug("Registered DAI '%s'\n", dai
->name
);
3638 for (i
--; i
>= 0; i
--)
3639 snd_soc_unregister_dai(dev
);
3643 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3646 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3648 * @dai: Array of DAIs to unregister
3649 * @count: Number of DAIs
3651 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3655 for (i
= 0; i
< count
; i
++)
3656 snd_soc_unregister_dai(dev
);
3658 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3661 * snd_soc_register_platform - Register a platform with the ASoC core
3663 * @platform: platform to register
3665 int snd_soc_register_platform(struct device
*dev
,
3666 struct snd_soc_platform_driver
*platform_drv
)
3668 struct snd_soc_platform
*platform
;
3670 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3672 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3673 if (platform
== NULL
)
3676 /* create platform component name */
3677 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3678 if (platform
->name
== NULL
) {
3683 platform
->dev
= dev
;
3684 platform
->driver
= platform_drv
;
3685 platform
->dapm
.dev
= dev
;
3686 platform
->dapm
.platform
= platform
;
3687 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3688 mutex_init(&platform
->mutex
);
3690 mutex_lock(&client_mutex
);
3691 list_add(&platform
->list
, &platform_list
);
3692 mutex_unlock(&client_mutex
);
3694 pr_debug("Registered platform '%s'\n", platform
->name
);
3698 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3701 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3703 * @platform: platform to unregister
3705 void snd_soc_unregister_platform(struct device
*dev
)
3707 struct snd_soc_platform
*platform
;
3709 list_for_each_entry(platform
, &platform_list
, list
) {
3710 if (dev
== platform
->dev
)
3716 mutex_lock(&client_mutex
);
3717 list_del(&platform
->list
);
3718 mutex_unlock(&client_mutex
);
3720 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3721 kfree(platform
->name
);
3724 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3726 static u64 codec_format_map
[] = {
3727 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3728 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3729 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3730 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3731 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3732 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3733 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3734 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3735 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3736 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3737 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3738 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3739 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3740 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3741 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3742 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3745 /* Fix up the DAI formats for endianness: codecs don't actually see
3746 * the endianness of the data but we're using the CPU format
3747 * definitions which do need to include endianness so we ensure that
3748 * codec DAIs always have both big and little endian variants set.
3750 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3754 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3755 if (stream
->formats
& codec_format_map
[i
])
3756 stream
->formats
|= codec_format_map
[i
];
3760 * snd_soc_register_codec - Register a codec with the ASoC core
3762 * @codec: codec to register
3764 int snd_soc_register_codec(struct device
*dev
,
3765 const struct snd_soc_codec_driver
*codec_drv
,
3766 struct snd_soc_dai_driver
*dai_drv
,
3770 struct snd_soc_codec
*codec
;
3773 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3775 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3779 /* create CODEC component name */
3780 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3781 if (codec
->name
== NULL
) {
3786 if (codec_drv
->compress_type
)
3787 codec
->compress_type
= codec_drv
->compress_type
;
3789 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3791 codec
->write
= codec_drv
->write
;
3792 codec
->read
= codec_drv
->read
;
3793 codec
->volatile_register
= codec_drv
->volatile_register
;
3794 codec
->readable_register
= codec_drv
->readable_register
;
3795 codec
->writable_register
= codec_drv
->writable_register
;
3796 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
3797 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3798 codec
->dapm
.dev
= dev
;
3799 codec
->dapm
.codec
= codec
;
3800 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3801 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3803 codec
->driver
= codec_drv
;
3804 codec
->num_dai
= num_dai
;
3805 mutex_init(&codec
->mutex
);
3807 /* allocate CODEC register cache */
3808 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3809 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3810 codec
->reg_size
= reg_size
;
3811 /* it is necessary to make a copy of the default register cache
3812 * because in the case of using a compression type that requires
3813 * the default register cache to be marked as __devinitconst the
3814 * kernel might have freed the array by the time we initialize
3817 if (codec_drv
->reg_cache_default
) {
3818 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3819 reg_size
, GFP_KERNEL
);
3820 if (!codec
->reg_def_copy
) {
3827 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
3828 if (!codec
->volatile_register
)
3829 codec
->volatile_register
= snd_soc_default_volatile_register
;
3830 if (!codec
->readable_register
)
3831 codec
->readable_register
= snd_soc_default_readable_register
;
3832 if (!codec
->writable_register
)
3833 codec
->writable_register
= snd_soc_default_writable_register
;
3836 for (i
= 0; i
< num_dai
; i
++) {
3837 fixup_codec_formats(&dai_drv
[i
].playback
);
3838 fixup_codec_formats(&dai_drv
[i
].capture
);
3841 mutex_lock(&client_mutex
);
3842 list_add(&codec
->list
, &codec_list
);
3843 mutex_unlock(&client_mutex
);
3845 /* register any DAIs */
3847 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
3849 dev_err(codec
->dev
, "Failed to regster DAIs: %d\n",
3853 pr_debug("Registered codec '%s'\n", codec
->name
);
3857 kfree(codec
->reg_def_copy
);
3858 codec
->reg_def_copy
= NULL
;
3863 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
3866 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3868 * @codec: codec to unregister
3870 void snd_soc_unregister_codec(struct device
*dev
)
3872 struct snd_soc_codec
*codec
;
3875 list_for_each_entry(codec
, &codec_list
, list
) {
3876 if (dev
== codec
->dev
)
3883 for (i
= 0; i
< codec
->num_dai
; i
++)
3884 snd_soc_unregister_dai(dev
);
3886 mutex_lock(&client_mutex
);
3887 list_del(&codec
->list
);
3888 mutex_unlock(&client_mutex
);
3890 pr_debug("Unregistered codec '%s'\n", codec
->name
);
3892 snd_soc_cache_exit(codec
);
3893 kfree(codec
->reg_def_copy
);
3897 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
3899 /* Retrieve a card's name from device tree */
3900 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
3901 const char *propname
)
3903 struct device_node
*np
= card
->dev
->of_node
;
3906 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
3908 * EINVAL means the property does not exist. This is fine providing
3909 * card->name was previously set, which is checked later in
3910 * snd_soc_register_card.
3912 if (ret
< 0 && ret
!= -EINVAL
) {
3914 "Property '%s' could not be read: %d\n",
3921 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
3923 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
3924 const char *propname
)
3926 struct device_node
*np
= card
->dev
->of_node
;
3928 struct snd_soc_dapm_route
*routes
;
3931 num_routes
= of_property_count_strings(np
, propname
);
3932 if (num_routes
< 0 || num_routes
& 1) {
3934 "Property '%s' does not exist or its length is not even\n",
3941 "Property '%s's length is zero\n",
3946 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
3950 "Could not allocate DAPM route table\n");
3954 for (i
= 0; i
< num_routes
; i
++) {
3955 ret
= of_property_read_string_index(np
, propname
,
3956 2 * i
, &routes
[i
].sink
);
3959 "Property '%s' index %d could not be read: %d\n",
3960 propname
, 2 * i
, ret
);
3963 ret
= of_property_read_string_index(np
, propname
,
3964 (2 * i
) + 1, &routes
[i
].source
);
3967 "Property '%s' index %d could not be read: %d\n",
3968 propname
, (2 * i
) + 1, ret
);
3973 card
->num_dapm_routes
= num_routes
;
3974 card
->dapm_routes
= routes
;
3978 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
3980 static int __init
snd_soc_init(void)
3982 #ifdef CONFIG_DEBUG_FS
3983 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
3984 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
3985 pr_warn("ASoC: Failed to create debugfs directory\n");
3986 snd_soc_debugfs_root
= NULL
;
3989 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
3991 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3993 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
3995 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
3997 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
3998 &platform_list_fops
))
3999 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4002 snd_soc_util_init();
4004 return platform_driver_register(&soc_driver
);
4006 module_init(snd_soc_init
);
4008 static void __exit
snd_soc_exit(void)
4010 snd_soc_util_exit();
4012 #ifdef CONFIG_DEBUG_FS
4013 debugfs_remove_recursive(snd_soc_debugfs_root
);
4015 platform_driver_unregister(&soc_driver
);
4017 module_exit(snd_soc_exit
);
4019 /* Module information */
4020 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4021 MODULE_DESCRIPTION("ALSA SoC Core");
4022 MODULE_LICENSE("GPL");
4023 MODULE_ALIAS("platform:soc-audio");