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 int soc_remove_platform(struct snd_soc_platform
*platform
)
905 if (platform
->driver
->remove
) {
906 ret
= platform
->driver
->remove(platform
);
908 pr_err("asoc: failed to remove %s: %d\n",
909 platform
->name
, ret
);
912 /* Make sure all DAPM widgets are freed */
913 snd_soc_dapm_free(&platform
->dapm
);
915 soc_cleanup_platform_debugfs(platform
);
916 platform
->probed
= 0;
917 list_del(&platform
->card_list
);
918 module_put(platform
->dev
->driver
->owner
);
923 static void soc_remove_codec(struct snd_soc_codec
*codec
)
927 if (codec
->driver
->remove
) {
928 err
= codec
->driver
->remove(codec
);
931 "asoc: failed to remove %s: %d\n",
935 /* Make sure all DAPM widgets are freed */
936 snd_soc_dapm_free(&codec
->dapm
);
938 soc_cleanup_codec_debugfs(codec
);
940 list_del(&codec
->card_list
);
941 module_put(codec
->dev
->driver
->owner
);
944 static void soc_remove_link_dais(struct snd_soc_card
*card
, int num
, int order
)
946 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
947 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
950 /* unregister the rtd device */
951 if (rtd
->dev_registered
) {
952 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
953 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
954 device_unregister(rtd
->dev
);
955 rtd
->dev_registered
= 0;
958 /* remove the CODEC DAI */
959 if (codec_dai
&& codec_dai
->probed
&&
960 codec_dai
->driver
->remove_order
== order
) {
961 if (codec_dai
->driver
->remove
) {
962 err
= codec_dai
->driver
->remove(codec_dai
);
964 pr_err("asoc: failed to remove %s: %d\n",
965 codec_dai
->name
, err
);
967 codec_dai
->probed
= 0;
968 list_del(&codec_dai
->card_list
);
971 /* remove the cpu_dai */
972 if (cpu_dai
&& cpu_dai
->probed
&&
973 cpu_dai
->driver
->remove_order
== order
) {
974 if (cpu_dai
->driver
->remove
) {
975 err
= cpu_dai
->driver
->remove(cpu_dai
);
977 pr_err("asoc: failed to remove %s: %d\n",
981 list_del(&cpu_dai
->card_list
);
983 if (!cpu_dai
->codec
) {
984 snd_soc_dapm_free(&cpu_dai
->dapm
);
985 module_put(cpu_dai
->dev
->driver
->owner
);
990 static void soc_remove_link_components(struct snd_soc_card
*card
, int num
,
993 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
994 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
995 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
996 struct snd_soc_platform
*platform
= rtd
->platform
;
997 struct snd_soc_codec
*codec
;
999 /* remove the platform */
1000 if (platform
&& platform
->probed
&&
1001 platform
->driver
->remove_order
== order
) {
1002 soc_remove_platform(platform
);
1005 /* remove the CODEC-side CODEC */
1007 codec
= codec_dai
->codec
;
1008 if (codec
&& codec
->probed
&&
1009 codec
->driver
->remove_order
== order
)
1010 soc_remove_codec(codec
);
1013 /* remove any CPU-side CODEC */
1015 codec
= cpu_dai
->codec
;
1016 if (codec
&& codec
->probed
&&
1017 codec
->driver
->remove_order
== order
)
1018 soc_remove_codec(codec
);
1022 static void soc_remove_dai_links(struct snd_soc_card
*card
)
1026 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1028 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1029 soc_remove_link_dais(card
, dai
, order
);
1032 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1034 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1035 soc_remove_link_components(card
, dai
, order
);
1041 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1042 struct snd_soc_codec
*codec
)
1046 if (card
->codec_conf
== NULL
)
1049 for (i
= 0; i
< card
->num_configs
; i
++) {
1050 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1051 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
1052 codec
->name_prefix
= map
->name_prefix
;
1058 static int soc_probe_codec(struct snd_soc_card
*card
,
1059 struct snd_soc_codec
*codec
)
1062 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
1063 struct snd_soc_dai
*dai
;
1066 codec
->dapm
.card
= card
;
1067 soc_set_name_prefix(card
, codec
);
1069 if (!try_module_get(codec
->dev
->driver
->owner
))
1072 soc_init_codec_debugfs(codec
);
1074 if (driver
->dapm_widgets
)
1075 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
1076 driver
->num_dapm_widgets
);
1078 /* Create DAPM widgets for each DAI stream */
1079 list_for_each_entry(dai
, &dai_list
, list
) {
1080 if (dai
->dev
!= codec
->dev
)
1083 snd_soc_dapm_new_dai_widgets(&codec
->dapm
, dai
);
1086 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
1088 if (driver
->probe
) {
1089 ret
= driver
->probe(codec
);
1092 "asoc: failed to probe CODEC %s: %d\n",
1098 /* If the driver didn't set I/O up try regmap */
1099 if (!codec
->control_data
)
1100 snd_soc_codec_set_cache_io(codec
, 0, 0, SND_SOC_REGMAP
);
1102 if (driver
->controls
)
1103 snd_soc_add_codec_controls(codec
, driver
->controls
,
1104 driver
->num_controls
);
1105 if (driver
->dapm_routes
)
1106 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1107 driver
->num_dapm_routes
);
1109 /* mark codec as probed and add to card codec list */
1111 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1112 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1117 soc_cleanup_codec_debugfs(codec
);
1118 module_put(codec
->dev
->driver
->owner
);
1123 static int soc_probe_platform(struct snd_soc_card
*card
,
1124 struct snd_soc_platform
*platform
)
1127 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1128 struct snd_soc_dai
*dai
;
1130 platform
->card
= card
;
1131 platform
->dapm
.card
= card
;
1133 if (!try_module_get(platform
->dev
->driver
->owner
))
1136 soc_init_platform_debugfs(platform
);
1138 if (driver
->dapm_widgets
)
1139 snd_soc_dapm_new_controls(&platform
->dapm
,
1140 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1142 /* Create DAPM widgets for each DAI stream */
1143 list_for_each_entry(dai
, &dai_list
, list
) {
1144 if (dai
->dev
!= platform
->dev
)
1147 snd_soc_dapm_new_dai_widgets(&platform
->dapm
, dai
);
1150 platform
->dapm
.idle_bias_off
= 1;
1152 if (driver
->probe
) {
1153 ret
= driver
->probe(platform
);
1155 dev_err(platform
->dev
,
1156 "asoc: failed to probe platform %s: %d\n",
1157 platform
->name
, ret
);
1162 if (driver
->controls
)
1163 snd_soc_add_platform_controls(platform
, driver
->controls
,
1164 driver
->num_controls
);
1165 if (driver
->dapm_routes
)
1166 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1167 driver
->num_dapm_routes
);
1169 /* mark platform as probed and add to card platform list */
1170 platform
->probed
= 1;
1171 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1172 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1177 soc_cleanup_platform_debugfs(platform
);
1178 module_put(platform
->dev
->driver
->owner
);
1183 static void rtd_release(struct device
*dev
)
1188 static int soc_post_component_init(struct snd_soc_card
*card
,
1189 struct snd_soc_codec
*codec
,
1190 int num
, int dailess
)
1192 struct snd_soc_dai_link
*dai_link
= NULL
;
1193 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1194 struct snd_soc_pcm_runtime
*rtd
;
1195 const char *temp
, *name
;
1199 dai_link
= &card
->dai_link
[num
];
1200 rtd
= &card
->rtd
[num
];
1201 name
= dai_link
->name
;
1203 aux_dev
= &card
->aux_dev
[num
];
1204 rtd
= &card
->rtd_aux
[num
];
1205 name
= aux_dev
->name
;
1209 /* Make sure all DAPM widgets are instantiated */
1210 snd_soc_dapm_new_widgets(&codec
->dapm
);
1212 /* machine controls, routes and widgets are not prefixed */
1213 temp
= codec
->name_prefix
;
1214 codec
->name_prefix
= NULL
;
1216 /* do machine specific initialization */
1217 if (!dailess
&& dai_link
->init
)
1218 ret
= dai_link
->init(rtd
);
1219 else if (dailess
&& aux_dev
->init
)
1220 ret
= aux_dev
->init(&codec
->dapm
);
1222 dev_err(card
->dev
, "asoc: failed to init %s: %d\n", name
, ret
);
1225 codec
->name_prefix
= temp
;
1227 /* register the rtd device */
1230 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1233 device_initialize(rtd
->dev
);
1234 rtd
->dev
->parent
= card
->dev
;
1235 rtd
->dev
->release
= rtd_release
;
1236 rtd
->dev
->init_name
= name
;
1237 dev_set_drvdata(rtd
->dev
, rtd
);
1238 mutex_init(&rtd
->pcm_mutex
);
1239 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1240 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1241 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1242 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1243 ret
= device_add(rtd
->dev
);
1246 "asoc: failed to register runtime device: %d\n", ret
);
1249 rtd
->dev_registered
= 1;
1251 /* add DAPM sysfs entries for this codec */
1252 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1255 "asoc: failed to add codec dapm sysfs entries: %d\n",
1258 /* add codec sysfs entries */
1259 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1262 "asoc: failed to add codec sysfs files: %d\n", ret
);
1264 #ifdef CONFIG_DEBUG_FS
1265 /* add DPCM sysfs entries */
1266 if (!dailess
&& !dai_link
->dynamic
)
1269 ret
= soc_dpcm_debugfs_add(rtd
);
1271 dev_err(rtd
->dev
, "asoc: failed to add dpcm sysfs entries: %d\n", ret
);
1278 static int soc_probe_link_components(struct snd_soc_card
*card
, int num
,
1281 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1282 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1283 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1284 struct snd_soc_platform
*platform
= rtd
->platform
;
1287 /* probe the CPU-side component, if it is a CODEC */
1288 if (cpu_dai
->codec
&&
1289 !cpu_dai
->codec
->probed
&&
1290 cpu_dai
->codec
->driver
->probe_order
== order
) {
1291 ret
= soc_probe_codec(card
, cpu_dai
->codec
);
1296 /* probe the CODEC-side component */
1297 if (!codec_dai
->codec
->probed
&&
1298 codec_dai
->codec
->driver
->probe_order
== order
) {
1299 ret
= soc_probe_codec(card
, codec_dai
->codec
);
1304 /* probe the platform */
1305 if (!platform
->probed
&&
1306 platform
->driver
->probe_order
== order
) {
1307 ret
= soc_probe_platform(card
, platform
);
1315 static int soc_probe_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1317 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1318 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1319 struct snd_soc_codec
*codec
= rtd
->codec
;
1320 struct snd_soc_platform
*platform
= rtd
->platform
;
1321 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1322 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1323 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1326 dev_dbg(card
->dev
, "probe %s dai link %d late %d\n",
1327 card
->name
, num
, order
);
1329 /* config components */
1330 cpu_dai
->platform
= platform
;
1331 codec_dai
->card
= card
;
1332 cpu_dai
->card
= card
;
1334 /* set default power off timeout */
1335 rtd
->pmdown_time
= pmdown_time
;
1337 /* probe the cpu_dai */
1338 if (!cpu_dai
->probed
&&
1339 cpu_dai
->driver
->probe_order
== order
) {
1340 if (!cpu_dai
->codec
) {
1341 cpu_dai
->dapm
.card
= card
;
1342 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1345 list_add(&cpu_dai
->dapm
.list
, &card
->dapm_list
);
1346 snd_soc_dapm_new_dai_widgets(&cpu_dai
->dapm
, cpu_dai
);
1349 if (cpu_dai
->driver
->probe
) {
1350 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1352 pr_err("asoc: failed to probe CPU DAI %s: %d\n",
1353 cpu_dai
->name
, ret
);
1354 module_put(cpu_dai
->dev
->driver
->owner
);
1358 cpu_dai
->probed
= 1;
1359 /* mark cpu_dai as probed and add to card dai list */
1360 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1363 /* probe the CODEC DAI */
1364 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1365 if (codec_dai
->driver
->probe
) {
1366 ret
= codec_dai
->driver
->probe(codec_dai
);
1368 pr_err("asoc: failed to probe CODEC DAI %s: %d\n",
1369 codec_dai
->name
, ret
);
1374 /* mark codec_dai as probed and add to card dai list */
1375 codec_dai
->probed
= 1;
1376 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1379 /* complete DAI probe during last probe */
1380 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1383 ret
= soc_post_component_init(card
, codec
, num
, 0);
1387 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1389 pr_warn("asoc: failed to add pmdown_time sysfs:%d\n", ret
);
1391 if (!dai_link
->params
) {
1392 /* create the pcm */
1393 ret
= soc_new_pcm(rtd
, num
);
1395 pr_err("asoc: can't create pcm %s :%d\n",
1396 dai_link
->stream_name
, ret
);
1400 /* link the DAI widgets */
1401 play_w
= codec_dai
->playback_widget
;
1402 capture_w
= cpu_dai
->capture_widget
;
1403 if (play_w
&& capture_w
) {
1404 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1407 dev_err(card
->dev
, "Can't link %s to %s: %d\n",
1408 play_w
->name
, capture_w
->name
, ret
);
1413 play_w
= cpu_dai
->playback_widget
;
1414 capture_w
= codec_dai
->capture_widget
;
1415 if (play_w
&& capture_w
) {
1416 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1419 dev_err(card
->dev
, "Can't link %s to %s: %d\n",
1420 play_w
->name
, capture_w
->name
, ret
);
1426 /* add platform data for AC97 devices */
1427 if (rtd
->codec_dai
->driver
->ac97_control
)
1428 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1433 #ifdef CONFIG_SND_SOC_AC97_BUS
1434 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1438 /* Only instantiate AC97 if not already done by the adaptor
1439 * for the generic AC97 subsystem.
1441 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1443 * It is possible that the AC97 device is already registered to
1444 * the device subsystem. This happens when the device is created
1445 * via snd_ac97_mixer(). Currently only SoC codec that does so
1446 * is the generic AC97 glue but others migh emerge.
1448 * In those cases we don't try to register the device again.
1450 if (!rtd
->codec
->ac97_created
)
1453 ret
= soc_ac97_dev_register(rtd
->codec
);
1455 pr_err("asoc: AC97 device register failed:%d\n", ret
);
1459 rtd
->codec
->ac97_registered
= 1;
1464 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1466 if (codec
->ac97_registered
) {
1467 soc_ac97_dev_unregister(codec
);
1468 codec
->ac97_registered
= 0;
1473 static int soc_check_aux_dev(struct snd_soc_card
*card
, int num
)
1475 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1476 struct snd_soc_codec
*codec
;
1478 /* find CODEC from registered CODECs*/
1479 list_for_each_entry(codec
, &codec_list
, list
) {
1480 if (!strcmp(codec
->name
, aux_dev
->codec_name
))
1484 return -EPROBE_DEFER
;
1487 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1489 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1490 struct snd_soc_codec
*codec
;
1493 /* find CODEC from registered CODECs*/
1494 list_for_each_entry(codec
, &codec_list
, list
) {
1495 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1496 if (codec
->probed
) {
1498 "asoc: codec already probed");
1505 /* codec not found */
1506 dev_err(card
->dev
, "asoc: codec %s not found", aux_dev
->codec_name
);
1507 return -EPROBE_DEFER
;
1510 ret
= soc_probe_codec(card
, codec
);
1514 ret
= soc_post_component_init(card
, codec
, num
, 1);
1520 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1522 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1523 struct snd_soc_codec
*codec
= rtd
->codec
;
1525 /* unregister the rtd device */
1526 if (rtd
->dev_registered
) {
1527 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1528 device_del(rtd
->dev
);
1529 rtd
->dev_registered
= 0;
1532 if (codec
&& codec
->probed
)
1533 soc_remove_codec(codec
);
1536 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1537 enum snd_soc_compress_type compress_type
)
1541 if (codec
->cache_init
)
1544 /* override the compress_type if necessary */
1545 if (compress_type
&& codec
->compress_type
!= compress_type
)
1546 codec
->compress_type
= compress_type
;
1547 ret
= snd_soc_cache_init(codec
);
1549 dev_err(codec
->dev
, "Failed to set cache compression type: %d\n",
1553 codec
->cache_init
= 1;
1557 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1559 struct snd_soc_codec
*codec
;
1560 struct snd_soc_codec_conf
*codec_conf
;
1561 enum snd_soc_compress_type compress_type
;
1562 struct snd_soc_dai_link
*dai_link
;
1563 int ret
, i
, order
, dai_fmt
;
1565 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1568 for (i
= 0; i
< card
->num_links
; i
++) {
1569 ret
= soc_bind_dai_link(card
, i
);
1574 /* check aux_devs too */
1575 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1576 ret
= soc_check_aux_dev(card
, i
);
1581 /* initialize the register cache for each available codec */
1582 list_for_each_entry(codec
, &codec_list
, list
) {
1583 if (codec
->cache_init
)
1585 /* by default we don't override the compress_type */
1587 /* check to see if we need to override the compress_type */
1588 for (i
= 0; i
< card
->num_configs
; ++i
) {
1589 codec_conf
= &card
->codec_conf
[i
];
1590 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1591 compress_type
= codec_conf
->compress_type
;
1592 if (compress_type
&& compress_type
1593 != codec
->compress_type
)
1597 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1602 /* card bind complete so register a sound card */
1603 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1604 card
->owner
, 0, &card
->snd_card
);
1606 pr_err("asoc: can't create sound card for card %s: %d\n",
1610 card
->snd_card
->dev
= card
->dev
;
1612 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1613 card
->dapm
.dev
= card
->dev
;
1614 card
->dapm
.card
= card
;
1615 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1617 #ifdef CONFIG_DEBUG_FS
1618 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1621 #ifdef CONFIG_PM_SLEEP
1622 /* deferred resume work */
1623 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1626 if (card
->dapm_widgets
)
1627 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1628 card
->num_dapm_widgets
);
1630 /* initialise the sound card only once */
1632 ret
= card
->probe(card
);
1634 goto card_probe_error
;
1637 /* probe all components used by DAI links on this card */
1638 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1640 for (i
= 0; i
< card
->num_links
; i
++) {
1641 ret
= soc_probe_link_components(card
, i
, order
);
1643 pr_err("asoc: failed to instantiate card %s: %d\n",
1650 /* probe all DAI links on this card */
1651 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1653 for (i
= 0; i
< card
->num_links
; i
++) {
1654 ret
= soc_probe_link_dais(card
, i
, order
);
1656 pr_err("asoc: failed to instantiate card %s: %d\n",
1663 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1664 ret
= soc_probe_aux_dev(card
, i
);
1666 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1668 goto probe_aux_dev_err
;
1672 snd_soc_dapm_link_dai_widgets(card
);
1675 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1677 if (card
->dapm_routes
)
1678 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1679 card
->num_dapm_routes
);
1681 snd_soc_dapm_new_widgets(&card
->dapm
);
1683 for (i
= 0; i
< card
->num_links
; i
++) {
1684 dai_link
= &card
->dai_link
[i
];
1685 dai_fmt
= dai_link
->dai_fmt
;
1688 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1690 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1691 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1692 "Failed to set DAI format: %d\n",
1696 /* If this is a regular CPU link there will be a platform */
1698 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1699 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1701 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1702 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1703 "Failed to set DAI format: %d\n",
1705 } else if (dai_fmt
) {
1706 /* Flip the polarity for the "CPU" end */
1707 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1708 switch (dai_link
->dai_fmt
&
1709 SND_SOC_DAIFMT_MASTER_MASK
) {
1710 case SND_SOC_DAIFMT_CBM_CFM
:
1711 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1713 case SND_SOC_DAIFMT_CBM_CFS
:
1714 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1716 case SND_SOC_DAIFMT_CBS_CFM
:
1717 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1719 case SND_SOC_DAIFMT_CBS_CFS
:
1720 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1724 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1726 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1727 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1728 "Failed to set DAI format: %d\n",
1733 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1735 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1736 "%s", card
->long_name
? card
->long_name
: card
->name
);
1737 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1738 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1739 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1740 switch (card
->snd_card
->driver
[i
]) {
1746 if (!isalnum(card
->snd_card
->driver
[i
]))
1747 card
->snd_card
->driver
[i
] = '_';
1752 if (card
->late_probe
) {
1753 ret
= card
->late_probe(card
);
1755 dev_err(card
->dev
, "%s late_probe() failed: %d\n",
1757 goto probe_aux_dev_err
;
1761 snd_soc_dapm_new_widgets(&card
->dapm
);
1763 if (card
->fully_routed
)
1764 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1765 snd_soc_dapm_auto_nc_codec_pins(codec
);
1767 ret
= snd_card_register(card
->snd_card
);
1769 pr_err("asoc: failed to register soundcard for %s: %d\n",
1771 goto probe_aux_dev_err
;
1774 #ifdef CONFIG_SND_SOC_AC97_BUS
1775 /* register any AC97 codecs */
1776 for (i
= 0; i
< card
->num_rtd
; i
++) {
1777 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1779 pr_err("asoc: failed to register AC97 %s: %d\n",
1782 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1783 goto probe_aux_dev_err
;
1788 card
->instantiated
= 1;
1789 snd_soc_dapm_sync(&card
->dapm
);
1790 mutex_unlock(&card
->mutex
);
1795 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1796 soc_remove_aux_dev(card
, i
);
1799 soc_remove_dai_links(card
);
1805 snd_card_free(card
->snd_card
);
1808 mutex_unlock(&card
->mutex
);
1813 /* probes a new socdev */
1814 static int soc_probe(struct platform_device
*pdev
)
1816 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1820 * no card, so machine driver should be registering card
1821 * we should not be here in that case so ret error
1826 dev_warn(&pdev
->dev
,
1827 "ASoC machine %s should use snd_soc_register_card()\n",
1830 /* Bodge while we unpick instantiation */
1831 card
->dev
= &pdev
->dev
;
1833 ret
= snd_soc_register_card(card
);
1835 dev_err(&pdev
->dev
, "Failed to register card\n");
1842 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1846 /* make sure any delayed work runs */
1847 for (i
= 0; i
< card
->num_rtd
; i
++) {
1848 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1849 flush_delayed_work_sync(&rtd
->delayed_work
);
1852 /* remove auxiliary devices */
1853 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1854 soc_remove_aux_dev(card
, i
);
1856 /* remove and free each DAI */
1857 soc_remove_dai_links(card
);
1859 soc_cleanup_card_debugfs(card
);
1861 /* remove the card */
1865 snd_soc_dapm_free(&card
->dapm
);
1867 snd_card_free(card
->snd_card
);
1872 /* removes a socdev */
1873 static int soc_remove(struct platform_device
*pdev
)
1875 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1877 snd_soc_unregister_card(card
);
1881 int snd_soc_poweroff(struct device
*dev
)
1883 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1886 if (!card
->instantiated
)
1889 /* Flush out pmdown_time work - we actually do want to run it
1890 * now, we're shutting down so no imminent restart. */
1891 for (i
= 0; i
< card
->num_rtd
; i
++) {
1892 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1893 flush_delayed_work_sync(&rtd
->delayed_work
);
1896 snd_soc_dapm_shutdown(card
);
1900 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1902 const struct dev_pm_ops snd_soc_pm_ops
= {
1903 .suspend
= snd_soc_suspend
,
1904 .resume
= snd_soc_resume
,
1905 .freeze
= snd_soc_suspend
,
1906 .thaw
= snd_soc_resume
,
1907 .poweroff
= snd_soc_poweroff
,
1908 .restore
= snd_soc_resume
,
1910 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1912 /* ASoC platform driver */
1913 static struct platform_driver soc_driver
= {
1915 .name
= "soc-audio",
1916 .owner
= THIS_MODULE
,
1917 .pm
= &snd_soc_pm_ops
,
1920 .remove
= soc_remove
,
1924 * snd_soc_codec_volatile_register: Report if a register is volatile.
1926 * @codec: CODEC to query.
1927 * @reg: Register to query.
1929 * Boolean function indiciating if a CODEC register is volatile.
1931 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1934 if (codec
->volatile_register
)
1935 return codec
->volatile_register(codec
, reg
);
1939 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1942 * snd_soc_codec_readable_register: Report if a register is readable.
1944 * @codec: CODEC to query.
1945 * @reg: Register to query.
1947 * Boolean function indicating if a CODEC register is readable.
1949 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1952 if (codec
->readable_register
)
1953 return codec
->readable_register(codec
, reg
);
1957 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1960 * snd_soc_codec_writable_register: Report if a register is writable.
1962 * @codec: CODEC to query.
1963 * @reg: Register to query.
1965 * Boolean function indicating if a CODEC register is writable.
1967 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1970 if (codec
->writable_register
)
1971 return codec
->writable_register(codec
, reg
);
1975 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
1977 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
1982 if (!platform
->driver
->read
) {
1983 dev_err(platform
->dev
, "platform has no read back\n");
1987 ret
= platform
->driver
->read(platform
, reg
);
1988 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
1989 trace_snd_soc_preg_read(platform
, reg
, ret
);
1993 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
1995 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
1996 unsigned int reg
, unsigned int val
)
1998 if (!platform
->driver
->write
) {
1999 dev_err(platform
->dev
, "platform has no write back\n");
2003 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
2004 trace_snd_soc_preg_write(platform
, reg
, val
);
2005 return platform
->driver
->write(platform
, reg
, val
);
2007 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
2010 * snd_soc_new_ac97_codec - initailise AC97 device
2011 * @codec: audio codec
2012 * @ops: AC97 bus operations
2013 * @num: AC97 codec number
2015 * Initialises AC97 codec resources for use by ad-hoc devices only.
2017 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
2018 struct snd_ac97_bus_ops
*ops
, int num
)
2020 mutex_lock(&codec
->mutex
);
2022 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
2023 if (codec
->ac97
== NULL
) {
2024 mutex_unlock(&codec
->mutex
);
2028 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
2029 if (codec
->ac97
->bus
== NULL
) {
2032 mutex_unlock(&codec
->mutex
);
2036 codec
->ac97
->bus
->ops
= ops
;
2037 codec
->ac97
->num
= num
;
2040 * Mark the AC97 device to be created by us. This way we ensure that the
2041 * device will be registered with the device subsystem later on.
2043 codec
->ac97_created
= 1;
2045 mutex_unlock(&codec
->mutex
);
2048 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
2051 * snd_soc_free_ac97_codec - free AC97 codec device
2052 * @codec: audio codec
2054 * Frees AC97 codec device resources.
2056 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
2058 mutex_lock(&codec
->mutex
);
2059 #ifdef CONFIG_SND_SOC_AC97_BUS
2060 soc_unregister_ac97_dai_link(codec
);
2062 kfree(codec
->ac97
->bus
);
2065 codec
->ac97_created
= 0;
2066 mutex_unlock(&codec
->mutex
);
2068 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
2070 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
2074 ret
= codec
->read(codec
, reg
);
2075 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
2076 trace_snd_soc_reg_read(codec
, reg
, ret
);
2080 EXPORT_SYMBOL_GPL(snd_soc_read
);
2082 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
2083 unsigned int reg
, unsigned int val
)
2085 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
2086 trace_snd_soc_reg_write(codec
, reg
, val
);
2087 return codec
->write(codec
, reg
, val
);
2089 EXPORT_SYMBOL_GPL(snd_soc_write
);
2091 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
2092 unsigned int reg
, const void *data
, size_t len
)
2094 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
2096 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
2099 * snd_soc_update_bits - update codec register bits
2100 * @codec: audio codec
2101 * @reg: codec register
2102 * @mask: register mask
2105 * Writes new register value.
2107 * Returns 1 for change, 0 for no change, or negative error code.
2109 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2110 unsigned int mask
, unsigned int value
)
2113 unsigned int old
, new;
2116 if (codec
->using_regmap
) {
2117 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
2118 mask
, value
, &change
);
2120 ret
= snd_soc_read(codec
, reg
);
2125 new = (old
& ~mask
) | (value
& mask
);
2126 change
= old
!= new;
2128 ret
= snd_soc_write(codec
, reg
, new);
2136 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
2139 * snd_soc_update_bits_locked - update codec register bits
2140 * @codec: audio codec
2141 * @reg: codec register
2142 * @mask: register mask
2145 * Writes new register value, and takes the codec mutex.
2147 * Returns 1 for change else 0.
2149 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
2150 unsigned short reg
, unsigned int mask
,
2155 mutex_lock(&codec
->mutex
);
2156 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
2157 mutex_unlock(&codec
->mutex
);
2161 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
2164 * snd_soc_test_bits - test register for change
2165 * @codec: audio codec
2166 * @reg: codec register
2167 * @mask: register mask
2170 * Tests a register with a new value and checks if the new value is
2171 * different from the old value.
2173 * Returns 1 for change else 0.
2175 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2176 unsigned int mask
, unsigned int value
)
2179 unsigned int old
, new;
2181 old
= snd_soc_read(codec
, reg
);
2182 new = (old
& ~mask
) | value
;
2183 change
= old
!= new;
2187 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
2190 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
2191 * @substream: the pcm substream
2192 * @hw: the hardware parameters
2194 * Sets the substream runtime hardware parameters.
2196 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
2197 const struct snd_pcm_hardware
*hw
)
2199 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2200 runtime
->hw
.info
= hw
->info
;
2201 runtime
->hw
.formats
= hw
->formats
;
2202 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
2203 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
2204 runtime
->hw
.periods_min
= hw
->periods_min
;
2205 runtime
->hw
.periods_max
= hw
->periods_max
;
2206 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
2207 runtime
->hw
.fifo_size
= hw
->fifo_size
;
2210 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
2213 * snd_soc_cnew - create new control
2214 * @_template: control template
2215 * @data: control private data
2216 * @long_name: control long name
2217 * @prefix: control name prefix
2219 * Create a new mixer control from a template control.
2221 * Returns 0 for success, else error.
2223 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2224 void *data
, const char *long_name
,
2227 struct snd_kcontrol_new
template;
2228 struct snd_kcontrol
*kcontrol
;
2232 memcpy(&template, _template
, sizeof(template));
2236 long_name
= template.name
;
2239 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
2240 name
= kmalloc(name_len
, GFP_KERNEL
);
2244 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
2246 template.name
= name
;
2248 template.name
= long_name
;
2251 kcontrol
= snd_ctl_new1(&template, data
);
2257 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2259 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2260 const struct snd_kcontrol_new
*controls
, int num_controls
,
2261 const char *prefix
, void *data
)
2265 for (i
= 0; i
< num_controls
; i
++) {
2266 const struct snd_kcontrol_new
*control
= &controls
[i
];
2267 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2268 control
->name
, prefix
));
2270 dev_err(dev
, "Failed to add %s: %d\n", control
->name
, err
);
2279 * snd_soc_add_codec_controls - add an array of controls to a codec.
2280 * Convenience function to add a list of controls. Many codecs were
2281 * duplicating this code.
2283 * @codec: codec to add controls to
2284 * @controls: array of controls to add
2285 * @num_controls: number of elements in the array
2287 * Return 0 for success, else error.
2289 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2290 const struct snd_kcontrol_new
*controls
, int num_controls
)
2292 struct snd_card
*card
= codec
->card
->snd_card
;
2294 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2295 codec
->name_prefix
, codec
);
2297 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2300 * snd_soc_add_platform_controls - add an array of controls to a platform.
2301 * Convenience function to add a list of controls.
2303 * @platform: platform to add controls to
2304 * @controls: array of controls to add
2305 * @num_controls: number of elements in the array
2307 * Return 0 for success, else error.
2309 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2310 const struct snd_kcontrol_new
*controls
, int num_controls
)
2312 struct snd_card
*card
= platform
->card
->snd_card
;
2314 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2317 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2320 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2321 * Convenience function to add a list of controls.
2323 * @soc_card: SoC card to add controls to
2324 * @controls: array of controls to add
2325 * @num_controls: number of elements in the array
2327 * Return 0 for success, else error.
2329 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2330 const struct snd_kcontrol_new
*controls
, int num_controls
)
2332 struct snd_card
*card
= soc_card
->snd_card
;
2334 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2337 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2340 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2341 * Convienience function to add a list of controls.
2343 * @dai: DAI to add controls to
2344 * @controls: array of controls to add
2345 * @num_controls: number of elements in the array
2347 * Return 0 for success, else error.
2349 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2350 const struct snd_kcontrol_new
*controls
, int num_controls
)
2352 struct snd_card
*card
= dai
->card
->snd_card
;
2354 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2357 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2360 * snd_soc_info_enum_double - enumerated double mixer info callback
2361 * @kcontrol: mixer control
2362 * @uinfo: control element information
2364 * Callback to provide information about a double enumerated
2367 * Returns 0 for success.
2369 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2370 struct snd_ctl_elem_info
*uinfo
)
2372 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2374 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2375 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2376 uinfo
->value
.enumerated
.items
= e
->max
;
2378 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2379 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2380 strcpy(uinfo
->value
.enumerated
.name
,
2381 e
->texts
[uinfo
->value
.enumerated
.item
]);
2384 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2387 * snd_soc_get_enum_double - enumerated double mixer get callback
2388 * @kcontrol: mixer control
2389 * @ucontrol: control element information
2391 * Callback to get the value of a double enumerated mixer.
2393 * Returns 0 for success.
2395 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2396 struct snd_ctl_elem_value
*ucontrol
)
2398 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2399 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2400 unsigned int val
, bitmask
;
2402 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2404 val
= snd_soc_read(codec
, e
->reg
);
2405 ucontrol
->value
.enumerated
.item
[0]
2406 = (val
>> e
->shift_l
) & (bitmask
- 1);
2407 if (e
->shift_l
!= e
->shift_r
)
2408 ucontrol
->value
.enumerated
.item
[1] =
2409 (val
>> e
->shift_r
) & (bitmask
- 1);
2413 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2416 * snd_soc_put_enum_double - enumerated double mixer put callback
2417 * @kcontrol: mixer control
2418 * @ucontrol: control element information
2420 * Callback to set the value of a double enumerated mixer.
2422 * Returns 0 for success.
2424 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2425 struct snd_ctl_elem_value
*ucontrol
)
2427 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2428 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2430 unsigned int mask
, bitmask
;
2432 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
2434 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2436 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2437 mask
= (bitmask
- 1) << e
->shift_l
;
2438 if (e
->shift_l
!= e
->shift_r
) {
2439 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2441 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2442 mask
|= (bitmask
- 1) << e
->shift_r
;
2445 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2447 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2450 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2451 * @kcontrol: mixer control
2452 * @ucontrol: control element information
2454 * Callback to get the value of a double semi enumerated mixer.
2456 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2457 * used for handling bitfield coded enumeration for example.
2459 * Returns 0 for success.
2461 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2462 struct snd_ctl_elem_value
*ucontrol
)
2464 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2465 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2466 unsigned int reg_val
, val
, mux
;
2468 reg_val
= snd_soc_read(codec
, e
->reg
);
2469 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2470 for (mux
= 0; mux
< e
->max
; mux
++) {
2471 if (val
== e
->values
[mux
])
2474 ucontrol
->value
.enumerated
.item
[0] = mux
;
2475 if (e
->shift_l
!= e
->shift_r
) {
2476 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2477 for (mux
= 0; mux
< e
->max
; mux
++) {
2478 if (val
== e
->values
[mux
])
2481 ucontrol
->value
.enumerated
.item
[1] = mux
;
2486 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2489 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2490 * @kcontrol: mixer control
2491 * @ucontrol: control element information
2493 * Callback to set the value of a double semi enumerated mixer.
2495 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2496 * used for handling bitfield coded enumeration for example.
2498 * Returns 0 for success.
2500 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2501 struct snd_ctl_elem_value
*ucontrol
)
2503 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2504 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2508 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2510 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2511 mask
= e
->mask
<< e
->shift_l
;
2512 if (e
->shift_l
!= e
->shift_r
) {
2513 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2515 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2516 mask
|= e
->mask
<< e
->shift_r
;
2519 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2521 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2524 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2525 * @kcontrol: mixer control
2526 * @uinfo: control element information
2528 * Callback to provide information about an external enumerated
2531 * Returns 0 for success.
2533 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2534 struct snd_ctl_elem_info
*uinfo
)
2536 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2538 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2540 uinfo
->value
.enumerated
.items
= e
->max
;
2542 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2543 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2544 strcpy(uinfo
->value
.enumerated
.name
,
2545 e
->texts
[uinfo
->value
.enumerated
.item
]);
2548 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2551 * snd_soc_info_volsw_ext - external single mixer info callback
2552 * @kcontrol: mixer control
2553 * @uinfo: control element information
2555 * Callback to provide information about a single external mixer control.
2557 * Returns 0 for success.
2559 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2560 struct snd_ctl_elem_info
*uinfo
)
2562 int max
= kcontrol
->private_value
;
2564 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2565 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2567 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2570 uinfo
->value
.integer
.min
= 0;
2571 uinfo
->value
.integer
.max
= max
;
2574 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2577 * snd_soc_info_volsw - single mixer info callback
2578 * @kcontrol: mixer control
2579 * @uinfo: control element information
2581 * Callback to provide information about a single mixer control, or a double
2582 * mixer control that spans 2 registers.
2584 * Returns 0 for success.
2586 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2587 struct snd_ctl_elem_info
*uinfo
)
2589 struct soc_mixer_control
*mc
=
2590 (struct soc_mixer_control
*)kcontrol
->private_value
;
2593 if (!mc
->platform_max
)
2594 mc
->platform_max
= mc
->max
;
2595 platform_max
= mc
->platform_max
;
2597 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2598 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2600 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2602 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2603 uinfo
->value
.integer
.min
= 0;
2604 uinfo
->value
.integer
.max
= platform_max
;
2607 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2610 * snd_soc_get_volsw - single mixer get callback
2611 * @kcontrol: mixer control
2612 * @ucontrol: control element information
2614 * Callback to get the value of a single mixer control, or a double mixer
2615 * control that spans 2 registers.
2617 * Returns 0 for success.
2619 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2620 struct snd_ctl_elem_value
*ucontrol
)
2622 struct soc_mixer_control
*mc
=
2623 (struct soc_mixer_control
*)kcontrol
->private_value
;
2624 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2625 unsigned int reg
= mc
->reg
;
2626 unsigned int reg2
= mc
->rreg
;
2627 unsigned int shift
= mc
->shift
;
2628 unsigned int rshift
= mc
->rshift
;
2630 unsigned int mask
= (1 << fls(max
)) - 1;
2631 unsigned int invert
= mc
->invert
;
2633 ucontrol
->value
.integer
.value
[0] =
2634 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2636 ucontrol
->value
.integer
.value
[0] =
2637 max
- ucontrol
->value
.integer
.value
[0];
2639 if (snd_soc_volsw_is_stereo(mc
)) {
2641 ucontrol
->value
.integer
.value
[1] =
2642 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2644 ucontrol
->value
.integer
.value
[1] =
2645 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2647 ucontrol
->value
.integer
.value
[1] =
2648 max
- ucontrol
->value
.integer
.value
[1];
2653 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2656 * snd_soc_put_volsw - single mixer put callback
2657 * @kcontrol: mixer control
2658 * @ucontrol: control element information
2660 * Callback to set the value of a single mixer control, or a double mixer
2661 * control that spans 2 registers.
2663 * Returns 0 for success.
2665 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2666 struct snd_ctl_elem_value
*ucontrol
)
2668 struct soc_mixer_control
*mc
=
2669 (struct soc_mixer_control
*)kcontrol
->private_value
;
2670 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2671 unsigned int reg
= mc
->reg
;
2672 unsigned int reg2
= mc
->rreg
;
2673 unsigned int shift
= mc
->shift
;
2674 unsigned int rshift
= mc
->rshift
;
2676 unsigned int mask
= (1 << fls(max
)) - 1;
2677 unsigned int invert
= mc
->invert
;
2680 unsigned int val2
= 0;
2681 unsigned int val
, val_mask
;
2683 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2686 val_mask
= mask
<< shift
;
2688 if (snd_soc_volsw_is_stereo(mc
)) {
2689 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2693 val_mask
|= mask
<< rshift
;
2694 val
|= val2
<< rshift
;
2696 val2
= val2
<< shift
;
2700 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2705 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2709 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2712 * snd_soc_get_volsw_sx - single mixer get callback
2713 * @kcontrol: mixer control
2714 * @ucontrol: control element information
2716 * Callback to get the value of a single mixer control, or a double mixer
2717 * control that spans 2 registers.
2719 * Returns 0 for success.
2721 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2722 struct snd_ctl_elem_value
*ucontrol
)
2724 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2725 struct soc_mixer_control
*mc
=
2726 (struct soc_mixer_control
*)kcontrol
->private_value
;
2728 unsigned int reg
= mc
->reg
;
2729 unsigned int reg2
= mc
->rreg
;
2730 unsigned int shift
= mc
->shift
;
2731 unsigned int rshift
= mc
->rshift
;
2734 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2736 ucontrol
->value
.integer
.value
[0] =
2737 ((snd_soc_read(codec
, reg
) >> shift
) - min
) & mask
;
2739 if (snd_soc_volsw_is_stereo(mc
))
2740 ucontrol
->value
.integer
.value
[1] =
2741 ((snd_soc_read(codec
, reg2
) >> rshift
) - min
) & mask
;
2745 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2748 * snd_soc_put_volsw_sx - double mixer set callback
2749 * @kcontrol: mixer control
2750 * @uinfo: control element information
2752 * Callback to set the value of a double mixer control that spans 2 registers.
2754 * Returns 0 for success.
2756 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2757 struct snd_ctl_elem_value
*ucontrol
)
2759 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2760 struct soc_mixer_control
*mc
=
2761 (struct soc_mixer_control
*)kcontrol
->private_value
;
2763 unsigned int reg
= mc
->reg
;
2764 unsigned int reg2
= mc
->rreg
;
2765 unsigned int shift
= mc
->shift
;
2766 unsigned int rshift
= mc
->rshift
;
2769 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2771 unsigned short val
, val_mask
, val2
= 0;
2773 val_mask
= mask
<< shift
;
2774 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2777 if (snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
))
2780 if (snd_soc_volsw_is_stereo(mc
)) {
2781 val_mask
= mask
<< rshift
;
2782 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2783 val2
= val2
<< rshift
;
2785 if (snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
))
2790 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2793 * snd_soc_info_volsw_s8 - signed mixer info callback
2794 * @kcontrol: mixer control
2795 * @uinfo: control element information
2797 * Callback to provide information about a signed mixer control.
2799 * Returns 0 for success.
2801 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2802 struct snd_ctl_elem_info
*uinfo
)
2804 struct soc_mixer_control
*mc
=
2805 (struct soc_mixer_control
*)kcontrol
->private_value
;
2809 if (!mc
->platform_max
)
2810 mc
->platform_max
= mc
->max
;
2811 platform_max
= mc
->platform_max
;
2813 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2815 uinfo
->value
.integer
.min
= 0;
2816 uinfo
->value
.integer
.max
= platform_max
- min
;
2819 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2822 * snd_soc_get_volsw_s8 - signed mixer get callback
2823 * @kcontrol: mixer control
2824 * @ucontrol: control element information
2826 * Callback to get the value of a signed mixer control.
2828 * Returns 0 for success.
2830 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2831 struct snd_ctl_elem_value
*ucontrol
)
2833 struct soc_mixer_control
*mc
=
2834 (struct soc_mixer_control
*)kcontrol
->private_value
;
2835 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2836 unsigned int reg
= mc
->reg
;
2838 int val
= snd_soc_read(codec
, reg
);
2840 ucontrol
->value
.integer
.value
[0] =
2841 ((signed char)(val
& 0xff))-min
;
2842 ucontrol
->value
.integer
.value
[1] =
2843 ((signed char)((val
>> 8) & 0xff))-min
;
2846 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2849 * snd_soc_put_volsw_sgn - signed mixer put callback
2850 * @kcontrol: mixer control
2851 * @ucontrol: control element information
2853 * Callback to set the value of a signed mixer control.
2855 * Returns 0 for success.
2857 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2858 struct snd_ctl_elem_value
*ucontrol
)
2860 struct soc_mixer_control
*mc
=
2861 (struct soc_mixer_control
*)kcontrol
->private_value
;
2862 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2863 unsigned int reg
= mc
->reg
;
2867 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2868 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2870 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2872 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2875 * snd_soc_info_volsw_range - single mixer info callback with range.
2876 * @kcontrol: mixer control
2877 * @uinfo: control element information
2879 * Callback to provide information, within a range, about a single
2882 * returns 0 for success.
2884 int snd_soc_info_volsw_range(struct snd_kcontrol
*kcontrol
,
2885 struct snd_ctl_elem_info
*uinfo
)
2887 struct soc_mixer_control
*mc
=
2888 (struct soc_mixer_control
*)kcontrol
->private_value
;
2892 if (!mc
->platform_max
)
2893 mc
->platform_max
= mc
->max
;
2894 platform_max
= mc
->platform_max
;
2896 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2898 uinfo
->value
.integer
.min
= 0;
2899 uinfo
->value
.integer
.max
= platform_max
- min
;
2903 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range
);
2906 * snd_soc_put_volsw_range - single mixer put value callback with range.
2907 * @kcontrol: mixer control
2908 * @ucontrol: control element information
2910 * Callback to set the value, within a range, for a single mixer control.
2912 * Returns 0 for success.
2914 int snd_soc_put_volsw_range(struct snd_kcontrol
*kcontrol
,
2915 struct snd_ctl_elem_value
*ucontrol
)
2917 struct soc_mixer_control
*mc
=
2918 (struct soc_mixer_control
*)kcontrol
->private_value
;
2919 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2920 unsigned int reg
= mc
->reg
;
2921 unsigned int shift
= mc
->shift
;
2924 unsigned int mask
= (1 << fls(max
)) - 1;
2925 unsigned int invert
= mc
->invert
;
2926 unsigned int val
, val_mask
;
2928 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2931 val_mask
= mask
<< shift
;
2934 return snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2936 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range
);
2939 * snd_soc_get_volsw_range - single mixer get callback with range
2940 * @kcontrol: mixer control
2941 * @ucontrol: control element information
2943 * Callback to get the value, within a range, of a single mixer control.
2945 * Returns 0 for success.
2947 int snd_soc_get_volsw_range(struct snd_kcontrol
*kcontrol
,
2948 struct snd_ctl_elem_value
*ucontrol
)
2950 struct soc_mixer_control
*mc
=
2951 (struct soc_mixer_control
*)kcontrol
->private_value
;
2952 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2953 unsigned int reg
= mc
->reg
;
2954 unsigned int shift
= mc
->shift
;
2957 unsigned int mask
= (1 << fls(max
)) - 1;
2958 unsigned int invert
= mc
->invert
;
2960 ucontrol
->value
.integer
.value
[0] =
2961 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2963 ucontrol
->value
.integer
.value
[0] =
2964 max
- ucontrol
->value
.integer
.value
[0];
2965 ucontrol
->value
.integer
.value
[0] =
2966 ucontrol
->value
.integer
.value
[0] - min
;
2970 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range
);
2973 * snd_soc_limit_volume - Set new limit to an existing volume control.
2975 * @codec: where to look for the control
2976 * @name: Name of the control
2977 * @max: new maximum limit
2979 * Return 0 for success, else error.
2981 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2982 const char *name
, int max
)
2984 struct snd_card
*card
= codec
->card
->snd_card
;
2985 struct snd_kcontrol
*kctl
;
2986 struct soc_mixer_control
*mc
;
2990 /* Sanity check for name and max */
2991 if (unlikely(!name
|| max
<= 0))
2994 list_for_each_entry(kctl
, &card
->controls
, list
) {
2995 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
3001 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
3002 if (max
<= mc
->max
) {
3003 mc
->platform_max
= max
;
3009 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
3011 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
3012 struct snd_ctl_elem_info
*uinfo
)
3014 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3015 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3017 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3018 uinfo
->count
= params
->num_regs
* codec
->val_bytes
;
3022 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
3024 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
3025 struct snd_ctl_elem_value
*ucontrol
)
3027 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3028 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3031 if (codec
->using_regmap
)
3032 ret
= regmap_raw_read(codec
->control_data
, params
->base
,
3033 ucontrol
->value
.bytes
.data
,
3034 params
->num_regs
* codec
->val_bytes
);
3038 /* Hide any masked bytes to ensure consistent data reporting */
3039 if (ret
== 0 && params
->mask
) {
3040 switch (codec
->val_bytes
) {
3042 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
3045 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
3049 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
3059 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
3061 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
3062 struct snd_ctl_elem_value
*ucontrol
)
3064 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3065 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3070 if (!codec
->using_regmap
)
3073 data
= ucontrol
->value
.bytes
.data
;
3074 len
= params
->num_regs
* codec
->val_bytes
;
3077 * If we've got a mask then we need to preserve the register
3078 * bits. We shouldn't modify the incoming data so take a
3082 ret
= regmap_read(codec
->control_data
, params
->base
, &val
);
3086 val
&= params
->mask
;
3088 data
= kmemdup(data
, len
, GFP_KERNEL
);
3092 switch (codec
->val_bytes
) {
3094 ((u8
*)data
)[0] &= ~params
->mask
;
3095 ((u8
*)data
)[0] |= val
;
3098 ((u16
*)data
)[0] &= cpu_to_be16(~params
->mask
);
3099 ((u16
*)data
)[0] |= cpu_to_be16(val
);
3102 ((u32
*)data
)[0] &= cpu_to_be32(~params
->mask
);
3103 ((u32
*)data
)[0] |= cpu_to_be32(val
);
3110 ret
= regmap_raw_write(codec
->control_data
, params
->base
,
3118 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
3121 * snd_soc_info_xr_sx - signed multi register info callback
3122 * @kcontrol: mreg control
3123 * @uinfo: control element information
3125 * Callback to provide information of a control that can
3126 * span multiple codec registers which together
3127 * forms a single signed value in a MSB/LSB manner.
3129 * Returns 0 for success.
3131 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
3132 struct snd_ctl_elem_info
*uinfo
)
3134 struct soc_mreg_control
*mc
=
3135 (struct soc_mreg_control
*)kcontrol
->private_value
;
3136 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3138 uinfo
->value
.integer
.min
= mc
->min
;
3139 uinfo
->value
.integer
.max
= mc
->max
;
3143 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
3146 * snd_soc_get_xr_sx - signed multi register get callback
3147 * @kcontrol: mreg control
3148 * @ucontrol: control element information
3150 * Callback to get the value of a control that can span
3151 * multiple codec registers which together forms a single
3152 * signed value in a MSB/LSB manner. The control supports
3153 * specifying total no of bits used to allow for bitfields
3154 * across the multiple codec registers.
3156 * Returns 0 for success.
3158 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
3159 struct snd_ctl_elem_value
*ucontrol
)
3161 struct soc_mreg_control
*mc
=
3162 (struct soc_mreg_control
*)kcontrol
->private_value
;
3163 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3164 unsigned int regbase
= mc
->regbase
;
3165 unsigned int regcount
= mc
->regcount
;
3166 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3167 unsigned int regwmask
= (1<<regwshift
)-1;
3168 unsigned int invert
= mc
->invert
;
3169 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3173 unsigned long regval
;
3176 for (i
= 0; i
< regcount
; i
++) {
3177 regval
= snd_soc_read(codec
, regbase
+i
) & regwmask
;
3178 val
|= regval
<< (regwshift
*(regcount
-i
-1));
3181 if (min
< 0 && val
> max
)
3185 ucontrol
->value
.integer
.value
[0] = val
;
3189 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3192 * snd_soc_put_xr_sx - signed multi register get callback
3193 * @kcontrol: mreg control
3194 * @ucontrol: control element information
3196 * Callback to set the value of a control that can span
3197 * multiple codec registers which together forms a single
3198 * signed value in a MSB/LSB manner. The control supports
3199 * specifying total no of bits used to allow for bitfields
3200 * across the multiple codec registers.
3202 * Returns 0 for success.
3204 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3205 struct snd_ctl_elem_value
*ucontrol
)
3207 struct soc_mreg_control
*mc
=
3208 (struct soc_mreg_control
*)kcontrol
->private_value
;
3209 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3210 unsigned int regbase
= mc
->regbase
;
3211 unsigned int regcount
= mc
->regcount
;
3212 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3213 unsigned int regwmask
= (1<<regwshift
)-1;
3214 unsigned int invert
= mc
->invert
;
3215 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3217 long val
= ucontrol
->value
.integer
.value
[0];
3218 unsigned int i
, regval
, regmask
;
3224 for (i
= 0; i
< regcount
; i
++) {
3225 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3226 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3227 err
= snd_soc_update_bits_locked(codec
, regbase
+i
,
3235 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3238 * snd_soc_get_strobe - strobe get callback
3239 * @kcontrol: mixer control
3240 * @ucontrol: control element information
3242 * Callback get the value of a strobe mixer control.
3244 * Returns 0 for success.
3246 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3247 struct snd_ctl_elem_value
*ucontrol
)
3249 struct soc_mixer_control
*mc
=
3250 (struct soc_mixer_control
*)kcontrol
->private_value
;
3251 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3252 unsigned int reg
= mc
->reg
;
3253 unsigned int shift
= mc
->shift
;
3254 unsigned int mask
= 1 << shift
;
3255 unsigned int invert
= mc
->invert
!= 0;
3256 unsigned int val
= snd_soc_read(codec
, reg
) & mask
;
3258 if (shift
!= 0 && val
!= 0)
3260 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3264 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3267 * snd_soc_put_strobe - strobe put callback
3268 * @kcontrol: mixer control
3269 * @ucontrol: control element information
3271 * Callback strobe a register bit to high then low (or the inverse)
3272 * in one pass of a single mixer enum control.
3274 * Returns 1 for success.
3276 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3277 struct snd_ctl_elem_value
*ucontrol
)
3279 struct soc_mixer_control
*mc
=
3280 (struct soc_mixer_control
*)kcontrol
->private_value
;
3281 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3282 unsigned int reg
= mc
->reg
;
3283 unsigned int shift
= mc
->shift
;
3284 unsigned int mask
= 1 << shift
;
3285 unsigned int invert
= mc
->invert
!= 0;
3286 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3287 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3288 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3291 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val1
);
3295 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val2
);
3298 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3301 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3303 * @clk_id: DAI specific clock ID
3304 * @freq: new clock frequency in Hz
3305 * @dir: new clock direction - input/output.
3307 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3309 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3310 unsigned int freq
, int dir
)
3312 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3313 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3314 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3315 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3320 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3323 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3325 * @clk_id: DAI specific clock ID
3326 * @source: Source for the clock
3327 * @freq: new clock frequency in Hz
3328 * @dir: new clock direction - input/output.
3330 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3332 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3333 int source
, unsigned int freq
, int dir
)
3335 if (codec
->driver
->set_sysclk
)
3336 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3341 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3344 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3346 * @div_id: DAI specific clock divider ID
3347 * @div: new clock divisor.
3349 * Configures the clock dividers. This is used to derive the best DAI bit and
3350 * frame clocks from the system or master clock. It's best to set the DAI bit
3351 * and frame clocks as low as possible to save system power.
3353 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3354 int div_id
, int div
)
3356 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3357 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3361 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3364 * snd_soc_dai_set_pll - configure DAI PLL.
3366 * @pll_id: DAI specific PLL ID
3367 * @source: DAI specific source for the PLL
3368 * @freq_in: PLL input clock frequency in Hz
3369 * @freq_out: requested PLL output clock frequency in Hz
3371 * Configures and enables PLL to generate output clock based on input clock.
3373 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3374 unsigned int freq_in
, unsigned int freq_out
)
3376 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3377 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3379 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3380 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3385 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3388 * snd_soc_codec_set_pll - configure codec PLL.
3390 * @pll_id: DAI specific PLL ID
3391 * @source: DAI specific source for the PLL
3392 * @freq_in: PLL input clock frequency in Hz
3393 * @freq_out: requested PLL output clock frequency in Hz
3395 * Configures and enables PLL to generate output clock based on input clock.
3397 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3398 unsigned int freq_in
, unsigned int freq_out
)
3400 if (codec
->driver
->set_pll
)
3401 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3406 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3409 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3411 * @fmt: SND_SOC_DAIFMT_ format value.
3413 * Configures the DAI hardware format and clocking.
3415 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3417 if (dai
->driver
== NULL
)
3419 if (dai
->driver
->ops
->set_fmt
== NULL
)
3421 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3423 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3426 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3428 * @tx_mask: bitmask representing active TX slots.
3429 * @rx_mask: bitmask representing active RX slots.
3430 * @slots: Number of slots in use.
3431 * @slot_width: Width in bits for each slot.
3433 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3436 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3437 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3439 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3440 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3445 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3448 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3450 * @tx_num: how many TX channels
3451 * @tx_slot: pointer to an array which imply the TX slot number channel
3453 * @rx_num: how many RX channels
3454 * @rx_slot: pointer to an array which imply the RX slot number channel
3457 * configure the relationship between channel number and TDM slot number.
3459 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3460 unsigned int tx_num
, unsigned int *tx_slot
,
3461 unsigned int rx_num
, unsigned int *rx_slot
)
3463 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3464 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3469 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3472 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3474 * @tristate: tristate enable
3476 * Tristates the DAI so that others can use it.
3478 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3480 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3481 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3485 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3488 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3490 * @mute: mute enable
3492 * Mutes the DAI DAC.
3494 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
3496 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
3497 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3501 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3504 * snd_soc_register_card - Register a card with the ASoC core
3506 * @card: Card to register
3509 int snd_soc_register_card(struct snd_soc_card
*card
)
3513 if (!card
->name
|| !card
->dev
)
3516 for (i
= 0; i
< card
->num_links
; i
++) {
3517 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3520 * Codec must be specified by 1 of name or OF node,
3521 * not both or neither.
3523 if (!!link
->codec_name
== !!link
->codec_of_node
) {
3525 "Neither/both codec name/of_node are set for %s\n",
3529 /* Codec DAI name must be specified */
3530 if (!link
->codec_dai_name
) {
3531 dev_err(card
->dev
, "codec_dai_name not set for %s\n",
3537 * Platform may be specified by either name or OF node, but
3538 * can be left unspecified, and a dummy platform will be used.
3540 if (link
->platform_name
&& link
->platform_of_node
) {
3542 "Both platform name/of_node are set for %s\n", link
->name
);
3547 * CPU device may be specified by either name or OF node, but
3548 * can be left unspecified, and will be matched based on DAI
3551 if (link
->cpu_name
&& link
->cpu_of_node
) {
3553 "Neither/both cpu name/of_node are set for %s\n",
3558 * At least one of CPU DAI name or CPU device name/node must be
3561 if (!link
->cpu_dai_name
&&
3562 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3564 "Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3570 dev_set_drvdata(card
->dev
, card
);
3572 snd_soc_initialize_card_lists(card
);
3574 soc_init_card_debugfs(card
);
3576 card
->rtd
= devm_kzalloc(card
->dev
,
3577 sizeof(struct snd_soc_pcm_runtime
) *
3578 (card
->num_links
+ card
->num_aux_devs
),
3580 if (card
->rtd
== NULL
)
3583 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3585 for (i
= 0; i
< card
->num_links
; i
++)
3586 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3588 INIT_LIST_HEAD(&card
->list
);
3589 INIT_LIST_HEAD(&card
->dapm_dirty
);
3590 card
->instantiated
= 0;
3591 mutex_init(&card
->mutex
);
3592 mutex_init(&card
->dapm_mutex
);
3594 ret
= snd_soc_instantiate_card(card
);
3596 soc_cleanup_card_debugfs(card
);
3600 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3603 * snd_soc_unregister_card - Unregister a card with the ASoC core
3605 * @card: Card to unregister
3608 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3610 if (card
->instantiated
)
3611 soc_cleanup_card_resources(card
);
3612 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
3616 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3619 * Simplify DAI link configuration by removing ".-1" from device names
3620 * and sanitizing names.
3622 static char *fmt_single_name(struct device
*dev
, int *id
)
3624 char *found
, name
[NAME_SIZE
];
3627 if (dev_name(dev
) == NULL
)
3630 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3632 /* are we a "%s.%d" name (platform and SPI components) */
3633 found
= strstr(name
, dev
->driver
->name
);
3636 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3638 /* discard ID from name if ID == -1 */
3640 found
[strlen(dev
->driver
->name
)] = '\0';
3644 /* I2C component devices are named "bus-addr" */
3645 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3646 char tmp
[NAME_SIZE
];
3648 /* create unique ID number from I2C addr and bus */
3649 *id
= ((id1
& 0xffff) << 16) + id2
;
3651 /* sanitize component name for DAI link creation */
3652 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3653 strlcpy(name
, tmp
, NAME_SIZE
);
3658 return kstrdup(name
, GFP_KERNEL
);
3662 * Simplify DAI link naming for single devices with multiple DAIs by removing
3663 * any ".-1" and using the DAI name (instead of device name).
3665 static inline char *fmt_multiple_name(struct device
*dev
,
3666 struct snd_soc_dai_driver
*dai_drv
)
3668 if (dai_drv
->name
== NULL
) {
3669 pr_err("asoc: error - multiple DAI %s registered with no name\n",
3674 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3678 * snd_soc_register_dai - Register a DAI with the ASoC core
3680 * @dai: DAI to register
3682 int snd_soc_register_dai(struct device
*dev
,
3683 struct snd_soc_dai_driver
*dai_drv
)
3685 struct snd_soc_codec
*codec
;
3686 struct snd_soc_dai
*dai
;
3688 dev_dbg(dev
, "dai register %s\n", dev_name(dev
));
3690 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3694 /* create DAI component name */
3695 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3696 if (dai
->name
== NULL
) {
3702 dai
->driver
= dai_drv
;
3703 dai
->dapm
.dev
= dev
;
3704 if (!dai
->driver
->ops
)
3705 dai
->driver
->ops
= &null_dai_ops
;
3707 mutex_lock(&client_mutex
);
3709 list_for_each_entry(codec
, &codec_list
, list
) {
3710 if (codec
->dev
== dev
) {
3711 dev_dbg(dev
, "Mapped DAI %s to CODEC %s\n",
3712 dai
->name
, codec
->name
);
3718 list_add(&dai
->list
, &dai_list
);
3720 mutex_unlock(&client_mutex
);
3722 pr_debug("Registered DAI '%s'\n", dai
->name
);
3726 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3729 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3731 * @dai: DAI to unregister
3733 void snd_soc_unregister_dai(struct device
*dev
)
3735 struct snd_soc_dai
*dai
;
3737 list_for_each_entry(dai
, &dai_list
, list
) {
3738 if (dev
== dai
->dev
)
3744 mutex_lock(&client_mutex
);
3745 list_del(&dai
->list
);
3746 mutex_unlock(&client_mutex
);
3748 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
3752 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3755 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3757 * @dai: Array of DAIs to register
3758 * @count: Number of DAIs
3760 int snd_soc_register_dais(struct device
*dev
,
3761 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3763 struct snd_soc_codec
*codec
;
3764 struct snd_soc_dai
*dai
;
3767 dev_dbg(dev
, "dai register %s #%Zu\n", dev_name(dev
), count
);
3769 for (i
= 0; i
< count
; i
++) {
3771 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3777 /* create DAI component name */
3778 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3779 if (dai
->name
== NULL
) {
3786 dai
->driver
= &dai_drv
[i
];
3787 if (dai
->driver
->id
)
3788 dai
->id
= dai
->driver
->id
;
3791 dai
->dapm
.dev
= dev
;
3792 if (!dai
->driver
->ops
)
3793 dai
->driver
->ops
= &null_dai_ops
;
3795 mutex_lock(&client_mutex
);
3797 list_for_each_entry(codec
, &codec_list
, list
) {
3798 if (codec
->dev
== dev
) {
3799 dev_dbg(dev
, "Mapped DAI %s to CODEC %s\n",
3800 dai
->name
, codec
->name
);
3806 list_add(&dai
->list
, &dai_list
);
3808 mutex_unlock(&client_mutex
);
3810 pr_debug("Registered DAI '%s'\n", dai
->name
);
3816 for (i
--; i
>= 0; i
--)
3817 snd_soc_unregister_dai(dev
);
3821 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3824 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3826 * @dai: Array of DAIs to unregister
3827 * @count: Number of DAIs
3829 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3833 for (i
= 0; i
< count
; i
++)
3834 snd_soc_unregister_dai(dev
);
3836 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3839 * snd_soc_register_platform - Register a platform with the ASoC core
3841 * @platform: platform to register
3843 int snd_soc_register_platform(struct device
*dev
,
3844 struct snd_soc_platform_driver
*platform_drv
)
3846 struct snd_soc_platform
*platform
;
3848 dev_dbg(dev
, "platform register %s\n", dev_name(dev
));
3850 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3851 if (platform
== NULL
)
3854 /* create platform component name */
3855 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3856 if (platform
->name
== NULL
) {
3861 platform
->dev
= dev
;
3862 platform
->driver
= platform_drv
;
3863 platform
->dapm
.dev
= dev
;
3864 platform
->dapm
.platform
= platform
;
3865 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3866 mutex_init(&platform
->mutex
);
3868 mutex_lock(&client_mutex
);
3869 list_add(&platform
->list
, &platform_list
);
3870 mutex_unlock(&client_mutex
);
3872 pr_debug("Registered platform '%s'\n", platform
->name
);
3876 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3879 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3881 * @platform: platform to unregister
3883 void snd_soc_unregister_platform(struct device
*dev
)
3885 struct snd_soc_platform
*platform
;
3887 list_for_each_entry(platform
, &platform_list
, list
) {
3888 if (dev
== platform
->dev
)
3894 mutex_lock(&client_mutex
);
3895 list_del(&platform
->list
);
3896 mutex_unlock(&client_mutex
);
3898 pr_debug("Unregistered platform '%s'\n", platform
->name
);
3899 kfree(platform
->name
);
3902 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3904 static u64 codec_format_map
[] = {
3905 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3906 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3907 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3908 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3909 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3910 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3911 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3912 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3913 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3914 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3915 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3916 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3917 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3918 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3919 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3920 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3923 /* Fix up the DAI formats for endianness: codecs don't actually see
3924 * the endianness of the data but we're using the CPU format
3925 * definitions which do need to include endianness so we ensure that
3926 * codec DAIs always have both big and little endian variants set.
3928 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3932 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3933 if (stream
->formats
& codec_format_map
[i
])
3934 stream
->formats
|= codec_format_map
[i
];
3938 * snd_soc_register_codec - Register a codec with the ASoC core
3940 * @codec: codec to register
3942 int snd_soc_register_codec(struct device
*dev
,
3943 const struct snd_soc_codec_driver
*codec_drv
,
3944 struct snd_soc_dai_driver
*dai_drv
,
3948 struct snd_soc_codec
*codec
;
3951 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3953 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3957 /* create CODEC component name */
3958 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3959 if (codec
->name
== NULL
) {
3964 if (codec_drv
->compress_type
)
3965 codec
->compress_type
= codec_drv
->compress_type
;
3967 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3969 codec
->write
= codec_drv
->write
;
3970 codec
->read
= codec_drv
->read
;
3971 codec
->volatile_register
= codec_drv
->volatile_register
;
3972 codec
->readable_register
= codec_drv
->readable_register
;
3973 codec
->writable_register
= codec_drv
->writable_register
;
3974 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
3975 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
3976 codec
->dapm
.dev
= dev
;
3977 codec
->dapm
.codec
= codec
;
3978 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
3979 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
3981 codec
->driver
= codec_drv
;
3982 codec
->num_dai
= num_dai
;
3983 mutex_init(&codec
->mutex
);
3985 /* allocate CODEC register cache */
3986 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
3987 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
3988 codec
->reg_size
= reg_size
;
3989 /* it is necessary to make a copy of the default register cache
3990 * because in the case of using a compression type that requires
3991 * the default register cache to be marked as __devinitconst the
3992 * kernel might have freed the array by the time we initialize
3995 if (codec_drv
->reg_cache_default
) {
3996 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
3997 reg_size
, GFP_KERNEL
);
3998 if (!codec
->reg_def_copy
) {
4005 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
4006 if (!codec
->volatile_register
)
4007 codec
->volatile_register
= snd_soc_default_volatile_register
;
4008 if (!codec
->readable_register
)
4009 codec
->readable_register
= snd_soc_default_readable_register
;
4010 if (!codec
->writable_register
)
4011 codec
->writable_register
= snd_soc_default_writable_register
;
4014 for (i
= 0; i
< num_dai
; i
++) {
4015 fixup_codec_formats(&dai_drv
[i
].playback
);
4016 fixup_codec_formats(&dai_drv
[i
].capture
);
4019 mutex_lock(&client_mutex
);
4020 list_add(&codec
->list
, &codec_list
);
4021 mutex_unlock(&client_mutex
);
4023 /* register any DAIs */
4025 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
4027 dev_err(codec
->dev
, "Failed to regster DAIs: %d\n",
4031 pr_debug("Registered codec '%s'\n", codec
->name
);
4035 kfree(codec
->reg_def_copy
);
4036 codec
->reg_def_copy
= NULL
;
4041 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
4044 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4046 * @codec: codec to unregister
4048 void snd_soc_unregister_codec(struct device
*dev
)
4050 struct snd_soc_codec
*codec
;
4053 list_for_each_entry(codec
, &codec_list
, list
) {
4054 if (dev
== codec
->dev
)
4061 for (i
= 0; i
< codec
->num_dai
; i
++)
4062 snd_soc_unregister_dai(dev
);
4064 mutex_lock(&client_mutex
);
4065 list_del(&codec
->list
);
4066 mutex_unlock(&client_mutex
);
4068 pr_debug("Unregistered codec '%s'\n", codec
->name
);
4070 snd_soc_cache_exit(codec
);
4071 kfree(codec
->reg_def_copy
);
4075 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
4077 /* Retrieve a card's name from device tree */
4078 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
4079 const char *propname
)
4081 struct device_node
*np
= card
->dev
->of_node
;
4084 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
4086 * EINVAL means the property does not exist. This is fine providing
4087 * card->name was previously set, which is checked later in
4088 * snd_soc_register_card.
4090 if (ret
< 0 && ret
!= -EINVAL
) {
4092 "Property '%s' could not be read: %d\n",
4099 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
4101 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
4102 const char *propname
)
4104 struct device_node
*np
= card
->dev
->of_node
;
4106 struct snd_soc_dapm_route
*routes
;
4109 num_routes
= of_property_count_strings(np
, propname
);
4110 if (num_routes
< 0 || num_routes
& 1) {
4112 "Property '%s' does not exist or its length is not even\n",
4119 "Property '%s's length is zero\n",
4124 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
4128 "Could not allocate DAPM route table\n");
4132 for (i
= 0; i
< num_routes
; i
++) {
4133 ret
= of_property_read_string_index(np
, propname
,
4134 2 * i
, &routes
[i
].sink
);
4137 "Property '%s' index %d could not be read: %d\n",
4138 propname
, 2 * i
, ret
);
4142 ret
= of_property_read_string_index(np
, propname
,
4143 (2 * i
) + 1, &routes
[i
].source
);
4146 "Property '%s' index %d could not be read: %d\n",
4147 propname
, (2 * i
) + 1, ret
);
4153 card
->num_dapm_routes
= num_routes
;
4154 card
->dapm_routes
= routes
;
4158 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
4160 static int __init
snd_soc_init(void)
4162 #ifdef CONFIG_DEBUG_FS
4163 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
4164 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
4165 pr_warn("ASoC: Failed to create debugfs directory\n");
4166 snd_soc_debugfs_root
= NULL
;
4169 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
4171 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4173 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
4175 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4177 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
4178 &platform_list_fops
))
4179 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4182 snd_soc_util_init();
4184 return platform_driver_register(&soc_driver
);
4186 module_init(snd_soc_init
);
4188 static void __exit
snd_soc_exit(void)
4190 snd_soc_util_exit();
4192 #ifdef CONFIG_DEBUG_FS
4193 debugfs_remove_recursive(snd_soc_debugfs_root
);
4195 platform_driver_unregister(&soc_driver
);
4197 module_exit(snd_soc_exit
);
4199 /* Module information */
4200 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4201 MODULE_DESCRIPTION("ALSA SoC Core");
4202 MODULE_LICENSE("GPL");
4203 MODULE_ALIAS("platform:soc-audio");