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
, "ASoC: Failed to create codec debugfs"
279 debugfs_create_bool("cache_sync", 0444, codec
->debugfs_codec_root
,
281 debugfs_create_bool("cache_only", 0444, codec
->debugfs_codec_root
,
284 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
285 codec
->debugfs_codec_root
,
286 codec
, &codec_reg_fops
);
287 if (!codec
->debugfs_reg
)
288 dev_warn(codec
->dev
, "ASoC: Failed to create codec register"
291 snd_soc_dapm_debugfs_init(&codec
->dapm
, codec
->debugfs_codec_root
);
294 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
296 debugfs_remove_recursive(codec
->debugfs_codec_root
);
299 static void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
301 struct dentry
*debugfs_card_root
= platform
->card
->debugfs_card_root
;
303 platform
->debugfs_platform_root
= debugfs_create_dir(platform
->name
,
305 if (!platform
->debugfs_platform_root
) {
306 dev_warn(platform
->dev
,
307 "ASoC: Failed to create platform debugfs directory\n");
311 snd_soc_dapm_debugfs_init(&platform
->dapm
,
312 platform
->debugfs_platform_root
);
315 static void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
317 debugfs_remove_recursive(platform
->debugfs_platform_root
);
320 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
321 size_t count
, loff_t
*ppos
)
323 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
324 ssize_t len
, ret
= 0;
325 struct snd_soc_codec
*codec
;
330 list_for_each_entry(codec
, &codec_list
, list
) {
331 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
335 if (ret
> PAGE_SIZE
) {
342 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
349 static const struct file_operations codec_list_fops
= {
350 .read
= codec_list_read_file
,
351 .llseek
= default_llseek
,/* read accesses f_pos */
354 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
355 size_t count
, loff_t
*ppos
)
357 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
358 ssize_t len
, ret
= 0;
359 struct snd_soc_dai
*dai
;
364 list_for_each_entry(dai
, &dai_list
, list
) {
365 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n", dai
->name
);
368 if (ret
> PAGE_SIZE
) {
374 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
381 static const struct file_operations dai_list_fops
= {
382 .read
= dai_list_read_file
,
383 .llseek
= default_llseek
,/* read accesses f_pos */
386 static ssize_t
platform_list_read_file(struct file
*file
,
387 char __user
*user_buf
,
388 size_t count
, loff_t
*ppos
)
390 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
391 ssize_t len
, ret
= 0;
392 struct snd_soc_platform
*platform
;
397 list_for_each_entry(platform
, &platform_list
, list
) {
398 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
402 if (ret
> PAGE_SIZE
) {
408 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
415 static const struct file_operations platform_list_fops
= {
416 .read
= platform_list_read_file
,
417 .llseek
= default_llseek
,/* read accesses f_pos */
420 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
422 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
423 snd_soc_debugfs_root
);
424 if (!card
->debugfs_card_root
) {
426 "ASoC: Failed to create card debugfs directory\n");
430 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
431 card
->debugfs_card_root
,
433 if (!card
->debugfs_pop_time
)
435 "ASoC: Failed to create pop time debugfs file\n");
438 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
440 debugfs_remove_recursive(card
->debugfs_card_root
);
445 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
449 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
453 static inline void soc_init_platform_debugfs(struct snd_soc_platform
*platform
)
457 static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform
*platform
)
461 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
465 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
470 struct snd_pcm_substream
*snd_soc_get_dai_substream(struct snd_soc_card
*card
,
471 const char *dai_link
, int stream
)
475 for (i
= 0; i
< card
->num_links
; i
++) {
476 if (card
->rtd
[i
].dai_link
->no_pcm
&&
477 !strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
478 return card
->rtd
[i
].pcm
->streams
[stream
].substream
;
480 dev_dbg(card
->dev
, "ASoC: failed to find dai link %s\n", dai_link
);
483 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream
);
485 struct snd_soc_pcm_runtime
*snd_soc_get_pcm_runtime(struct snd_soc_card
*card
,
486 const char *dai_link
)
490 for (i
= 0; i
< card
->num_links
; i
++) {
491 if (!strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
492 return &card
->rtd
[i
];
494 dev_dbg(card
->dev
, "ASoC: failed to find rtd %s\n", dai_link
);
497 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime
);
499 #ifdef CONFIG_SND_SOC_AC97_BUS
500 /* unregister ac97 codec */
501 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
503 if (codec
->ac97
->dev
.bus
)
504 device_unregister(&codec
->ac97
->dev
);
508 /* stop no dev release warning */
509 static void soc_ac97_device_release(struct device
*dev
){}
511 /* register ac97 codec to bus */
512 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
516 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
517 codec
->ac97
->dev
.parent
= codec
->card
->dev
;
518 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
520 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
521 codec
->card
->snd_card
->number
, 0, codec
->name
);
522 err
= device_register(&codec
->ac97
->dev
);
524 dev_err(codec
->dev
, "ASoC: Can't register ac97 bus\n");
525 codec
->ac97
->dev
.bus
= NULL
;
532 #ifdef CONFIG_PM_SLEEP
533 /* powers down audio subsystem for suspend */
534 int snd_soc_suspend(struct device
*dev
)
536 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
537 struct snd_soc_codec
*codec
;
540 /* If the initialization of this soc device failed, there is no codec
541 * associated with it. Just bail out in this case.
543 if (list_empty(&card
->codec_dev_list
))
546 /* Due to the resume being scheduled into a workqueue we could
547 * suspend before that's finished - wait for it to complete.
549 snd_power_lock(card
->snd_card
);
550 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
551 snd_power_unlock(card
->snd_card
);
553 /* we're going to block userspace touching us until resume completes */
554 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
556 /* mute any active DACs */
557 for (i
= 0; i
< card
->num_rtd
; i
++) {
558 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
559 struct snd_soc_dai_driver
*drv
= dai
->driver
;
561 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
564 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
565 drv
->ops
->digital_mute(dai
, 1);
568 /* suspend all pcms */
569 for (i
= 0; i
< card
->num_rtd
; i
++) {
570 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
573 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
576 if (card
->suspend_pre
)
577 card
->suspend_pre(card
);
579 for (i
= 0; i
< card
->num_rtd
; i
++) {
580 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
581 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
583 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
586 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
587 cpu_dai
->driver
->suspend(cpu_dai
);
588 if (platform
->driver
->suspend
&& !platform
->suspended
) {
589 platform
->driver
->suspend(cpu_dai
);
590 platform
->suspended
= 1;
594 /* close any waiting streams and save state */
595 for (i
= 0; i
< card
->num_rtd
; i
++) {
596 flush_delayed_work(&card
->rtd
[i
].delayed_work
);
597 card
->rtd
[i
].codec
->dapm
.suspend_bias_level
= card
->rtd
[i
].codec
->dapm
.bias_level
;
600 for (i
= 0; i
< card
->num_rtd
; i
++) {
602 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
605 snd_soc_dapm_stream_event(&card
->rtd
[i
],
606 SNDRV_PCM_STREAM_PLAYBACK
,
607 SND_SOC_DAPM_STREAM_SUSPEND
);
609 snd_soc_dapm_stream_event(&card
->rtd
[i
],
610 SNDRV_PCM_STREAM_CAPTURE
,
611 SND_SOC_DAPM_STREAM_SUSPEND
);
614 /* Recheck all analogue paths too */
615 dapm_mark_io_dirty(&card
->dapm
);
616 snd_soc_dapm_sync(&card
->dapm
);
618 /* suspend all CODECs */
619 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
620 /* If there are paths active then the CODEC will be held with
621 * bias _ON and should not be suspended. */
622 if (!codec
->suspended
&& codec
->driver
->suspend
) {
623 switch (codec
->dapm
.bias_level
) {
624 case SND_SOC_BIAS_STANDBY
:
626 * If the CODEC is capable of idle
627 * bias off then being in STANDBY
628 * means it's doing something,
629 * otherwise fall through.
631 if (codec
->dapm
.idle_bias_off
) {
633 "ASoC: idle_bias_off CODEC on"
637 case SND_SOC_BIAS_OFF
:
638 codec
->driver
->suspend(codec
);
639 codec
->suspended
= 1;
640 codec
->cache_sync
= 1;
641 if (codec
->using_regmap
)
642 regcache_mark_dirty(codec
->control_data
);
645 dev_dbg(codec
->dev
, "ASoC: CODEC is on"
652 for (i
= 0; i
< card
->num_rtd
; i
++) {
653 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
655 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
658 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
659 cpu_dai
->driver
->suspend(cpu_dai
);
662 if (card
->suspend_post
)
663 card
->suspend_post(card
);
667 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
669 /* deferred resume work, so resume can complete before we finished
670 * setting our codec back up, which can be very slow on I2C
672 static void soc_resume_deferred(struct work_struct
*work
)
674 struct snd_soc_card
*card
=
675 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
676 struct snd_soc_codec
*codec
;
679 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
680 * so userspace apps are blocked from touching us
683 dev_dbg(card
->dev
, "ASoC: starting resume work\n");
685 /* Bring us up into D2 so that DAPM starts enabling things */
686 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
688 if (card
->resume_pre
)
689 card
->resume_pre(card
);
691 /* resume AC97 DAIs */
692 for (i
= 0; i
< card
->num_rtd
; i
++) {
693 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
695 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
698 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
699 cpu_dai
->driver
->resume(cpu_dai
);
702 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
703 /* If the CODEC was idle over suspend then it will have been
704 * left with bias OFF or STANDBY and suspended so we must now
705 * resume. Otherwise the suspend was suppressed.
707 if (codec
->driver
->resume
&& codec
->suspended
) {
708 switch (codec
->dapm
.bias_level
) {
709 case SND_SOC_BIAS_STANDBY
:
710 case SND_SOC_BIAS_OFF
:
711 codec
->driver
->resume(codec
);
712 codec
->suspended
= 0;
715 dev_dbg(codec
->dev
, "ASoC: CODEC was on over"
722 for (i
= 0; i
< card
->num_rtd
; i
++) {
724 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
727 snd_soc_dapm_stream_event(&card
->rtd
[i
],
728 SNDRV_PCM_STREAM_PLAYBACK
,
729 SND_SOC_DAPM_STREAM_RESUME
);
731 snd_soc_dapm_stream_event(&card
->rtd
[i
],
732 SNDRV_PCM_STREAM_CAPTURE
,
733 SND_SOC_DAPM_STREAM_RESUME
);
736 /* unmute any active DACs */
737 for (i
= 0; i
< card
->num_rtd
; i
++) {
738 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dai
;
739 struct snd_soc_dai_driver
*drv
= dai
->driver
;
741 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
744 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
745 drv
->ops
->digital_mute(dai
, 0);
748 for (i
= 0; i
< card
->num_rtd
; i
++) {
749 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
750 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
752 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
755 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
756 cpu_dai
->driver
->resume(cpu_dai
);
757 if (platform
->driver
->resume
&& platform
->suspended
) {
758 platform
->driver
->resume(cpu_dai
);
759 platform
->suspended
= 0;
763 if (card
->resume_post
)
764 card
->resume_post(card
);
766 dev_dbg(card
->dev
, "ASoC: resume work completed\n");
768 /* userspace can access us now we are back as we were before */
769 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
771 /* Recheck all analogue paths too */
772 dapm_mark_io_dirty(&card
->dapm
);
773 snd_soc_dapm_sync(&card
->dapm
);
776 /* powers up audio subsystem after a suspend */
777 int snd_soc_resume(struct device
*dev
)
779 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
780 int i
, ac97_control
= 0;
782 /* If the initialization of this soc device failed, there is no codec
783 * associated with it. Just bail out in this case.
785 if (list_empty(&card
->codec_dev_list
))
788 /* AC97 devices might have other drivers hanging off them so
789 * need to resume immediately. Other drivers don't have that
790 * problem and may take a substantial amount of time to resume
791 * due to I/O costs and anti-pop so handle them out of line.
793 for (i
= 0; i
< card
->num_rtd
; i
++) {
794 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
795 ac97_control
|= cpu_dai
->driver
->ac97_control
;
798 dev_dbg(dev
, "ASoC: Resuming AC97 immediately\n");
799 soc_resume_deferred(&card
->deferred_resume_work
);
801 dev_dbg(dev
, "ASoC: Scheduling resume work\n");
802 if (!schedule_work(&card
->deferred_resume_work
))
803 dev_err(dev
, "ASoC: resume work item may be lost\n");
808 EXPORT_SYMBOL_GPL(snd_soc_resume
);
810 #define snd_soc_suspend NULL
811 #define snd_soc_resume NULL
814 static const struct snd_soc_dai_ops null_dai_ops
= {
817 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
819 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
820 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
821 struct snd_soc_codec
*codec
;
822 struct snd_soc_platform
*platform
;
823 struct snd_soc_dai
*codec_dai
, *cpu_dai
;
824 const char *platform_name
;
826 dev_dbg(card
->dev
, "ASoC: binding %s at idx %d\n", dai_link
->name
, num
);
828 /* Find CPU DAI from registered DAIs*/
829 list_for_each_entry(cpu_dai
, &dai_list
, list
) {
830 if (dai_link
->cpu_of_node
&&
831 (cpu_dai
->dev
->of_node
!= dai_link
->cpu_of_node
))
833 if (dai_link
->cpu_name
&&
834 strcmp(dev_name(cpu_dai
->dev
), dai_link
->cpu_name
))
836 if (dai_link
->cpu_dai_name
&&
837 strcmp(cpu_dai
->name
, dai_link
->cpu_dai_name
))
840 rtd
->cpu_dai
= cpu_dai
;
844 dev_err(card
->dev
, "ASoC: CPU DAI %s not registered\n",
845 dai_link
->cpu_dai_name
);
846 return -EPROBE_DEFER
;
849 /* Find CODEC from registered CODECs */
850 list_for_each_entry(codec
, &codec_list
, list
) {
851 if (dai_link
->codec_of_node
) {
852 if (codec
->dev
->of_node
!= dai_link
->codec_of_node
)
855 if (strcmp(codec
->name
, dai_link
->codec_name
))
862 * CODEC found, so find CODEC DAI from registered DAIs from
865 list_for_each_entry(codec_dai
, &dai_list
, list
) {
866 if (codec
->dev
== codec_dai
->dev
&&
867 !strcmp(codec_dai
->name
,
868 dai_link
->codec_dai_name
)) {
870 rtd
->codec_dai
= codec_dai
;
874 if (!rtd
->codec_dai
) {
875 dev_err(card
->dev
, "ASoC: CODEC DAI %s not registered\n",
876 dai_link
->codec_dai_name
);
877 return -EPROBE_DEFER
;
882 dev_err(card
->dev
, "ASoC: CODEC %s not registered\n",
883 dai_link
->codec_name
);
884 return -EPROBE_DEFER
;
887 /* if there's no platform we match on the empty platform */
888 platform_name
= dai_link
->platform_name
;
889 if (!platform_name
&& !dai_link
->platform_of_node
)
890 platform_name
= "snd-soc-dummy";
892 /* find one from the set of registered platforms */
893 list_for_each_entry(platform
, &platform_list
, list
) {
894 if (dai_link
->platform_of_node
) {
895 if (platform
->dev
->of_node
!=
896 dai_link
->platform_of_node
)
899 if (strcmp(platform
->name
, platform_name
))
903 rtd
->platform
= platform
;
905 if (!rtd
->platform
) {
906 dev_err(card
->dev
, "ASoC: platform %s not registered\n",
907 dai_link
->platform_name
);
908 return -EPROBE_DEFER
;
916 static int soc_remove_platform(struct snd_soc_platform
*platform
)
920 if (platform
->driver
->remove
) {
921 ret
= platform
->driver
->remove(platform
);
923 dev_err(platform
->dev
, "ASoC: failed to remove %d\n",
927 /* Make sure all DAPM widgets are freed */
928 snd_soc_dapm_free(&platform
->dapm
);
930 soc_cleanup_platform_debugfs(platform
);
931 platform
->probed
= 0;
932 list_del(&platform
->card_list
);
933 module_put(platform
->dev
->driver
->owner
);
938 static void soc_remove_codec(struct snd_soc_codec
*codec
)
942 if (codec
->driver
->remove
) {
943 err
= codec
->driver
->remove(codec
);
945 dev_err(codec
->dev
, "ASoC: failed to remove %d\n", err
);
948 /* Make sure all DAPM widgets are freed */
949 snd_soc_dapm_free(&codec
->dapm
);
951 soc_cleanup_codec_debugfs(codec
);
953 list_del(&codec
->card_list
);
954 module_put(codec
->dev
->driver
->owner
);
957 static void soc_remove_link_dais(struct snd_soc_card
*card
, int num
, int order
)
959 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
960 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
, *cpu_dai
= rtd
->cpu_dai
;
963 /* unregister the rtd device */
964 if (rtd
->dev_registered
) {
965 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
966 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
967 device_unregister(rtd
->dev
);
968 rtd
->dev_registered
= 0;
971 /* remove the CODEC DAI */
972 if (codec_dai
&& codec_dai
->probed
&&
973 codec_dai
->driver
->remove_order
== order
) {
974 if (codec_dai
->driver
->remove
) {
975 err
= codec_dai
->driver
->remove(codec_dai
);
977 dev_err(codec_dai
->dev
,
978 "ASoC: failed to remove %s: %d\n",
979 codec_dai
->name
, err
);
981 codec_dai
->probed
= 0;
982 list_del(&codec_dai
->card_list
);
985 /* remove the cpu_dai */
986 if (cpu_dai
&& cpu_dai
->probed
&&
987 cpu_dai
->driver
->remove_order
== order
) {
988 if (cpu_dai
->driver
->remove
) {
989 err
= cpu_dai
->driver
->remove(cpu_dai
);
991 dev_err(cpu_dai
->dev
,
992 "ASoC: failed to remove %s: %d\n",
996 list_del(&cpu_dai
->card_list
);
998 if (!cpu_dai
->codec
) {
999 snd_soc_dapm_free(&cpu_dai
->dapm
);
1000 module_put(cpu_dai
->dev
->driver
->owner
);
1005 static void soc_remove_link_components(struct snd_soc_card
*card
, int num
,
1008 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1009 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1010 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1011 struct snd_soc_platform
*platform
= rtd
->platform
;
1012 struct snd_soc_codec
*codec
;
1014 /* remove the platform */
1015 if (platform
&& platform
->probed
&&
1016 platform
->driver
->remove_order
== order
) {
1017 soc_remove_platform(platform
);
1020 /* remove the CODEC-side CODEC */
1022 codec
= codec_dai
->codec
;
1023 if (codec
&& codec
->probed
&&
1024 codec
->driver
->remove_order
== order
)
1025 soc_remove_codec(codec
);
1028 /* remove any CPU-side CODEC */
1030 codec
= cpu_dai
->codec
;
1031 if (codec
&& codec
->probed
&&
1032 codec
->driver
->remove_order
== order
)
1033 soc_remove_codec(codec
);
1037 static void soc_remove_dai_links(struct snd_soc_card
*card
)
1041 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1043 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1044 soc_remove_link_dais(card
, dai
, order
);
1047 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1049 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1050 soc_remove_link_components(card
, dai
, order
);
1056 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1057 struct snd_soc_codec
*codec
)
1061 if (card
->codec_conf
== NULL
)
1064 for (i
= 0; i
< card
->num_configs
; i
++) {
1065 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1066 if (map
->dev_name
&& !strcmp(codec
->name
, map
->dev_name
)) {
1067 codec
->name_prefix
= map
->name_prefix
;
1073 static int soc_probe_codec(struct snd_soc_card
*card
,
1074 struct snd_soc_codec
*codec
)
1077 const struct snd_soc_codec_driver
*driver
= codec
->driver
;
1078 struct snd_soc_dai
*dai
;
1081 codec
->dapm
.card
= card
;
1082 soc_set_name_prefix(card
, codec
);
1084 if (!try_module_get(codec
->dev
->driver
->owner
))
1087 soc_init_codec_debugfs(codec
);
1089 if (driver
->dapm_widgets
)
1090 snd_soc_dapm_new_controls(&codec
->dapm
, driver
->dapm_widgets
,
1091 driver
->num_dapm_widgets
);
1093 /* Create DAPM widgets for each DAI stream */
1094 list_for_each_entry(dai
, &dai_list
, list
) {
1095 if (dai
->dev
!= codec
->dev
)
1098 snd_soc_dapm_new_dai_widgets(&codec
->dapm
, dai
);
1101 codec
->dapm
.idle_bias_off
= driver
->idle_bias_off
;
1103 if (driver
->probe
) {
1104 ret
= driver
->probe(codec
);
1107 "ASoC: failed to probe CODEC %d\n", ret
);
1112 /* If the driver didn't set I/O up try regmap */
1113 if (!codec
->write
&& dev_get_regmap(codec
->dev
, NULL
))
1114 snd_soc_codec_set_cache_io(codec
, 0, 0, SND_SOC_REGMAP
);
1116 if (driver
->controls
)
1117 snd_soc_add_codec_controls(codec
, driver
->controls
,
1118 driver
->num_controls
);
1119 if (driver
->dapm_routes
)
1120 snd_soc_dapm_add_routes(&codec
->dapm
, driver
->dapm_routes
,
1121 driver
->num_dapm_routes
);
1123 /* mark codec as probed and add to card codec list */
1125 list_add(&codec
->card_list
, &card
->codec_dev_list
);
1126 list_add(&codec
->dapm
.list
, &card
->dapm_list
);
1131 soc_cleanup_codec_debugfs(codec
);
1132 module_put(codec
->dev
->driver
->owner
);
1137 static int soc_probe_platform(struct snd_soc_card
*card
,
1138 struct snd_soc_platform
*platform
)
1141 const struct snd_soc_platform_driver
*driver
= platform
->driver
;
1142 struct snd_soc_dai
*dai
;
1144 platform
->card
= card
;
1145 platform
->dapm
.card
= card
;
1147 if (!try_module_get(platform
->dev
->driver
->owner
))
1150 soc_init_platform_debugfs(platform
);
1152 if (driver
->dapm_widgets
)
1153 snd_soc_dapm_new_controls(&platform
->dapm
,
1154 driver
->dapm_widgets
, driver
->num_dapm_widgets
);
1156 /* Create DAPM widgets for each DAI stream */
1157 list_for_each_entry(dai
, &dai_list
, list
) {
1158 if (dai
->dev
!= platform
->dev
)
1161 snd_soc_dapm_new_dai_widgets(&platform
->dapm
, dai
);
1164 platform
->dapm
.idle_bias_off
= 1;
1166 if (driver
->probe
) {
1167 ret
= driver
->probe(platform
);
1169 dev_err(platform
->dev
,
1170 "ASoC: failed to probe platform %d\n", ret
);
1175 if (driver
->controls
)
1176 snd_soc_add_platform_controls(platform
, driver
->controls
,
1177 driver
->num_controls
);
1178 if (driver
->dapm_routes
)
1179 snd_soc_dapm_add_routes(&platform
->dapm
, driver
->dapm_routes
,
1180 driver
->num_dapm_routes
);
1182 /* mark platform as probed and add to card platform list */
1183 platform
->probed
= 1;
1184 list_add(&platform
->card_list
, &card
->platform_dev_list
);
1185 list_add(&platform
->dapm
.list
, &card
->dapm_list
);
1190 soc_cleanup_platform_debugfs(platform
);
1191 module_put(platform
->dev
->driver
->owner
);
1196 static void rtd_release(struct device
*dev
)
1201 static int soc_post_component_init(struct snd_soc_card
*card
,
1202 struct snd_soc_codec
*codec
,
1203 int num
, int dailess
)
1205 struct snd_soc_dai_link
*dai_link
= NULL
;
1206 struct snd_soc_aux_dev
*aux_dev
= NULL
;
1207 struct snd_soc_pcm_runtime
*rtd
;
1208 const char *temp
, *name
;
1212 dai_link
= &card
->dai_link
[num
];
1213 rtd
= &card
->rtd
[num
];
1214 name
= dai_link
->name
;
1216 aux_dev
= &card
->aux_dev
[num
];
1217 rtd
= &card
->rtd_aux
[num
];
1218 name
= aux_dev
->name
;
1222 /* Make sure all DAPM widgets are instantiated */
1223 snd_soc_dapm_new_widgets(&codec
->dapm
);
1225 /* machine controls, routes and widgets are not prefixed */
1226 temp
= codec
->name_prefix
;
1227 codec
->name_prefix
= NULL
;
1229 /* do machine specific initialization */
1230 if (!dailess
&& dai_link
->init
)
1231 ret
= dai_link
->init(rtd
);
1232 else if (dailess
&& aux_dev
->init
)
1233 ret
= aux_dev
->init(&codec
->dapm
);
1235 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n", name
, ret
);
1238 codec
->name_prefix
= temp
;
1240 /* register the rtd device */
1243 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1246 device_initialize(rtd
->dev
);
1247 rtd
->dev
->parent
= card
->dev
;
1248 rtd
->dev
->release
= rtd_release
;
1249 rtd
->dev
->init_name
= name
;
1250 dev_set_drvdata(rtd
->dev
, rtd
);
1251 mutex_init(&rtd
->pcm_mutex
);
1252 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1253 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1254 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1255 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1256 ret
= device_add(rtd
->dev
);
1259 "ASoC: failed to register runtime device: %d\n", ret
);
1262 rtd
->dev_registered
= 1;
1264 /* add DAPM sysfs entries for this codec */
1265 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1268 "ASoC: failed to add codec dapm sysfs entries: %d\n", ret
);
1270 /* add codec sysfs entries */
1271 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1274 "ASoC: failed to add codec sysfs files: %d\n", ret
);
1276 #ifdef CONFIG_DEBUG_FS
1277 /* add DPCM sysfs entries */
1278 if (!dailess
&& !dai_link
->dynamic
)
1281 ret
= soc_dpcm_debugfs_add(rtd
);
1283 dev_err(rtd
->dev
, "ASoC: failed to add dpcm sysfs entries: %d\n", ret
);
1290 static int soc_probe_link_components(struct snd_soc_card
*card
, int num
,
1293 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1294 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1295 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1296 struct snd_soc_platform
*platform
= rtd
->platform
;
1299 /* probe the CPU-side component, if it is a CODEC */
1300 if (cpu_dai
->codec
&&
1301 !cpu_dai
->codec
->probed
&&
1302 cpu_dai
->codec
->driver
->probe_order
== order
) {
1303 ret
= soc_probe_codec(card
, cpu_dai
->codec
);
1308 /* probe the CODEC-side component */
1309 if (!codec_dai
->codec
->probed
&&
1310 codec_dai
->codec
->driver
->probe_order
== order
) {
1311 ret
= soc_probe_codec(card
, codec_dai
->codec
);
1316 /* probe the platform */
1317 if (!platform
->probed
&&
1318 platform
->driver
->probe_order
== order
) {
1319 ret
= soc_probe_platform(card
, platform
);
1327 static int soc_probe_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1329 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1330 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1331 struct snd_soc_codec
*codec
= rtd
->codec
;
1332 struct snd_soc_platform
*platform
= rtd
->platform
;
1333 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1334 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1335 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1338 dev_dbg(card
->dev
, "ASoC: probe %s dai link %d late %d\n",
1339 card
->name
, num
, order
);
1341 /* config components */
1342 cpu_dai
->platform
= platform
;
1343 codec_dai
->card
= card
;
1344 cpu_dai
->card
= card
;
1346 /* set default power off timeout */
1347 rtd
->pmdown_time
= pmdown_time
;
1349 /* probe the cpu_dai */
1350 if (!cpu_dai
->probed
&&
1351 cpu_dai
->driver
->probe_order
== order
) {
1352 if (!cpu_dai
->codec
) {
1353 cpu_dai
->dapm
.card
= card
;
1354 if (!try_module_get(cpu_dai
->dev
->driver
->owner
))
1357 list_add(&cpu_dai
->dapm
.list
, &card
->dapm_list
);
1358 snd_soc_dapm_new_dai_widgets(&cpu_dai
->dapm
, cpu_dai
);
1361 if (cpu_dai
->driver
->probe
) {
1362 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1364 dev_err(cpu_dai
->dev
,
1365 "ASoC: failed to probe CPU DAI %s: %d\n",
1366 cpu_dai
->name
, ret
);
1367 module_put(cpu_dai
->dev
->driver
->owner
);
1371 cpu_dai
->probed
= 1;
1372 /* mark cpu_dai as probed and add to card dai list */
1373 list_add(&cpu_dai
->card_list
, &card
->dai_dev_list
);
1376 /* probe the CODEC DAI */
1377 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1378 if (codec_dai
->driver
->probe
) {
1379 ret
= codec_dai
->driver
->probe(codec_dai
);
1381 dev_err(codec_dai
->dev
,
1382 "ASoC: failed to probe CODEC DAI %s: %d\n",
1383 codec_dai
->name
, ret
);
1388 /* mark codec_dai as probed and add to card dai list */
1389 codec_dai
->probed
= 1;
1390 list_add(&codec_dai
->card_list
, &card
->dai_dev_list
);
1393 /* complete DAI probe during last probe */
1394 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1397 ret
= soc_post_component_init(card
, codec
, num
, 0);
1401 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1403 dev_warn(rtd
->dev
, "ASoC: failed to add pmdown_time sysfs: %d\n",
1406 if (cpu_dai
->driver
->compress_dai
) {
1407 /*create compress_device"*/
1408 ret
= soc_new_compress(rtd
, num
);
1410 dev_err(card
->dev
, "ASoC: can't create compress %s\n",
1411 dai_link
->stream_name
);
1416 if (!dai_link
->params
) {
1417 /* create the pcm */
1418 ret
= soc_new_pcm(rtd
, num
);
1420 dev_err(card
->dev
, "ASoC: can't create pcm %s :%d\n",
1421 dai_link
->stream_name
, ret
);
1425 /* link the DAI widgets */
1426 play_w
= codec_dai
->playback_widget
;
1427 capture_w
= cpu_dai
->capture_widget
;
1428 if (play_w
&& capture_w
) {
1429 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1432 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1433 play_w
->name
, capture_w
->name
, ret
);
1438 play_w
= cpu_dai
->playback_widget
;
1439 capture_w
= codec_dai
->capture_widget
;
1440 if (play_w
&& capture_w
) {
1441 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1444 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1445 play_w
->name
, capture_w
->name
, ret
);
1452 /* add platform data for AC97 devices */
1453 if (rtd
->codec_dai
->driver
->ac97_control
)
1454 snd_ac97_dev_add_pdata(codec
->ac97
, rtd
->cpu_dai
->ac97_pdata
);
1459 #ifdef CONFIG_SND_SOC_AC97_BUS
1460 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1464 /* Only instantiate AC97 if not already done by the adaptor
1465 * for the generic AC97 subsystem.
1467 if (rtd
->codec_dai
->driver
->ac97_control
&& !rtd
->codec
->ac97_registered
) {
1469 * It is possible that the AC97 device is already registered to
1470 * the device subsystem. This happens when the device is created
1471 * via snd_ac97_mixer(). Currently only SoC codec that does so
1472 * is the generic AC97 glue but others migh emerge.
1474 * In those cases we don't try to register the device again.
1476 if (!rtd
->codec
->ac97_created
)
1479 ret
= soc_ac97_dev_register(rtd
->codec
);
1481 dev_err(rtd
->codec
->dev
,
1482 "ASoC: AC97 device register failed: %d\n", ret
);
1486 rtd
->codec
->ac97_registered
= 1;
1491 static void soc_unregister_ac97_dai_link(struct snd_soc_codec
*codec
)
1493 if (codec
->ac97_registered
) {
1494 soc_ac97_dev_unregister(codec
);
1495 codec
->ac97_registered
= 0;
1500 static int soc_check_aux_dev(struct snd_soc_card
*card
, int num
)
1502 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1503 struct snd_soc_codec
*codec
;
1505 /* find CODEC from registered CODECs*/
1506 list_for_each_entry(codec
, &codec_list
, list
) {
1507 if (!strcmp(codec
->name
, aux_dev
->codec_name
))
1511 dev_err(card
->dev
, "ASoC: %s not registered\n", aux_dev
->codec_name
);
1513 return -EPROBE_DEFER
;
1516 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1518 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1519 struct snd_soc_codec
*codec
;
1522 /* find CODEC from registered CODECs*/
1523 list_for_each_entry(codec
, &codec_list
, list
) {
1524 if (!strcmp(codec
->name
, aux_dev
->codec_name
)) {
1525 if (codec
->probed
) {
1527 "ASoC: codec already probed");
1534 /* codec not found */
1535 dev_err(card
->dev
, "ASoC: codec %s not found", aux_dev
->codec_name
);
1536 return -EPROBE_DEFER
;
1539 ret
= soc_probe_codec(card
, codec
);
1543 ret
= soc_post_component_init(card
, codec
, num
, 1);
1549 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1551 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1552 struct snd_soc_codec
*codec
= rtd
->codec
;
1554 /* unregister the rtd device */
1555 if (rtd
->dev_registered
) {
1556 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1557 device_del(rtd
->dev
);
1558 rtd
->dev_registered
= 0;
1561 if (codec
&& codec
->probed
)
1562 soc_remove_codec(codec
);
1565 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
,
1566 enum snd_soc_compress_type compress_type
)
1570 if (codec
->cache_init
)
1573 /* override the compress_type if necessary */
1574 if (compress_type
&& codec
->compress_type
!= compress_type
)
1575 codec
->compress_type
= compress_type
;
1576 ret
= snd_soc_cache_init(codec
);
1578 dev_err(codec
->dev
, "ASoC: Failed to set cache compression"
1579 " type: %d\n", ret
);
1582 codec
->cache_init
= 1;
1586 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1588 struct snd_soc_codec
*codec
;
1589 struct snd_soc_codec_conf
*codec_conf
;
1590 enum snd_soc_compress_type compress_type
;
1591 struct snd_soc_dai_link
*dai_link
;
1592 int ret
, i
, order
, dai_fmt
;
1594 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1597 for (i
= 0; i
< card
->num_links
; i
++) {
1598 ret
= soc_bind_dai_link(card
, i
);
1603 /* check aux_devs too */
1604 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1605 ret
= soc_check_aux_dev(card
, i
);
1610 /* initialize the register cache for each available codec */
1611 list_for_each_entry(codec
, &codec_list
, list
) {
1612 if (codec
->cache_init
)
1614 /* by default we don't override the compress_type */
1616 /* check to see if we need to override the compress_type */
1617 for (i
= 0; i
< card
->num_configs
; ++i
) {
1618 codec_conf
= &card
->codec_conf
[i
];
1619 if (!strcmp(codec
->name
, codec_conf
->dev_name
)) {
1620 compress_type
= codec_conf
->compress_type
;
1621 if (compress_type
&& compress_type
1622 != codec
->compress_type
)
1626 ret
= snd_soc_init_codec_cache(codec
, compress_type
);
1631 /* card bind complete so register a sound card */
1632 ret
= snd_card_create(SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1633 card
->owner
, 0, &card
->snd_card
);
1635 dev_err(card
->dev
, "ASoC: can't create sound card for"
1636 " card %s: %d\n", card
->name
, ret
);
1639 card
->snd_card
->dev
= card
->dev
;
1641 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1642 card
->dapm
.dev
= card
->dev
;
1643 card
->dapm
.card
= card
;
1644 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1646 #ifdef CONFIG_DEBUG_FS
1647 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1650 #ifdef CONFIG_PM_SLEEP
1651 /* deferred resume work */
1652 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1655 if (card
->dapm_widgets
)
1656 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1657 card
->num_dapm_widgets
);
1659 /* initialise the sound card only once */
1661 ret
= card
->probe(card
);
1663 goto card_probe_error
;
1666 /* probe all components used by DAI links on this card */
1667 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1669 for (i
= 0; i
< card
->num_links
; i
++) {
1670 ret
= soc_probe_link_components(card
, i
, order
);
1673 "ASoC: failed to instantiate card %d\n",
1680 /* probe all DAI links on this card */
1681 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1683 for (i
= 0; i
< card
->num_links
; i
++) {
1684 ret
= soc_probe_link_dais(card
, i
, order
);
1687 "ASoC: failed to instantiate card %d\n",
1694 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1695 ret
= soc_probe_aux_dev(card
, i
);
1698 "ASoC: failed to add auxiliary devices %d\n",
1700 goto probe_aux_dev_err
;
1704 snd_soc_dapm_link_dai_widgets(card
);
1707 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1709 if (card
->dapm_routes
)
1710 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1711 card
->num_dapm_routes
);
1713 snd_soc_dapm_new_widgets(&card
->dapm
);
1715 for (i
= 0; i
< card
->num_links
; i
++) {
1716 dai_link
= &card
->dai_link
[i
];
1717 dai_fmt
= dai_link
->dai_fmt
;
1720 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].codec_dai
,
1722 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1723 dev_warn(card
->rtd
[i
].codec_dai
->dev
,
1724 "ASoC: Failed to set DAI format: %d\n",
1728 /* If this is a regular CPU link there will be a platform */
1730 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1731 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1733 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1734 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1735 "ASoC: Failed to set DAI format: %d\n",
1737 } else if (dai_fmt
) {
1738 /* Flip the polarity for the "CPU" end */
1739 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1740 switch (dai_link
->dai_fmt
&
1741 SND_SOC_DAIFMT_MASTER_MASK
) {
1742 case SND_SOC_DAIFMT_CBM_CFM
:
1743 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1745 case SND_SOC_DAIFMT_CBM_CFS
:
1746 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1748 case SND_SOC_DAIFMT_CBS_CFM
:
1749 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1751 case SND_SOC_DAIFMT_CBS_CFS
:
1752 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1756 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1758 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1759 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1760 "ASoC: Failed to set DAI format: %d\n",
1765 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1767 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1768 "%s", card
->long_name
? card
->long_name
: card
->name
);
1769 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1770 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1771 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1772 switch (card
->snd_card
->driver
[i
]) {
1778 if (!isalnum(card
->snd_card
->driver
[i
]))
1779 card
->snd_card
->driver
[i
] = '_';
1784 if (card
->late_probe
) {
1785 ret
= card
->late_probe(card
);
1787 dev_err(card
->dev
, "ASoC: %s late_probe() failed: %d\n",
1789 goto probe_aux_dev_err
;
1793 snd_soc_dapm_new_widgets(&card
->dapm
);
1795 if (card
->fully_routed
)
1796 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
)
1797 snd_soc_dapm_auto_nc_codec_pins(codec
);
1799 ret
= snd_card_register(card
->snd_card
);
1801 dev_err(card
->dev
, "ASoC: failed to register soundcard %d\n",
1803 goto probe_aux_dev_err
;
1806 #ifdef CONFIG_SND_SOC_AC97_BUS
1807 /* register any AC97 codecs */
1808 for (i
= 0; i
< card
->num_rtd
; i
++) {
1809 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1811 dev_err(card
->dev
, "ASoC: failed to register AC97:"
1814 soc_unregister_ac97_dai_link(card
->rtd
[i
].codec
);
1815 goto probe_aux_dev_err
;
1820 card
->instantiated
= 1;
1821 snd_soc_dapm_sync(&card
->dapm
);
1822 mutex_unlock(&card
->mutex
);
1827 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1828 soc_remove_aux_dev(card
, i
);
1831 soc_remove_dai_links(card
);
1837 snd_card_free(card
->snd_card
);
1840 mutex_unlock(&card
->mutex
);
1845 /* probes a new socdev */
1846 static int soc_probe(struct platform_device
*pdev
)
1848 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1851 * no card, so machine driver should be registering card
1852 * we should not be here in that case so ret error
1857 dev_warn(&pdev
->dev
,
1858 "ASoC: machine %s should use snd_soc_register_card()\n",
1861 /* Bodge while we unpick instantiation */
1862 card
->dev
= &pdev
->dev
;
1864 return snd_soc_register_card(card
);
1867 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1871 /* make sure any delayed work runs */
1872 for (i
= 0; i
< card
->num_rtd
; i
++) {
1873 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1874 flush_delayed_work(&rtd
->delayed_work
);
1877 /* remove auxiliary devices */
1878 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1879 soc_remove_aux_dev(card
, i
);
1881 /* remove and free each DAI */
1882 soc_remove_dai_links(card
);
1884 soc_cleanup_card_debugfs(card
);
1886 /* remove the card */
1890 snd_soc_dapm_free(&card
->dapm
);
1892 snd_card_free(card
->snd_card
);
1897 /* removes a socdev */
1898 static int soc_remove(struct platform_device
*pdev
)
1900 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1902 snd_soc_unregister_card(card
);
1906 int snd_soc_poweroff(struct device
*dev
)
1908 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1911 if (!card
->instantiated
)
1914 /* Flush out pmdown_time work - we actually do want to run it
1915 * now, we're shutting down so no imminent restart. */
1916 for (i
= 0; i
< card
->num_rtd
; i
++) {
1917 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1918 flush_delayed_work(&rtd
->delayed_work
);
1921 snd_soc_dapm_shutdown(card
);
1925 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1927 const struct dev_pm_ops snd_soc_pm_ops
= {
1928 .suspend
= snd_soc_suspend
,
1929 .resume
= snd_soc_resume
,
1930 .freeze
= snd_soc_suspend
,
1931 .thaw
= snd_soc_resume
,
1932 .poweroff
= snd_soc_poweroff
,
1933 .restore
= snd_soc_resume
,
1935 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1937 /* ASoC platform driver */
1938 static struct platform_driver soc_driver
= {
1940 .name
= "soc-audio",
1941 .owner
= THIS_MODULE
,
1942 .pm
= &snd_soc_pm_ops
,
1945 .remove
= soc_remove
,
1949 * snd_soc_codec_volatile_register: Report if a register is volatile.
1951 * @codec: CODEC to query.
1952 * @reg: Register to query.
1954 * Boolean function indiciating if a CODEC register is volatile.
1956 int snd_soc_codec_volatile_register(struct snd_soc_codec
*codec
,
1959 if (codec
->volatile_register
)
1960 return codec
->volatile_register(codec
, reg
);
1964 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register
);
1967 * snd_soc_codec_readable_register: Report if a register is readable.
1969 * @codec: CODEC to query.
1970 * @reg: Register to query.
1972 * Boolean function indicating if a CODEC register is readable.
1974 int snd_soc_codec_readable_register(struct snd_soc_codec
*codec
,
1977 if (codec
->readable_register
)
1978 return codec
->readable_register(codec
, reg
);
1982 EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register
);
1985 * snd_soc_codec_writable_register: Report if a register is writable.
1987 * @codec: CODEC to query.
1988 * @reg: Register to query.
1990 * Boolean function indicating if a CODEC register is writable.
1992 int snd_soc_codec_writable_register(struct snd_soc_codec
*codec
,
1995 if (codec
->writable_register
)
1996 return codec
->writable_register(codec
, reg
);
2000 EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register
);
2002 int snd_soc_platform_read(struct snd_soc_platform
*platform
,
2007 if (!platform
->driver
->read
) {
2008 dev_err(platform
->dev
, "ASoC: platform has no read back\n");
2012 ret
= platform
->driver
->read(platform
, reg
);
2013 dev_dbg(platform
->dev
, "read %x => %x\n", reg
, ret
);
2014 trace_snd_soc_preg_read(platform
, reg
, ret
);
2018 EXPORT_SYMBOL_GPL(snd_soc_platform_read
);
2020 int snd_soc_platform_write(struct snd_soc_platform
*platform
,
2021 unsigned int reg
, unsigned int val
)
2023 if (!platform
->driver
->write
) {
2024 dev_err(platform
->dev
, "ASoC: platform has no write back\n");
2028 dev_dbg(platform
->dev
, "write %x = %x\n", reg
, val
);
2029 trace_snd_soc_preg_write(platform
, reg
, val
);
2030 return platform
->driver
->write(platform
, reg
, val
);
2032 EXPORT_SYMBOL_GPL(snd_soc_platform_write
);
2035 * snd_soc_new_ac97_codec - initailise AC97 device
2036 * @codec: audio codec
2037 * @ops: AC97 bus operations
2038 * @num: AC97 codec number
2040 * Initialises AC97 codec resources for use by ad-hoc devices only.
2042 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
2043 struct snd_ac97_bus_ops
*ops
, int num
)
2045 mutex_lock(&codec
->mutex
);
2047 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
2048 if (codec
->ac97
== NULL
) {
2049 mutex_unlock(&codec
->mutex
);
2053 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
2054 if (codec
->ac97
->bus
== NULL
) {
2057 mutex_unlock(&codec
->mutex
);
2061 codec
->ac97
->bus
->ops
= ops
;
2062 codec
->ac97
->num
= num
;
2065 * Mark the AC97 device to be created by us. This way we ensure that the
2066 * device will be registered with the device subsystem later on.
2068 codec
->ac97_created
= 1;
2070 mutex_unlock(&codec
->mutex
);
2073 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
2076 * snd_soc_free_ac97_codec - free AC97 codec device
2077 * @codec: audio codec
2079 * Frees AC97 codec device resources.
2081 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
2083 mutex_lock(&codec
->mutex
);
2084 #ifdef CONFIG_SND_SOC_AC97_BUS
2085 soc_unregister_ac97_dai_link(codec
);
2087 kfree(codec
->ac97
->bus
);
2090 codec
->ac97_created
= 0;
2091 mutex_unlock(&codec
->mutex
);
2093 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
2095 unsigned int snd_soc_read(struct snd_soc_codec
*codec
, unsigned int reg
)
2099 ret
= codec
->read(codec
, reg
);
2100 dev_dbg(codec
->dev
, "read %x => %x\n", reg
, ret
);
2101 trace_snd_soc_reg_read(codec
, reg
, ret
);
2105 EXPORT_SYMBOL_GPL(snd_soc_read
);
2107 unsigned int snd_soc_write(struct snd_soc_codec
*codec
,
2108 unsigned int reg
, unsigned int val
)
2110 dev_dbg(codec
->dev
, "write %x = %x\n", reg
, val
);
2111 trace_snd_soc_reg_write(codec
, reg
, val
);
2112 return codec
->write(codec
, reg
, val
);
2114 EXPORT_SYMBOL_GPL(snd_soc_write
);
2116 unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec
*codec
,
2117 unsigned int reg
, const void *data
, size_t len
)
2119 return codec
->bulk_write_raw(codec
, reg
, data
, len
);
2121 EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw
);
2124 * snd_soc_update_bits - update codec register bits
2125 * @codec: audio codec
2126 * @reg: codec register
2127 * @mask: register mask
2130 * Writes new register value.
2132 * Returns 1 for change, 0 for no change, or negative error code.
2134 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2135 unsigned int mask
, unsigned int value
)
2138 unsigned int old
, new;
2141 if (codec
->using_regmap
) {
2142 ret
= regmap_update_bits_check(codec
->control_data
, reg
,
2143 mask
, value
, &change
);
2145 ret
= snd_soc_read(codec
, reg
);
2150 new = (old
& ~mask
) | (value
& mask
);
2151 change
= old
!= new;
2153 ret
= snd_soc_write(codec
, reg
, new);
2161 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
2164 * snd_soc_update_bits_locked - update codec register bits
2165 * @codec: audio codec
2166 * @reg: codec register
2167 * @mask: register mask
2170 * Writes new register value, and takes the codec mutex.
2172 * Returns 1 for change else 0.
2174 int snd_soc_update_bits_locked(struct snd_soc_codec
*codec
,
2175 unsigned short reg
, unsigned int mask
,
2180 mutex_lock(&codec
->mutex
);
2181 change
= snd_soc_update_bits(codec
, reg
, mask
, value
);
2182 mutex_unlock(&codec
->mutex
);
2186 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked
);
2189 * snd_soc_test_bits - test register for change
2190 * @codec: audio codec
2191 * @reg: codec register
2192 * @mask: register mask
2195 * Tests a register with a new value and checks if the new value is
2196 * different from the old value.
2198 * Returns 1 for change else 0.
2200 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
2201 unsigned int mask
, unsigned int value
)
2204 unsigned int old
, new;
2206 old
= snd_soc_read(codec
, reg
);
2207 new = (old
& ~mask
) | value
;
2208 change
= old
!= new;
2212 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
2215 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
2216 * @substream: the pcm substream
2217 * @hw: the hardware parameters
2219 * Sets the substream runtime hardware parameters.
2221 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
2222 const struct snd_pcm_hardware
*hw
)
2224 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2225 runtime
->hw
.info
= hw
->info
;
2226 runtime
->hw
.formats
= hw
->formats
;
2227 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
2228 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
2229 runtime
->hw
.periods_min
= hw
->periods_min
;
2230 runtime
->hw
.periods_max
= hw
->periods_max
;
2231 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
2232 runtime
->hw
.fifo_size
= hw
->fifo_size
;
2235 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
2238 * snd_soc_cnew - create new control
2239 * @_template: control template
2240 * @data: control private data
2241 * @long_name: control long name
2242 * @prefix: control name prefix
2244 * Create a new mixer control from a template control.
2246 * Returns 0 for success, else error.
2248 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2249 void *data
, const char *long_name
,
2252 struct snd_kcontrol_new
template;
2253 struct snd_kcontrol
*kcontrol
;
2257 memcpy(&template, _template
, sizeof(template));
2261 long_name
= template.name
;
2264 name_len
= strlen(long_name
) + strlen(prefix
) + 2;
2265 name
= kmalloc(name_len
, GFP_KERNEL
);
2269 snprintf(name
, name_len
, "%s %s", prefix
, long_name
);
2271 template.name
= name
;
2273 template.name
= long_name
;
2276 kcontrol
= snd_ctl_new1(&template, data
);
2282 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2284 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2285 const struct snd_kcontrol_new
*controls
, int num_controls
,
2286 const char *prefix
, void *data
)
2290 for (i
= 0; i
< num_controls
; i
++) {
2291 const struct snd_kcontrol_new
*control
= &controls
[i
];
2292 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2293 control
->name
, prefix
));
2295 dev_err(dev
, "ASoC: Failed to add %s: %d\n",
2296 control
->name
, err
);
2305 * snd_soc_add_codec_controls - add an array of controls to a codec.
2306 * Convenience function to add a list of controls. Many codecs were
2307 * duplicating this code.
2309 * @codec: codec to add controls to
2310 * @controls: array of controls to add
2311 * @num_controls: number of elements in the array
2313 * Return 0 for success, else error.
2315 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2316 const struct snd_kcontrol_new
*controls
, int num_controls
)
2318 struct snd_card
*card
= codec
->card
->snd_card
;
2320 return snd_soc_add_controls(card
, codec
->dev
, controls
, num_controls
,
2321 codec
->name_prefix
, codec
);
2323 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2326 * snd_soc_add_platform_controls - add an array of controls to a platform.
2327 * Convenience function to add a list of controls.
2329 * @platform: platform to add controls to
2330 * @controls: array of controls to add
2331 * @num_controls: number of elements in the array
2333 * Return 0 for success, else error.
2335 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2336 const struct snd_kcontrol_new
*controls
, int num_controls
)
2338 struct snd_card
*card
= platform
->card
->snd_card
;
2340 return snd_soc_add_controls(card
, platform
->dev
, controls
, num_controls
,
2343 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2346 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2347 * Convenience function to add a list of controls.
2349 * @soc_card: SoC card to add controls to
2350 * @controls: array of controls to add
2351 * @num_controls: number of elements in the array
2353 * Return 0 for success, else error.
2355 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2356 const struct snd_kcontrol_new
*controls
, int num_controls
)
2358 struct snd_card
*card
= soc_card
->snd_card
;
2360 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2363 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2366 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2367 * Convienience function to add a list of controls.
2369 * @dai: DAI to add controls to
2370 * @controls: array of controls to add
2371 * @num_controls: number of elements in the array
2373 * Return 0 for success, else error.
2375 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2376 const struct snd_kcontrol_new
*controls
, int num_controls
)
2378 struct snd_card
*card
= dai
->card
->snd_card
;
2380 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2383 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2386 * snd_soc_info_enum_double - enumerated double mixer info callback
2387 * @kcontrol: mixer control
2388 * @uinfo: control element information
2390 * Callback to provide information about a double enumerated
2393 * Returns 0 for success.
2395 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2396 struct snd_ctl_elem_info
*uinfo
)
2398 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2400 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2401 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2402 uinfo
->value
.enumerated
.items
= e
->max
;
2404 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2405 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2406 strcpy(uinfo
->value
.enumerated
.name
,
2407 e
->texts
[uinfo
->value
.enumerated
.item
]);
2410 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2413 * snd_soc_get_enum_double - enumerated double mixer get callback
2414 * @kcontrol: mixer control
2415 * @ucontrol: control element information
2417 * Callback to get the value of a double enumerated mixer.
2419 * Returns 0 for success.
2421 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2422 struct snd_ctl_elem_value
*ucontrol
)
2424 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2425 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2428 val
= snd_soc_read(codec
, e
->reg
);
2429 ucontrol
->value
.enumerated
.item
[0]
2430 = (val
>> e
->shift_l
) & e
->mask
;
2431 if (e
->shift_l
!= e
->shift_r
)
2432 ucontrol
->value
.enumerated
.item
[1] =
2433 (val
>> e
->shift_r
) & e
->mask
;
2437 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2440 * snd_soc_put_enum_double - enumerated double mixer put callback
2441 * @kcontrol: mixer control
2442 * @ucontrol: control element information
2444 * Callback to set the value of a double enumerated mixer.
2446 * Returns 0 for success.
2448 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2449 struct snd_ctl_elem_value
*ucontrol
)
2451 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2452 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2456 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2458 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
2459 mask
= e
->mask
<< e
->shift_l
;
2460 if (e
->shift_l
!= e
->shift_r
) {
2461 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2463 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
2464 mask
|= e
->mask
<< e
->shift_r
;
2467 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2469 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2472 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2473 * @kcontrol: mixer control
2474 * @ucontrol: control element information
2476 * Callback to get the value of a double semi enumerated mixer.
2478 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2479 * used for handling bitfield coded enumeration for example.
2481 * Returns 0 for success.
2483 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
2484 struct snd_ctl_elem_value
*ucontrol
)
2486 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2487 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2488 unsigned int reg_val
, val
, mux
;
2490 reg_val
= snd_soc_read(codec
, e
->reg
);
2491 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2492 for (mux
= 0; mux
< e
->max
; mux
++) {
2493 if (val
== e
->values
[mux
])
2496 ucontrol
->value
.enumerated
.item
[0] = mux
;
2497 if (e
->shift_l
!= e
->shift_r
) {
2498 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
2499 for (mux
= 0; mux
< e
->max
; mux
++) {
2500 if (val
== e
->values
[mux
])
2503 ucontrol
->value
.enumerated
.item
[1] = mux
;
2508 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
2511 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2512 * @kcontrol: mixer control
2513 * @ucontrol: control element information
2515 * Callback to set the value of a double semi enumerated mixer.
2517 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2518 * used for handling bitfield coded enumeration for example.
2520 * Returns 0 for success.
2522 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
2523 struct snd_ctl_elem_value
*ucontrol
)
2525 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2526 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2530 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
2532 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
2533 mask
= e
->mask
<< e
->shift_l
;
2534 if (e
->shift_l
!= e
->shift_r
) {
2535 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
2537 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
2538 mask
|= e
->mask
<< e
->shift_r
;
2541 return snd_soc_update_bits_locked(codec
, e
->reg
, mask
, val
);
2543 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
2546 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2547 * @kcontrol: mixer control
2548 * @uinfo: control element information
2550 * Callback to provide information about an external enumerated
2553 * Returns 0 for success.
2555 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
2556 struct snd_ctl_elem_info
*uinfo
)
2558 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2560 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2562 uinfo
->value
.enumerated
.items
= e
->max
;
2564 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
2565 uinfo
->value
.enumerated
.item
= e
->max
- 1;
2566 strcpy(uinfo
->value
.enumerated
.name
,
2567 e
->texts
[uinfo
->value
.enumerated
.item
]);
2570 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
2573 * snd_soc_info_volsw_ext - external single mixer info callback
2574 * @kcontrol: mixer control
2575 * @uinfo: control element information
2577 * Callback to provide information about a single external mixer control.
2579 * Returns 0 for success.
2581 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
2582 struct snd_ctl_elem_info
*uinfo
)
2584 int max
= kcontrol
->private_value
;
2586 if (max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2587 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2589 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2592 uinfo
->value
.integer
.min
= 0;
2593 uinfo
->value
.integer
.max
= max
;
2596 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
2599 * snd_soc_info_volsw - single mixer info callback
2600 * @kcontrol: mixer control
2601 * @uinfo: control element information
2603 * Callback to provide information about a single mixer control, or a double
2604 * mixer control that spans 2 registers.
2606 * Returns 0 for success.
2608 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2609 struct snd_ctl_elem_info
*uinfo
)
2611 struct soc_mixer_control
*mc
=
2612 (struct soc_mixer_control
*)kcontrol
->private_value
;
2615 if (!mc
->platform_max
)
2616 mc
->platform_max
= mc
->max
;
2617 platform_max
= mc
->platform_max
;
2619 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2620 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2622 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2624 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2625 uinfo
->value
.integer
.min
= 0;
2626 uinfo
->value
.integer
.max
= platform_max
;
2629 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2632 * snd_soc_get_volsw - single mixer get callback
2633 * @kcontrol: mixer control
2634 * @ucontrol: control element information
2636 * Callback to get the value of a single mixer control, or a double mixer
2637 * control that spans 2 registers.
2639 * Returns 0 for success.
2641 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2642 struct snd_ctl_elem_value
*ucontrol
)
2644 struct soc_mixer_control
*mc
=
2645 (struct soc_mixer_control
*)kcontrol
->private_value
;
2646 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2647 unsigned int reg
= mc
->reg
;
2648 unsigned int reg2
= mc
->rreg
;
2649 unsigned int shift
= mc
->shift
;
2650 unsigned int rshift
= mc
->rshift
;
2652 unsigned int mask
= (1 << fls(max
)) - 1;
2653 unsigned int invert
= mc
->invert
;
2655 ucontrol
->value
.integer
.value
[0] =
2656 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2658 ucontrol
->value
.integer
.value
[0] =
2659 max
- ucontrol
->value
.integer
.value
[0];
2661 if (snd_soc_volsw_is_stereo(mc
)) {
2663 ucontrol
->value
.integer
.value
[1] =
2664 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
2666 ucontrol
->value
.integer
.value
[1] =
2667 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
2669 ucontrol
->value
.integer
.value
[1] =
2670 max
- ucontrol
->value
.integer
.value
[1];
2675 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2678 * snd_soc_put_volsw - single mixer put callback
2679 * @kcontrol: mixer control
2680 * @ucontrol: control element information
2682 * Callback to set the value of a single mixer control, or a double mixer
2683 * control that spans 2 registers.
2685 * Returns 0 for success.
2687 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2688 struct snd_ctl_elem_value
*ucontrol
)
2690 struct soc_mixer_control
*mc
=
2691 (struct soc_mixer_control
*)kcontrol
->private_value
;
2692 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2693 unsigned int reg
= mc
->reg
;
2694 unsigned int reg2
= mc
->rreg
;
2695 unsigned int shift
= mc
->shift
;
2696 unsigned int rshift
= mc
->rshift
;
2698 unsigned int mask
= (1 << fls(max
)) - 1;
2699 unsigned int invert
= mc
->invert
;
2702 unsigned int val2
= 0;
2703 unsigned int val
, val_mask
;
2705 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
2708 val_mask
= mask
<< shift
;
2710 if (snd_soc_volsw_is_stereo(mc
)) {
2711 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
2715 val_mask
|= mask
<< rshift
;
2716 val
|= val2
<< rshift
;
2718 val2
= val2
<< shift
;
2722 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2727 err
= snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
);
2731 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2734 * snd_soc_get_volsw_sx - single mixer get callback
2735 * @kcontrol: mixer control
2736 * @ucontrol: control element information
2738 * Callback to get the value of a single mixer control, or a double mixer
2739 * control that spans 2 registers.
2741 * Returns 0 for success.
2743 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2744 struct snd_ctl_elem_value
*ucontrol
)
2746 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2747 struct soc_mixer_control
*mc
=
2748 (struct soc_mixer_control
*)kcontrol
->private_value
;
2750 unsigned int reg
= mc
->reg
;
2751 unsigned int reg2
= mc
->rreg
;
2752 unsigned int shift
= mc
->shift
;
2753 unsigned int rshift
= mc
->rshift
;
2756 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2758 ucontrol
->value
.integer
.value
[0] =
2759 ((snd_soc_read(codec
, reg
) >> shift
) - min
) & mask
;
2761 if (snd_soc_volsw_is_stereo(mc
))
2762 ucontrol
->value
.integer
.value
[1] =
2763 ((snd_soc_read(codec
, reg2
) >> rshift
) - min
) & mask
;
2767 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2770 * snd_soc_put_volsw_sx - double mixer set callback
2771 * @kcontrol: mixer control
2772 * @uinfo: control element information
2774 * Callback to set the value of a double mixer control that spans 2 registers.
2776 * Returns 0 for success.
2778 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2779 struct snd_ctl_elem_value
*ucontrol
)
2781 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2782 struct soc_mixer_control
*mc
=
2783 (struct soc_mixer_control
*)kcontrol
->private_value
;
2785 unsigned int reg
= mc
->reg
;
2786 unsigned int reg2
= mc
->rreg
;
2787 unsigned int shift
= mc
->shift
;
2788 unsigned int rshift
= mc
->rshift
;
2791 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2793 unsigned short val
, val_mask
, val2
= 0;
2795 val_mask
= mask
<< shift
;
2796 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2799 err
= snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2803 if (snd_soc_volsw_is_stereo(mc
)) {
2804 val_mask
= mask
<< rshift
;
2805 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2806 val2
= val2
<< rshift
;
2808 if (snd_soc_update_bits_locked(codec
, reg2
, val_mask
, val2
))
2813 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2816 * snd_soc_info_volsw_s8 - signed mixer info callback
2817 * @kcontrol: mixer control
2818 * @uinfo: control element information
2820 * Callback to provide information about a signed mixer control.
2822 * Returns 0 for success.
2824 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2825 struct snd_ctl_elem_info
*uinfo
)
2827 struct soc_mixer_control
*mc
=
2828 (struct soc_mixer_control
*)kcontrol
->private_value
;
2832 if (!mc
->platform_max
)
2833 mc
->platform_max
= mc
->max
;
2834 platform_max
= mc
->platform_max
;
2836 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2838 uinfo
->value
.integer
.min
= 0;
2839 uinfo
->value
.integer
.max
= platform_max
- min
;
2842 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2845 * snd_soc_get_volsw_s8 - signed mixer get callback
2846 * @kcontrol: mixer control
2847 * @ucontrol: control element information
2849 * Callback to get the value of a signed mixer control.
2851 * Returns 0 for success.
2853 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2854 struct snd_ctl_elem_value
*ucontrol
)
2856 struct soc_mixer_control
*mc
=
2857 (struct soc_mixer_control
*)kcontrol
->private_value
;
2858 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2859 unsigned int reg
= mc
->reg
;
2861 int val
= snd_soc_read(codec
, reg
);
2863 ucontrol
->value
.integer
.value
[0] =
2864 ((signed char)(val
& 0xff))-min
;
2865 ucontrol
->value
.integer
.value
[1] =
2866 ((signed char)((val
>> 8) & 0xff))-min
;
2869 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2872 * snd_soc_put_volsw_sgn - signed mixer put callback
2873 * @kcontrol: mixer control
2874 * @ucontrol: control element information
2876 * Callback to set the value of a signed mixer control.
2878 * Returns 0 for success.
2880 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2881 struct snd_ctl_elem_value
*ucontrol
)
2883 struct soc_mixer_control
*mc
=
2884 (struct soc_mixer_control
*)kcontrol
->private_value
;
2885 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2886 unsigned int reg
= mc
->reg
;
2890 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2891 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2893 return snd_soc_update_bits_locked(codec
, reg
, 0xffff, val
);
2895 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2898 * snd_soc_info_volsw_range - single mixer info callback with range.
2899 * @kcontrol: mixer control
2900 * @uinfo: control element information
2902 * Callback to provide information, within a range, about a single
2905 * returns 0 for success.
2907 int snd_soc_info_volsw_range(struct snd_kcontrol
*kcontrol
,
2908 struct snd_ctl_elem_info
*uinfo
)
2910 struct soc_mixer_control
*mc
=
2911 (struct soc_mixer_control
*)kcontrol
->private_value
;
2915 if (!mc
->platform_max
)
2916 mc
->platform_max
= mc
->max
;
2917 platform_max
= mc
->platform_max
;
2919 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2921 uinfo
->value
.integer
.min
= 0;
2922 uinfo
->value
.integer
.max
= platform_max
- min
;
2926 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range
);
2929 * snd_soc_put_volsw_range - single mixer put value callback with range.
2930 * @kcontrol: mixer control
2931 * @ucontrol: control element information
2933 * Callback to set the value, within a range, for a single mixer control.
2935 * Returns 0 for success.
2937 int snd_soc_put_volsw_range(struct snd_kcontrol
*kcontrol
,
2938 struct snd_ctl_elem_value
*ucontrol
)
2940 struct soc_mixer_control
*mc
=
2941 (struct soc_mixer_control
*)kcontrol
->private_value
;
2942 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2943 unsigned int reg
= mc
->reg
;
2944 unsigned int shift
= mc
->shift
;
2947 unsigned int mask
= (1 << fls(max
)) - 1;
2948 unsigned int invert
= mc
->invert
;
2949 unsigned int val
, val_mask
;
2951 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2954 val_mask
= mask
<< shift
;
2957 return snd_soc_update_bits_locked(codec
, reg
, val_mask
, val
);
2959 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range
);
2962 * snd_soc_get_volsw_range - single mixer get callback with range
2963 * @kcontrol: mixer control
2964 * @ucontrol: control element information
2966 * Callback to get the value, within a range, of a single mixer control.
2968 * Returns 0 for success.
2970 int snd_soc_get_volsw_range(struct snd_kcontrol
*kcontrol
,
2971 struct snd_ctl_elem_value
*ucontrol
)
2973 struct soc_mixer_control
*mc
=
2974 (struct soc_mixer_control
*)kcontrol
->private_value
;
2975 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2976 unsigned int reg
= mc
->reg
;
2977 unsigned int shift
= mc
->shift
;
2980 unsigned int mask
= (1 << fls(max
)) - 1;
2981 unsigned int invert
= mc
->invert
;
2983 ucontrol
->value
.integer
.value
[0] =
2984 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
2986 ucontrol
->value
.integer
.value
[0] =
2987 max
- ucontrol
->value
.integer
.value
[0];
2988 ucontrol
->value
.integer
.value
[0] =
2989 ucontrol
->value
.integer
.value
[0] - min
;
2993 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range
);
2996 * snd_soc_limit_volume - Set new limit to an existing volume control.
2998 * @codec: where to look for the control
2999 * @name: Name of the control
3000 * @max: new maximum limit
3002 * Return 0 for success, else error.
3004 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
3005 const char *name
, int max
)
3007 struct snd_card
*card
= codec
->card
->snd_card
;
3008 struct snd_kcontrol
*kctl
;
3009 struct soc_mixer_control
*mc
;
3013 /* Sanity check for name and max */
3014 if (unlikely(!name
|| max
<= 0))
3017 list_for_each_entry(kctl
, &card
->controls
, list
) {
3018 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
3024 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
3025 if (max
<= mc
->max
) {
3026 mc
->platform_max
= max
;
3032 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
3034 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
3035 struct snd_ctl_elem_info
*uinfo
)
3037 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3038 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3040 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3041 uinfo
->count
= params
->num_regs
* codec
->val_bytes
;
3045 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
3047 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
3048 struct snd_ctl_elem_value
*ucontrol
)
3050 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3051 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3054 if (codec
->using_regmap
)
3055 ret
= regmap_raw_read(codec
->control_data
, params
->base
,
3056 ucontrol
->value
.bytes
.data
,
3057 params
->num_regs
* codec
->val_bytes
);
3061 /* Hide any masked bytes to ensure consistent data reporting */
3062 if (ret
== 0 && params
->mask
) {
3063 switch (codec
->val_bytes
) {
3065 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
3068 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
3072 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
3082 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
3084 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
3085 struct snd_ctl_elem_value
*ucontrol
)
3087 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3088 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3093 if (!codec
->using_regmap
)
3096 data
= ucontrol
->value
.bytes
.data
;
3097 len
= params
->num_regs
* codec
->val_bytes
;
3100 * If we've got a mask then we need to preserve the register
3101 * bits. We shouldn't modify the incoming data so take a
3105 ret
= regmap_read(codec
->control_data
, params
->base
, &val
);
3109 val
&= params
->mask
;
3111 data
= kmemdup(data
, len
, GFP_KERNEL
);
3115 switch (codec
->val_bytes
) {
3117 ((u8
*)data
)[0] &= ~params
->mask
;
3118 ((u8
*)data
)[0] |= val
;
3121 ((u16
*)data
)[0] &= cpu_to_be16(~params
->mask
);
3122 ((u16
*)data
)[0] |= cpu_to_be16(val
);
3125 ((u32
*)data
)[0] &= cpu_to_be32(~params
->mask
);
3126 ((u32
*)data
)[0] |= cpu_to_be32(val
);
3133 ret
= regmap_raw_write(codec
->control_data
, params
->base
,
3141 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
3144 * snd_soc_info_xr_sx - signed multi register info callback
3145 * @kcontrol: mreg control
3146 * @uinfo: control element information
3148 * Callback to provide information of a control that can
3149 * span multiple codec registers which together
3150 * forms a single signed value in a MSB/LSB manner.
3152 * Returns 0 for success.
3154 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
3155 struct snd_ctl_elem_info
*uinfo
)
3157 struct soc_mreg_control
*mc
=
3158 (struct soc_mreg_control
*)kcontrol
->private_value
;
3159 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3161 uinfo
->value
.integer
.min
= mc
->min
;
3162 uinfo
->value
.integer
.max
= mc
->max
;
3166 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
3169 * snd_soc_get_xr_sx - signed multi register get callback
3170 * @kcontrol: mreg control
3171 * @ucontrol: control element information
3173 * Callback to get the value of a control that can span
3174 * multiple codec registers which together forms a single
3175 * signed value in a MSB/LSB manner. The control supports
3176 * specifying total no of bits used to allow for bitfields
3177 * across the multiple codec registers.
3179 * Returns 0 for success.
3181 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
3182 struct snd_ctl_elem_value
*ucontrol
)
3184 struct soc_mreg_control
*mc
=
3185 (struct soc_mreg_control
*)kcontrol
->private_value
;
3186 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3187 unsigned int regbase
= mc
->regbase
;
3188 unsigned int regcount
= mc
->regcount
;
3189 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3190 unsigned int regwmask
= (1<<regwshift
)-1;
3191 unsigned int invert
= mc
->invert
;
3192 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3196 unsigned long regval
;
3199 for (i
= 0; i
< regcount
; i
++) {
3200 regval
= snd_soc_read(codec
, regbase
+i
) & regwmask
;
3201 val
|= regval
<< (regwshift
*(regcount
-i
-1));
3204 if (min
< 0 && val
> max
)
3208 ucontrol
->value
.integer
.value
[0] = val
;
3212 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3215 * snd_soc_put_xr_sx - signed multi register get callback
3216 * @kcontrol: mreg control
3217 * @ucontrol: control element information
3219 * Callback to set the value of a control that can span
3220 * multiple codec registers which together forms a single
3221 * signed value in a MSB/LSB manner. The control supports
3222 * specifying total no of bits used to allow for bitfields
3223 * across the multiple codec registers.
3225 * Returns 0 for success.
3227 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3228 struct snd_ctl_elem_value
*ucontrol
)
3230 struct soc_mreg_control
*mc
=
3231 (struct soc_mreg_control
*)kcontrol
->private_value
;
3232 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3233 unsigned int regbase
= mc
->regbase
;
3234 unsigned int regcount
= mc
->regcount
;
3235 unsigned int regwshift
= codec
->driver
->reg_word_size
* BITS_PER_BYTE
;
3236 unsigned int regwmask
= (1<<regwshift
)-1;
3237 unsigned int invert
= mc
->invert
;
3238 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3240 long val
= ucontrol
->value
.integer
.value
[0];
3241 unsigned int i
, regval
, regmask
;
3247 for (i
= 0; i
< regcount
; i
++) {
3248 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3249 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3250 err
= snd_soc_update_bits_locked(codec
, regbase
+i
,
3258 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3261 * snd_soc_get_strobe - strobe get callback
3262 * @kcontrol: mixer control
3263 * @ucontrol: control element information
3265 * Callback get the value of a strobe mixer control.
3267 * Returns 0 for success.
3269 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3270 struct snd_ctl_elem_value
*ucontrol
)
3272 struct soc_mixer_control
*mc
=
3273 (struct soc_mixer_control
*)kcontrol
->private_value
;
3274 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3275 unsigned int reg
= mc
->reg
;
3276 unsigned int shift
= mc
->shift
;
3277 unsigned int mask
= 1 << shift
;
3278 unsigned int invert
= mc
->invert
!= 0;
3279 unsigned int val
= snd_soc_read(codec
, reg
) & mask
;
3281 if (shift
!= 0 && val
!= 0)
3283 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3287 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3290 * snd_soc_put_strobe - strobe put callback
3291 * @kcontrol: mixer control
3292 * @ucontrol: control element information
3294 * Callback strobe a register bit to high then low (or the inverse)
3295 * in one pass of a single mixer enum control.
3297 * Returns 1 for success.
3299 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3300 struct snd_ctl_elem_value
*ucontrol
)
3302 struct soc_mixer_control
*mc
=
3303 (struct soc_mixer_control
*)kcontrol
->private_value
;
3304 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3305 unsigned int reg
= mc
->reg
;
3306 unsigned int shift
= mc
->shift
;
3307 unsigned int mask
= 1 << shift
;
3308 unsigned int invert
= mc
->invert
!= 0;
3309 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3310 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3311 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3314 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val1
);
3318 err
= snd_soc_update_bits_locked(codec
, reg
, mask
, val2
);
3321 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3324 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3326 * @clk_id: DAI specific clock ID
3327 * @freq: new clock frequency in Hz
3328 * @dir: new clock direction - input/output.
3330 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3332 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3333 unsigned int freq
, int dir
)
3335 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3336 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3337 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3338 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3343 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3346 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3348 * @clk_id: DAI specific clock ID
3349 * @source: Source for the clock
3350 * @freq: new clock frequency in Hz
3351 * @dir: new clock direction - input/output.
3353 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3355 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3356 int source
, unsigned int freq
, int dir
)
3358 if (codec
->driver
->set_sysclk
)
3359 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3364 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3367 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3369 * @div_id: DAI specific clock divider ID
3370 * @div: new clock divisor.
3372 * Configures the clock dividers. This is used to derive the best DAI bit and
3373 * frame clocks from the system or master clock. It's best to set the DAI bit
3374 * and frame clocks as low as possible to save system power.
3376 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3377 int div_id
, int div
)
3379 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3380 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3384 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3387 * snd_soc_dai_set_pll - configure DAI PLL.
3389 * @pll_id: DAI specific PLL ID
3390 * @source: DAI specific source for the PLL
3391 * @freq_in: PLL input clock frequency in Hz
3392 * @freq_out: requested PLL output clock frequency in Hz
3394 * Configures and enables PLL to generate output clock based on input clock.
3396 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3397 unsigned int freq_in
, unsigned int freq_out
)
3399 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3400 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3402 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3403 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3408 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3411 * snd_soc_codec_set_pll - configure codec PLL.
3413 * @pll_id: DAI specific PLL ID
3414 * @source: DAI specific source for the PLL
3415 * @freq_in: PLL input clock frequency in Hz
3416 * @freq_out: requested PLL output clock frequency in Hz
3418 * Configures and enables PLL to generate output clock based on input clock.
3420 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3421 unsigned int freq_in
, unsigned int freq_out
)
3423 if (codec
->driver
->set_pll
)
3424 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3429 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3432 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3434 * @fmt: SND_SOC_DAIFMT_ format value.
3436 * Configures the DAI hardware format and clocking.
3438 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3440 if (dai
->driver
== NULL
)
3442 if (dai
->driver
->ops
->set_fmt
== NULL
)
3444 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3446 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3449 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3451 * @tx_mask: bitmask representing active TX slots.
3452 * @rx_mask: bitmask representing active RX slots.
3453 * @slots: Number of slots in use.
3454 * @slot_width: Width in bits for each slot.
3456 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3459 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3460 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3462 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3463 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3468 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3471 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3473 * @tx_num: how many TX channels
3474 * @tx_slot: pointer to an array which imply the TX slot number channel
3476 * @rx_num: how many RX channels
3477 * @rx_slot: pointer to an array which imply the RX slot number channel
3480 * configure the relationship between channel number and TDM slot number.
3482 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3483 unsigned int tx_num
, unsigned int *tx_slot
,
3484 unsigned int rx_num
, unsigned int *rx_slot
)
3486 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3487 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3492 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3495 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3497 * @tristate: tristate enable
3499 * Tristates the DAI so that others can use it.
3501 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3503 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3504 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3508 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3511 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3513 * @mute: mute enable
3515 * Mutes the DAI DAC.
3517 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
3519 if (dai
->driver
&& dai
->driver
->ops
->digital_mute
)
3520 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3524 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3527 * snd_soc_register_card - Register a card with the ASoC core
3529 * @card: Card to register
3532 int snd_soc_register_card(struct snd_soc_card
*card
)
3536 if (!card
->name
|| !card
->dev
)
3539 for (i
= 0; i
< card
->num_links
; i
++) {
3540 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3543 * Codec must be specified by 1 of name or OF node,
3544 * not both or neither.
3546 if (!!link
->codec_name
== !!link
->codec_of_node
) {
3547 dev_err(card
->dev
, "ASoC: Neither/both codec"
3548 " name/of_node are set for %s\n", link
->name
);
3551 /* Codec DAI name must be specified */
3552 if (!link
->codec_dai_name
) {
3553 dev_err(card
->dev
, "ASoC: codec_dai_name not"
3554 " set for %s\n", link
->name
);
3559 * Platform may be specified by either name or OF node, but
3560 * can be left unspecified, and a dummy platform will be used.
3562 if (link
->platform_name
&& link
->platform_of_node
) {
3563 dev_err(card
->dev
, "ASoC: Both platform name/of_node"
3564 " are set for %s\n", link
->name
);
3569 * CPU device may be specified by either name or OF node, but
3570 * can be left unspecified, and will be matched based on DAI
3573 if (link
->cpu_name
&& link
->cpu_of_node
) {
3574 dev_err(card
->dev
, "ASoC: Neither/both "
3575 "cpu name/of_node are set for %s\n",link
->name
);
3579 * At least one of CPU DAI name or CPU device name/node must be
3582 if (!link
->cpu_dai_name
&&
3583 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3584 dev_err(card
->dev
, "ASoC: Neither cpu_dai_name nor "
3585 "cpu_name/of_node are set for %s\n", link
->name
);
3590 dev_set_drvdata(card
->dev
, card
);
3592 snd_soc_initialize_card_lists(card
);
3594 soc_init_card_debugfs(card
);
3596 card
->rtd
= devm_kzalloc(card
->dev
,
3597 sizeof(struct snd_soc_pcm_runtime
) *
3598 (card
->num_links
+ card
->num_aux_devs
),
3600 if (card
->rtd
== NULL
)
3603 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3605 for (i
= 0; i
< card
->num_links
; i
++)
3606 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3608 INIT_LIST_HEAD(&card
->list
);
3609 INIT_LIST_HEAD(&card
->dapm_dirty
);
3610 card
->instantiated
= 0;
3611 mutex_init(&card
->mutex
);
3612 mutex_init(&card
->dapm_mutex
);
3614 ret
= snd_soc_instantiate_card(card
);
3616 soc_cleanup_card_debugfs(card
);
3620 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3623 * snd_soc_unregister_card - Unregister a card with the ASoC core
3625 * @card: Card to unregister
3628 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3630 if (card
->instantiated
)
3631 soc_cleanup_card_resources(card
);
3632 dev_dbg(card
->dev
, "ASoC: Unregistered card '%s'\n", card
->name
);
3636 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3639 * Simplify DAI link configuration by removing ".-1" from device names
3640 * and sanitizing names.
3642 static char *fmt_single_name(struct device
*dev
, int *id
)
3644 char *found
, name
[NAME_SIZE
];
3647 if (dev_name(dev
) == NULL
)
3650 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3652 /* are we a "%s.%d" name (platform and SPI components) */
3653 found
= strstr(name
, dev
->driver
->name
);
3656 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3658 /* discard ID from name if ID == -1 */
3660 found
[strlen(dev
->driver
->name
)] = '\0';
3664 /* I2C component devices are named "bus-addr" */
3665 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3666 char tmp
[NAME_SIZE
];
3668 /* create unique ID number from I2C addr and bus */
3669 *id
= ((id1
& 0xffff) << 16) + id2
;
3671 /* sanitize component name for DAI link creation */
3672 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3673 strlcpy(name
, tmp
, NAME_SIZE
);
3678 return kstrdup(name
, GFP_KERNEL
);
3682 * Simplify DAI link naming for single devices with multiple DAIs by removing
3683 * any ".-1" and using the DAI name (instead of device name).
3685 static inline char *fmt_multiple_name(struct device
*dev
,
3686 struct snd_soc_dai_driver
*dai_drv
)
3688 if (dai_drv
->name
== NULL
) {
3689 dev_err(dev
, "ASoC: error - multiple DAI %s registered with"
3690 " no name\n", dev_name(dev
));
3694 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3698 * snd_soc_register_dai - Register a DAI with the ASoC core
3700 * @dai: DAI to register
3702 int snd_soc_register_dai(struct device
*dev
,
3703 struct snd_soc_dai_driver
*dai_drv
)
3705 struct snd_soc_codec
*codec
;
3706 struct snd_soc_dai
*dai
;
3708 dev_dbg(dev
, "ASoC: dai register %s\n", dev_name(dev
));
3710 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3714 /* create DAI component name */
3715 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3716 if (dai
->name
== NULL
) {
3722 dai
->driver
= dai_drv
;
3723 dai
->dapm
.dev
= dev
;
3724 if (!dai
->driver
->ops
)
3725 dai
->driver
->ops
= &null_dai_ops
;
3727 mutex_lock(&client_mutex
);
3729 list_for_each_entry(codec
, &codec_list
, list
) {
3730 if (codec
->dev
== dev
) {
3731 dev_dbg(dev
, "ASoC: Mapped DAI %s to CODEC %s\n",
3732 dai
->name
, codec
->name
);
3739 dai
->dapm
.idle_bias_off
= 1;
3741 list_add(&dai
->list
, &dai_list
);
3743 mutex_unlock(&client_mutex
);
3745 dev_dbg(dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3749 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
3752 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3754 * @dai: DAI to unregister
3756 void snd_soc_unregister_dai(struct device
*dev
)
3758 struct snd_soc_dai
*dai
;
3760 list_for_each_entry(dai
, &dai_list
, list
) {
3761 if (dev
== dai
->dev
)
3767 mutex_lock(&client_mutex
);
3768 list_del(&dai
->list
);
3769 mutex_unlock(&client_mutex
);
3771 dev_dbg(dev
, "ASoC: Unregistered DAI '%s'\n", dai
->name
);
3775 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
3778 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3780 * @dai: Array of DAIs to register
3781 * @count: Number of DAIs
3783 int snd_soc_register_dais(struct device
*dev
,
3784 struct snd_soc_dai_driver
*dai_drv
, size_t count
)
3786 struct snd_soc_codec
*codec
;
3787 struct snd_soc_dai
*dai
;
3790 dev_dbg(dev
, "ASoC: dai register %s #%Zu\n", dev_name(dev
), count
);
3792 for (i
= 0; i
< count
; i
++) {
3794 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3800 /* create DAI component name */
3801 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3802 if (dai
->name
== NULL
) {
3809 dai
->driver
= &dai_drv
[i
];
3810 if (dai
->driver
->id
)
3811 dai
->id
= dai
->driver
->id
;
3814 dai
->dapm
.dev
= dev
;
3815 if (!dai
->driver
->ops
)
3816 dai
->driver
->ops
= &null_dai_ops
;
3818 mutex_lock(&client_mutex
);
3820 list_for_each_entry(codec
, &codec_list
, list
) {
3821 if (codec
->dev
== dev
) {
3822 dev_dbg(dev
, "ASoC: Mapped DAI %s to "
3823 "CODEC %s\n", dai
->name
, codec
->name
);
3830 dai
->dapm
.idle_bias_off
= 1;
3832 list_add(&dai
->list
, &dai_list
);
3834 mutex_unlock(&client_mutex
);
3836 dev_dbg(dai
->dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3842 for (i
--; i
>= 0; i
--)
3843 snd_soc_unregister_dai(dev
);
3847 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
3850 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3852 * @dai: Array of DAIs to unregister
3853 * @count: Number of DAIs
3855 void snd_soc_unregister_dais(struct device
*dev
, size_t count
)
3859 for (i
= 0; i
< count
; i
++)
3860 snd_soc_unregister_dai(dev
);
3862 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
3865 * snd_soc_register_platform - Register a platform with the ASoC core
3867 * @platform: platform to register
3869 int snd_soc_register_platform(struct device
*dev
,
3870 struct snd_soc_platform_driver
*platform_drv
)
3872 struct snd_soc_platform
*platform
;
3874 dev_dbg(dev
, "ASoC: platform register %s\n", dev_name(dev
));
3876 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
3877 if (platform
== NULL
)
3880 /* create platform component name */
3881 platform
->name
= fmt_single_name(dev
, &platform
->id
);
3882 if (platform
->name
== NULL
) {
3887 platform
->dev
= dev
;
3888 platform
->driver
= platform_drv
;
3889 platform
->dapm
.dev
= dev
;
3890 platform
->dapm
.platform
= platform
;
3891 platform
->dapm
.stream_event
= platform_drv
->stream_event
;
3892 mutex_init(&platform
->mutex
);
3894 mutex_lock(&client_mutex
);
3895 list_add(&platform
->list
, &platform_list
);
3896 mutex_unlock(&client_mutex
);
3898 dev_dbg(dev
, "ASoC: Registered platform '%s'\n", platform
->name
);
3902 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
3905 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3907 * @platform: platform to unregister
3909 void snd_soc_unregister_platform(struct device
*dev
)
3911 struct snd_soc_platform
*platform
;
3913 list_for_each_entry(platform
, &platform_list
, list
) {
3914 if (dev
== platform
->dev
)
3920 mutex_lock(&client_mutex
);
3921 list_del(&platform
->list
);
3922 mutex_unlock(&client_mutex
);
3924 dev_dbg(dev
, "ASoC: Unregistered platform '%s'\n", platform
->name
);
3925 kfree(platform
->name
);
3928 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
3930 static u64 codec_format_map
[] = {
3931 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
3932 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
3933 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
3934 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
3935 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
3936 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
3937 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3938 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
3939 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
3940 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
3941 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
3942 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
3943 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
3944 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
3945 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3946 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
3949 /* Fix up the DAI formats for endianness: codecs don't actually see
3950 * the endianness of the data but we're using the CPU format
3951 * definitions which do need to include endianness so we ensure that
3952 * codec DAIs always have both big and little endian variants set.
3954 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
3958 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
3959 if (stream
->formats
& codec_format_map
[i
])
3960 stream
->formats
|= codec_format_map
[i
];
3964 * snd_soc_register_codec - Register a codec with the ASoC core
3966 * @codec: codec to register
3968 int snd_soc_register_codec(struct device
*dev
,
3969 const struct snd_soc_codec_driver
*codec_drv
,
3970 struct snd_soc_dai_driver
*dai_drv
,
3974 struct snd_soc_codec
*codec
;
3977 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
3979 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
3983 /* create CODEC component name */
3984 codec
->name
= fmt_single_name(dev
, &codec
->id
);
3985 if (codec
->name
== NULL
) {
3990 if (codec_drv
->compress_type
)
3991 codec
->compress_type
= codec_drv
->compress_type
;
3993 codec
->compress_type
= SND_SOC_FLAT_COMPRESSION
;
3995 codec
->write
= codec_drv
->write
;
3996 codec
->read
= codec_drv
->read
;
3997 codec
->volatile_register
= codec_drv
->volatile_register
;
3998 codec
->readable_register
= codec_drv
->readable_register
;
3999 codec
->writable_register
= codec_drv
->writable_register
;
4000 codec
->ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
4001 codec
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
4002 codec
->dapm
.dev
= dev
;
4003 codec
->dapm
.codec
= codec
;
4004 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
4005 codec
->dapm
.stream_event
= codec_drv
->stream_event
;
4007 codec
->driver
= codec_drv
;
4008 codec
->num_dai
= num_dai
;
4009 mutex_init(&codec
->mutex
);
4011 /* allocate CODEC register cache */
4012 if (codec_drv
->reg_cache_size
&& codec_drv
->reg_word_size
) {
4013 reg_size
= codec_drv
->reg_cache_size
* codec_drv
->reg_word_size
;
4014 codec
->reg_size
= reg_size
;
4015 /* it is necessary to make a copy of the default register cache
4016 * because in the case of using a compression type that requires
4017 * the default register cache to be marked as the
4018 * kernel might have freed the array by the time we initialize
4021 if (codec_drv
->reg_cache_default
) {
4022 codec
->reg_def_copy
= kmemdup(codec_drv
->reg_cache_default
,
4023 reg_size
, GFP_KERNEL
);
4024 if (!codec
->reg_def_copy
) {
4031 if (codec_drv
->reg_access_size
&& codec_drv
->reg_access_default
) {
4032 if (!codec
->volatile_register
)
4033 codec
->volatile_register
= snd_soc_default_volatile_register
;
4034 if (!codec
->readable_register
)
4035 codec
->readable_register
= snd_soc_default_readable_register
;
4036 if (!codec
->writable_register
)
4037 codec
->writable_register
= snd_soc_default_writable_register
;
4040 for (i
= 0; i
< num_dai
; i
++) {
4041 fixup_codec_formats(&dai_drv
[i
].playback
);
4042 fixup_codec_formats(&dai_drv
[i
].capture
);
4045 mutex_lock(&client_mutex
);
4046 list_add(&codec
->list
, &codec_list
);
4047 mutex_unlock(&client_mutex
);
4049 /* register any DAIs */
4051 ret
= snd_soc_register_dais(dev
, dai_drv
, num_dai
);
4053 dev_err(codec
->dev
, "ASoC: Failed to regster"
4054 " DAIs: %d\n", ret
);
4057 dev_dbg(codec
->dev
, "ASoC: Registered codec '%s'\n", codec
->name
);
4065 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
4068 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4070 * @codec: codec to unregister
4072 void snd_soc_unregister_codec(struct device
*dev
)
4074 struct snd_soc_codec
*codec
;
4077 list_for_each_entry(codec
, &codec_list
, list
) {
4078 if (dev
== codec
->dev
)
4085 for (i
= 0; i
< codec
->num_dai
; i
++)
4086 snd_soc_unregister_dai(dev
);
4088 mutex_lock(&client_mutex
);
4089 list_del(&codec
->list
);
4090 mutex_unlock(&client_mutex
);
4092 dev_dbg(codec
->dev
, "ASoC: Unregistered codec '%s'\n", codec
->name
);
4094 snd_soc_cache_exit(codec
);
4095 kfree(codec
->reg_def_copy
);
4099 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
4101 /* Retrieve a card's name from device tree */
4102 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
4103 const char *propname
)
4105 struct device_node
*np
= card
->dev
->of_node
;
4108 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
4110 * EINVAL means the property does not exist. This is fine providing
4111 * card->name was previously set, which is checked later in
4112 * snd_soc_register_card.
4114 if (ret
< 0 && ret
!= -EINVAL
) {
4116 "ASoC: Property '%s' could not be read: %d\n",
4123 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
4125 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
4126 const char *propname
)
4128 struct device_node
*np
= card
->dev
->of_node
;
4130 struct snd_soc_dapm_route
*routes
;
4133 num_routes
= of_property_count_strings(np
, propname
);
4134 if (num_routes
< 0 || num_routes
& 1) {
4135 dev_err(card
->dev
, "ASoC: Property '%s' does not exist or its"
4136 " length is not even\n", propname
);
4141 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4146 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
4150 "ASoC: Could not allocate DAPM route table\n");
4154 for (i
= 0; i
< num_routes
; i
++) {
4155 ret
= of_property_read_string_index(np
, propname
,
4156 2 * i
, &routes
[i
].sink
);
4159 "ASoC: Property '%s' index %d could not be read: %d\n",
4160 propname
, 2 * i
, ret
);
4164 ret
= of_property_read_string_index(np
, propname
,
4165 (2 * i
) + 1, &routes
[i
].source
);
4168 "ASoC: Property '%s' index %d could not be read: %d\n",
4169 propname
, (2 * i
) + 1, ret
);
4175 card
->num_dapm_routes
= num_routes
;
4176 card
->dapm_routes
= routes
;
4180 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
4182 static int __init
snd_soc_init(void)
4184 #ifdef CONFIG_DEBUG_FS
4185 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
4186 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
4187 pr_warn("ASoC: Failed to create debugfs directory\n");
4188 snd_soc_debugfs_root
= NULL
;
4191 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
4193 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4195 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
4197 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4199 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
4200 &platform_list_fops
))
4201 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4204 snd_soc_util_init();
4206 return platform_driver_register(&soc_driver
);
4208 module_init(snd_soc_init
);
4210 static void __exit
snd_soc_exit(void)
4212 snd_soc_util_exit();
4214 #ifdef CONFIG_DEBUG_FS
4215 debugfs_remove_recursive(snd_soc_debugfs_root
);
4217 platform_driver_unregister(&soc_driver
);
4219 module_exit(snd_soc_exit
);
4221 /* Module information */
4222 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4223 MODULE_DESCRIPTION("ALSA SoC Core");
4224 MODULE_LICENSE("GPL");
4225 MODULE_ALIAS("platform:soc-audio");