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/pinctrl/consumer.h>
34 #include <linux/ctype.h>
35 #include <linux/slab.h>
37 #include <linux/gpio.h>
38 #include <linux/of_gpio.h>
39 #include <sound/ac97_codec.h>
40 #include <sound/core.h>
41 #include <sound/jack.h>
42 #include <sound/pcm.h>
43 #include <sound/pcm_params.h>
44 #include <sound/soc.h>
45 #include <sound/soc-dpcm.h>
46 #include <sound/initval.h>
48 #define CREATE_TRACE_POINTS
49 #include <trace/events/asoc.h>
53 #ifdef CONFIG_DEBUG_FS
54 struct dentry
*snd_soc_debugfs_root
;
55 EXPORT_SYMBOL_GPL(snd_soc_debugfs_root
);
58 static DEFINE_MUTEX(client_mutex
);
59 static LIST_HEAD(platform_list
);
60 static LIST_HEAD(codec_list
);
61 static LIST_HEAD(component_list
);
64 * This is a timeout to do a DAPM powerdown after a stream is closed().
65 * It can be used to eliminate pops between different playback streams, e.g.
66 * between two audio tracks.
68 static int pmdown_time
= 5000;
69 module_param(pmdown_time
, int, 0);
70 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
72 struct snd_ac97_reset_cfg
{
74 struct pinctrl_state
*pstate_reset
;
75 struct pinctrl_state
*pstate_warm_reset
;
76 struct pinctrl_state
*pstate_run
;
82 /* returns the minimum number of bytes needed to represent
83 * a particular given value */
84 static int min_bytes_needed(unsigned long val
)
89 for (i
= (sizeof val
* 8) - 1; i
>= 0; --i
, ++c
)
92 c
= (sizeof val
* 8) - c
;
100 /* fill buf which is 'len' bytes with a formatted
101 * string of the form 'reg: value\n' */
102 static int format_register_str(struct snd_soc_codec
*codec
,
103 unsigned int reg
, char *buf
, size_t len
)
105 int wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
106 int regsize
= codec
->driver
->reg_word_size
* 2;
108 char tmpbuf
[len
+ 1];
109 char regbuf
[regsize
+ 1];
111 /* since tmpbuf is allocated on the stack, warn the callers if they
112 * try to abuse this function */
115 /* +2 for ': ' and + 1 for '\n' */
116 if (wordsize
+ regsize
+ 2 + 1 != len
)
119 ret
= snd_soc_read(codec
, reg
);
121 memset(regbuf
, 'X', regsize
);
122 regbuf
[regsize
] = '\0';
124 snprintf(regbuf
, regsize
+ 1, "%.*x", regsize
, ret
);
127 /* prepare the buffer */
128 snprintf(tmpbuf
, len
+ 1, "%.*x: %s\n", wordsize
, reg
, regbuf
);
129 /* copy it back to the caller without the '\0' */
130 memcpy(buf
, tmpbuf
, len
);
135 /* codec register dump */
136 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
,
137 size_t count
, loff_t pos
)
140 int wordsize
, regsize
;
145 wordsize
= min_bytes_needed(codec
->driver
->reg_cache_size
) * 2;
146 regsize
= codec
->driver
->reg_word_size
* 2;
148 len
= wordsize
+ regsize
+ 2 + 1;
150 if (!codec
->driver
->reg_cache_size
)
153 if (codec
->driver
->reg_cache_step
)
154 step
= codec
->driver
->reg_cache_step
;
156 for (i
= 0; i
< codec
->driver
->reg_cache_size
; i
+= step
) {
157 /* only support larger than PAGE_SIZE bytes debugfs
158 * entries for the default case */
160 if (total
+ len
>= count
- 1)
162 format_register_str(codec
, i
, buf
+ total
, len
);
168 total
= min(total
, count
- 1);
173 static ssize_t
codec_reg_show(struct device
*dev
,
174 struct device_attribute
*attr
, char *buf
)
176 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
178 return soc_codec_reg_show(rtd
->codec
, buf
, PAGE_SIZE
, 0);
181 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
183 static ssize_t
pmdown_time_show(struct device
*dev
,
184 struct device_attribute
*attr
, char *buf
)
186 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
188 return sprintf(buf
, "%ld\n", rtd
->pmdown_time
);
191 static ssize_t
pmdown_time_set(struct device
*dev
,
192 struct device_attribute
*attr
,
193 const char *buf
, size_t count
)
195 struct snd_soc_pcm_runtime
*rtd
= dev_get_drvdata(dev
);
198 ret
= kstrtol(buf
, 10, &rtd
->pmdown_time
);
205 static DEVICE_ATTR(pmdown_time
, 0644, pmdown_time_show
, pmdown_time_set
);
207 #ifdef CONFIG_DEBUG_FS
208 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
209 size_t count
, loff_t
*ppos
)
212 struct snd_soc_codec
*codec
= file
->private_data
;
215 if (*ppos
< 0 || !count
)
218 buf
= kmalloc(count
, GFP_KERNEL
);
222 ret
= soc_codec_reg_show(codec
, buf
, count
, *ppos
);
224 if (copy_to_user(user_buf
, buf
, ret
)) {
235 static ssize_t
codec_reg_write_file(struct file
*file
,
236 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
241 unsigned long reg
, value
;
242 struct snd_soc_codec
*codec
= file
->private_data
;
245 buf_size
= min(count
, (sizeof(buf
)-1));
246 if (copy_from_user(buf
, user_buf
, buf_size
))
250 while (*start
== ' ')
252 reg
= simple_strtoul(start
, &start
, 16);
253 while (*start
== ' ')
255 ret
= kstrtoul(start
, 16, &value
);
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER
, LOCKDEP_NOW_UNRELIABLE
);
262 snd_soc_write(codec
, reg
, value
);
266 static const struct file_operations codec_reg_fops
= {
268 .read
= codec_reg_read_file
,
269 .write
= codec_reg_write_file
,
270 .llseek
= default_llseek
,
273 static void soc_init_component_debugfs(struct snd_soc_component
*component
)
275 if (component
->debugfs_prefix
) {
278 name
= kasprintf(GFP_KERNEL
, "%s:%s",
279 component
->debugfs_prefix
, component
->name
);
281 component
->debugfs_root
= debugfs_create_dir(name
,
282 component
->card
->debugfs_card_root
);
286 component
->debugfs_root
= debugfs_create_dir(component
->name
,
287 component
->card
->debugfs_card_root
);
290 if (!component
->debugfs_root
) {
291 dev_warn(component
->dev
,
292 "ASoC: Failed to create component debugfs directory\n");
296 snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component
),
297 component
->debugfs_root
);
299 if (component
->init_debugfs
)
300 component
->init_debugfs(component
);
303 static void soc_cleanup_component_debugfs(struct snd_soc_component
*component
)
305 debugfs_remove_recursive(component
->debugfs_root
);
308 static void soc_init_codec_debugfs(struct snd_soc_component
*component
)
310 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
312 debugfs_create_bool("cache_sync", 0444, codec
->component
.debugfs_root
,
315 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
316 codec
->component
.debugfs_root
,
317 codec
, &codec_reg_fops
);
318 if (!codec
->debugfs_reg
)
320 "ASoC: Failed to create codec register debugfs file\n");
323 static ssize_t
codec_list_read_file(struct file
*file
, char __user
*user_buf
,
324 size_t count
, loff_t
*ppos
)
326 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
327 ssize_t len
, ret
= 0;
328 struct snd_soc_codec
*codec
;
333 list_for_each_entry(codec
, &codec_list
, list
) {
334 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
335 codec
->component
.name
);
338 if (ret
> PAGE_SIZE
) {
345 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
352 static const struct file_operations codec_list_fops
= {
353 .read
= codec_list_read_file
,
354 .llseek
= default_llseek
,/* read accesses f_pos */
357 static ssize_t
dai_list_read_file(struct file
*file
, char __user
*user_buf
,
358 size_t count
, loff_t
*ppos
)
360 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
361 ssize_t len
, ret
= 0;
362 struct snd_soc_component
*component
;
363 struct snd_soc_dai
*dai
;
368 list_for_each_entry(component
, &component_list
, list
) {
369 list_for_each_entry(dai
, &component
->dai_list
, list
) {
370 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
374 if (ret
> PAGE_SIZE
) {
381 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
388 static const struct file_operations dai_list_fops
= {
389 .read
= dai_list_read_file
,
390 .llseek
= default_llseek
,/* read accesses f_pos */
393 static ssize_t
platform_list_read_file(struct file
*file
,
394 char __user
*user_buf
,
395 size_t count
, loff_t
*ppos
)
397 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
398 ssize_t len
, ret
= 0;
399 struct snd_soc_platform
*platform
;
404 list_for_each_entry(platform
, &platform_list
, list
) {
405 len
= snprintf(buf
+ ret
, PAGE_SIZE
- ret
, "%s\n",
406 platform
->component
.name
);
409 if (ret
> PAGE_SIZE
) {
415 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
422 static const struct file_operations platform_list_fops
= {
423 .read
= platform_list_read_file
,
424 .llseek
= default_llseek
,/* read accesses f_pos */
427 static void soc_init_card_debugfs(struct snd_soc_card
*card
)
429 card
->debugfs_card_root
= debugfs_create_dir(card
->name
,
430 snd_soc_debugfs_root
);
431 if (!card
->debugfs_card_root
) {
433 "ASoC: Failed to create card debugfs directory\n");
437 card
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0644,
438 card
->debugfs_card_root
,
440 if (!card
->debugfs_pop_time
)
442 "ASoC: Failed to create pop time debugfs file\n");
445 static void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
447 debugfs_remove_recursive(card
->debugfs_card_root
);
452 #define soc_init_codec_debugfs NULL
454 static inline void soc_init_component_debugfs(
455 struct snd_soc_component
*component
)
459 static inline void soc_cleanup_component_debugfs(
460 struct snd_soc_component
*component
)
464 static inline void soc_init_card_debugfs(struct snd_soc_card
*card
)
468 static inline void soc_cleanup_card_debugfs(struct snd_soc_card
*card
)
473 struct snd_pcm_substream
*snd_soc_get_dai_substream(struct snd_soc_card
*card
,
474 const char *dai_link
, int stream
)
478 for (i
= 0; i
< card
->num_links
; i
++) {
479 if (card
->rtd
[i
].dai_link
->no_pcm
&&
480 !strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
481 return card
->rtd
[i
].pcm
->streams
[stream
].substream
;
483 dev_dbg(card
->dev
, "ASoC: failed to find dai link %s\n", dai_link
);
486 EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream
);
488 struct snd_soc_pcm_runtime
*snd_soc_get_pcm_runtime(struct snd_soc_card
*card
,
489 const char *dai_link
)
493 for (i
= 0; i
< card
->num_links
; i
++) {
494 if (!strcmp(card
->rtd
[i
].dai_link
->name
, dai_link
))
495 return &card
->rtd
[i
];
497 dev_dbg(card
->dev
, "ASoC: failed to find rtd %s\n", dai_link
);
500 EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime
);
502 #ifdef CONFIG_SND_SOC_AC97_BUS
503 /* unregister ac97 codec */
504 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
506 if (codec
->ac97
->dev
.bus
)
507 device_unregister(&codec
->ac97
->dev
);
511 /* stop no dev release warning */
512 static void soc_ac97_device_release(struct device
*dev
){}
514 /* register ac97 codec to bus */
515 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
519 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
520 codec
->ac97
->dev
.parent
= codec
->component
.card
->dev
;
521 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
523 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
524 codec
->component
.card
->snd_card
->number
, 0,
525 codec
->component
.name
);
526 err
= device_register(&codec
->ac97
->dev
);
528 dev_err(codec
->dev
, "ASoC: Can't register ac97 bus\n");
529 codec
->ac97
->dev
.bus
= NULL
;
536 static void codec2codec_close_delayed_work(struct work_struct
*work
)
538 /* Currently nothing to do for c2c links
539 * Since c2c links are internal nodes in the DAPM graph and
540 * don't interface with the outside world or application layer
541 * we don't have to do any special handling on close.
545 #ifdef CONFIG_PM_SLEEP
546 /* powers down audio subsystem for suspend */
547 int snd_soc_suspend(struct device
*dev
)
549 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
550 struct snd_soc_codec
*codec
;
553 /* If the card is not initialized yet there is nothing to do */
554 if (!card
->instantiated
)
557 /* Due to the resume being scheduled into a workqueue we could
558 * suspend before that's finished - wait for it to complete.
560 snd_power_lock(card
->snd_card
);
561 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
562 snd_power_unlock(card
->snd_card
);
564 /* we're going to block userspace touching us until resume completes */
565 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
567 /* mute any active DACs */
568 for (i
= 0; i
< card
->num_rtd
; i
++) {
570 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
573 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
574 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dais
[j
];
575 struct snd_soc_dai_driver
*drv
= dai
->driver
;
577 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
578 drv
->ops
->digital_mute(dai
, 1);
582 /* suspend all pcms */
583 for (i
= 0; i
< card
->num_rtd
; i
++) {
584 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
587 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
590 if (card
->suspend_pre
)
591 card
->suspend_pre(card
);
593 for (i
= 0; i
< card
->num_rtd
; i
++) {
594 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
595 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
597 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
600 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
601 cpu_dai
->driver
->suspend(cpu_dai
);
602 if (platform
->driver
->suspend
&& !platform
->suspended
) {
603 platform
->driver
->suspend(cpu_dai
);
604 platform
->suspended
= 1;
608 /* close any waiting streams and save state */
609 for (i
= 0; i
< card
->num_rtd
; i
++) {
610 struct snd_soc_dai
**codec_dais
= card
->rtd
[i
].codec_dais
;
611 flush_delayed_work(&card
->rtd
[i
].delayed_work
);
612 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
613 codec_dais
[j
]->codec
->dapm
.suspend_bias_level
=
614 codec_dais
[j
]->codec
->dapm
.bias_level
;
618 for (i
= 0; i
< card
->num_rtd
; i
++) {
620 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
623 snd_soc_dapm_stream_event(&card
->rtd
[i
],
624 SNDRV_PCM_STREAM_PLAYBACK
,
625 SND_SOC_DAPM_STREAM_SUSPEND
);
627 snd_soc_dapm_stream_event(&card
->rtd
[i
],
628 SNDRV_PCM_STREAM_CAPTURE
,
629 SND_SOC_DAPM_STREAM_SUSPEND
);
632 /* Recheck all analogue paths too */
633 dapm_mark_io_dirty(&card
->dapm
);
634 snd_soc_dapm_sync(&card
->dapm
);
636 /* suspend all CODECs */
637 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
638 /* If there are paths active then the CODEC will be held with
639 * bias _ON and should not be suspended. */
640 if (!codec
->suspended
) {
641 switch (codec
->dapm
.bias_level
) {
642 case SND_SOC_BIAS_STANDBY
:
644 * If the CODEC is capable of idle
645 * bias off then being in STANDBY
646 * means it's doing something,
647 * otherwise fall through.
649 if (codec
->dapm
.idle_bias_off
) {
651 "ASoC: idle_bias_off CODEC on over suspend\n");
655 case SND_SOC_BIAS_OFF
:
656 if (codec
->driver
->suspend
)
657 codec
->driver
->suspend(codec
);
658 codec
->suspended
= 1;
659 codec
->cache_sync
= 1;
660 if (codec
->component
.regmap
)
661 regcache_mark_dirty(codec
->component
.regmap
);
662 /* deactivate pins to sleep state */
663 pinctrl_pm_select_sleep_state(codec
->dev
);
667 "ASoC: CODEC is on over suspend\n");
673 for (i
= 0; i
< card
->num_rtd
; i
++) {
674 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
676 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
679 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
680 cpu_dai
->driver
->suspend(cpu_dai
);
682 /* deactivate pins to sleep state */
683 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
686 if (card
->suspend_post
)
687 card
->suspend_post(card
);
691 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
693 /* deferred resume work, so resume can complete before we finished
694 * setting our codec back up, which can be very slow on I2C
696 static void soc_resume_deferred(struct work_struct
*work
)
698 struct snd_soc_card
*card
=
699 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
700 struct snd_soc_codec
*codec
;
703 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
704 * so userspace apps are blocked from touching us
707 dev_dbg(card
->dev
, "ASoC: starting resume work\n");
709 /* Bring us up into D2 so that DAPM starts enabling things */
710 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
712 if (card
->resume_pre
)
713 card
->resume_pre(card
);
715 /* resume AC97 DAIs */
716 for (i
= 0; i
< card
->num_rtd
; i
++) {
717 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
719 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
722 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
723 cpu_dai
->driver
->resume(cpu_dai
);
726 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
727 /* If the CODEC was idle over suspend then it will have been
728 * left with bias OFF or STANDBY and suspended so we must now
729 * resume. Otherwise the suspend was suppressed.
731 if (codec
->suspended
) {
732 switch (codec
->dapm
.bias_level
) {
733 case SND_SOC_BIAS_STANDBY
:
734 case SND_SOC_BIAS_OFF
:
735 if (codec
->driver
->resume
)
736 codec
->driver
->resume(codec
);
737 codec
->suspended
= 0;
741 "ASoC: CODEC was on over suspend\n");
747 for (i
= 0; i
< card
->num_rtd
; i
++) {
749 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
752 snd_soc_dapm_stream_event(&card
->rtd
[i
],
753 SNDRV_PCM_STREAM_PLAYBACK
,
754 SND_SOC_DAPM_STREAM_RESUME
);
756 snd_soc_dapm_stream_event(&card
->rtd
[i
],
757 SNDRV_PCM_STREAM_CAPTURE
,
758 SND_SOC_DAPM_STREAM_RESUME
);
761 /* unmute any active DACs */
762 for (i
= 0; i
< card
->num_rtd
; i
++) {
764 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
767 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
768 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dais
[j
];
769 struct snd_soc_dai_driver
*drv
= dai
->driver
;
771 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
772 drv
->ops
->digital_mute(dai
, 0);
776 for (i
= 0; i
< card
->num_rtd
; i
++) {
777 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
778 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
780 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
783 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
784 cpu_dai
->driver
->resume(cpu_dai
);
785 if (platform
->driver
->resume
&& platform
->suspended
) {
786 platform
->driver
->resume(cpu_dai
);
787 platform
->suspended
= 0;
791 if (card
->resume_post
)
792 card
->resume_post(card
);
794 dev_dbg(card
->dev
, "ASoC: resume work completed\n");
796 /* userspace can access us now we are back as we were before */
797 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
799 /* Recheck all analogue paths too */
800 dapm_mark_io_dirty(&card
->dapm
);
801 snd_soc_dapm_sync(&card
->dapm
);
804 /* powers up audio subsystem after a suspend */
805 int snd_soc_resume(struct device
*dev
)
807 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
808 int i
, ac97_control
= 0;
810 /* If the card is not initialized yet there is nothing to do */
811 if (!card
->instantiated
)
814 /* activate pins from sleep state */
815 for (i
= 0; i
< card
->num_rtd
; i
++) {
816 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
817 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
818 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
822 pinctrl_pm_select_default_state(cpu_dai
->dev
);
824 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
825 struct snd_soc_dai
*codec_dai
= codec_dais
[j
];
826 if (codec_dai
->active
)
827 pinctrl_pm_select_default_state(codec_dai
->dev
);
831 /* AC97 devices might have other drivers hanging off them so
832 * need to resume immediately. Other drivers don't have that
833 * problem and may take a substantial amount of time to resume
834 * due to I/O costs and anti-pop so handle them out of line.
836 for (i
= 0; i
< card
->num_rtd
; i
++) {
837 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
838 ac97_control
|= cpu_dai
->driver
->ac97_control
;
841 dev_dbg(dev
, "ASoC: Resuming AC97 immediately\n");
842 soc_resume_deferred(&card
->deferred_resume_work
);
844 dev_dbg(dev
, "ASoC: Scheduling resume work\n");
845 if (!schedule_work(&card
->deferred_resume_work
))
846 dev_err(dev
, "ASoC: resume work item may be lost\n");
851 EXPORT_SYMBOL_GPL(snd_soc_resume
);
853 #define snd_soc_suspend NULL
854 #define snd_soc_resume NULL
857 static const struct snd_soc_dai_ops null_dai_ops
= {
860 static struct snd_soc_component
*soc_find_component(
861 const struct device_node
*of_node
, const char *name
)
863 struct snd_soc_component
*component
;
865 list_for_each_entry(component
, &component_list
, list
) {
867 if (component
->dev
->of_node
== of_node
)
869 } else if (strcmp(component
->name
, name
) == 0) {
877 static struct snd_soc_dai
*snd_soc_find_dai(
878 const struct snd_soc_dai_link_component
*dlc
)
880 struct snd_soc_component
*component
;
881 struct snd_soc_dai
*dai
;
883 /* Find CPU DAI from registered DAIs*/
884 list_for_each_entry(component
, &component_list
, list
) {
885 if (dlc
->of_node
&& component
->dev
->of_node
!= dlc
->of_node
)
887 if (dlc
->name
&& strcmp(dev_name(component
->dev
), dlc
->name
))
889 list_for_each_entry(dai
, &component
->dai_list
, list
) {
890 if (dlc
->dai_name
&& strcmp(dai
->name
, dlc
->dai_name
))
900 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
902 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
903 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
904 struct snd_soc_dai_link_component
*codecs
= dai_link
->codecs
;
905 struct snd_soc_dai_link_component cpu_dai_component
;
906 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
907 struct snd_soc_platform
*platform
;
908 const char *platform_name
;
911 dev_dbg(card
->dev
, "ASoC: binding %s at idx %d\n", dai_link
->name
, num
);
913 cpu_dai_component
.name
= dai_link
->cpu_name
;
914 cpu_dai_component
.of_node
= dai_link
->cpu_of_node
;
915 cpu_dai_component
.dai_name
= dai_link
->cpu_dai_name
;
916 rtd
->cpu_dai
= snd_soc_find_dai(&cpu_dai_component
);
918 dev_err(card
->dev
, "ASoC: CPU DAI %s not registered\n",
919 dai_link
->cpu_dai_name
);
920 return -EPROBE_DEFER
;
923 rtd
->num_codecs
= dai_link
->num_codecs
;
925 /* Find CODEC from registered CODECs */
926 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
927 codec_dais
[i
] = snd_soc_find_dai(&codecs
[i
]);
928 if (!codec_dais
[i
]) {
929 dev_err(card
->dev
, "ASoC: CODEC DAI %s not registered\n",
931 return -EPROBE_DEFER
;
935 /* Single codec links expect codec and codec_dai in runtime data */
936 rtd
->codec_dai
= codec_dais
[0];
937 rtd
->codec
= rtd
->codec_dai
->codec
;
939 /* if there's no platform we match on the empty platform */
940 platform_name
= dai_link
->platform_name
;
941 if (!platform_name
&& !dai_link
->platform_of_node
)
942 platform_name
= "snd-soc-dummy";
944 /* find one from the set of registered platforms */
945 list_for_each_entry(platform
, &platform_list
, list
) {
946 if (dai_link
->platform_of_node
) {
947 if (platform
->dev
->of_node
!=
948 dai_link
->platform_of_node
)
951 if (strcmp(platform
->component
.name
, platform_name
))
955 rtd
->platform
= platform
;
957 if (!rtd
->platform
) {
958 dev_err(card
->dev
, "ASoC: platform %s not registered\n",
959 dai_link
->platform_name
);
960 return -EPROBE_DEFER
;
968 static void soc_remove_component(struct snd_soc_component
*component
)
970 if (!component
->probed
)
973 /* This is a HACK and will be removed soon */
974 if (component
->codec
)
975 list_del(&component
->codec
->card_list
);
977 if (component
->remove
)
978 component
->remove(component
);
980 snd_soc_dapm_free(snd_soc_component_get_dapm(component
));
982 soc_cleanup_component_debugfs(component
);
983 component
->probed
= 0;
984 module_put(component
->dev
->driver
->owner
);
987 static void soc_remove_dai(struct snd_soc_dai
*dai
, int order
)
991 if (dai
&& dai
->probed
&&
992 dai
->driver
->remove_order
== order
) {
993 if (dai
->driver
->remove
) {
994 err
= dai
->driver
->remove(dai
);
997 "ASoC: failed to remove %s: %d\n",
1004 static void soc_remove_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1006 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1009 /* unregister the rtd device */
1010 if (rtd
->dev_registered
) {
1011 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
1012 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1013 device_unregister(rtd
->dev
);
1014 rtd
->dev_registered
= 0;
1017 /* remove the CODEC DAI */
1018 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1019 soc_remove_dai(rtd
->codec_dais
[i
], order
);
1021 soc_remove_dai(rtd
->cpu_dai
, order
);
1024 static void soc_remove_link_components(struct snd_soc_card
*card
, int num
,
1027 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1028 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1029 struct snd_soc_platform
*platform
= rtd
->platform
;
1030 struct snd_soc_component
*component
;
1033 /* remove the platform */
1034 if (platform
&& platform
->component
.driver
->remove_order
== order
)
1035 soc_remove_component(&platform
->component
);
1037 /* remove the CODEC-side CODEC */
1038 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1039 component
= rtd
->codec_dais
[i
]->component
;
1040 if (component
->driver
->remove_order
== order
)
1041 soc_remove_component(component
);
1044 /* remove any CPU-side CODEC */
1046 if (cpu_dai
->component
->driver
->remove_order
== order
)
1047 soc_remove_component(cpu_dai
->component
);
1051 static void soc_remove_dai_links(struct snd_soc_card
*card
)
1055 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1057 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1058 soc_remove_link_dais(card
, dai
, order
);
1061 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1063 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1064 soc_remove_link_components(card
, dai
, order
);
1070 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1071 struct snd_soc_component
*component
)
1075 if (card
->codec_conf
== NULL
)
1078 for (i
= 0; i
< card
->num_configs
; i
++) {
1079 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1080 if (map
->of_node
&& component
->dev
->of_node
!= map
->of_node
)
1082 if (map
->dev_name
&& strcmp(component
->name
, map
->dev_name
))
1084 component
->name_prefix
= map
->name_prefix
;
1089 static int soc_probe_component(struct snd_soc_card
*card
,
1090 struct snd_soc_component
*component
)
1092 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(component
);
1093 struct snd_soc_dai
*dai
;
1096 if (component
->probed
)
1099 component
->card
= card
;
1101 soc_set_name_prefix(card
, component
);
1103 if (!try_module_get(component
->dev
->driver
->owner
))
1106 soc_init_component_debugfs(component
);
1108 if (component
->dapm_widgets
) {
1109 ret
= snd_soc_dapm_new_controls(dapm
, component
->dapm_widgets
,
1110 component
->num_dapm_widgets
);
1113 dev_err(component
->dev
,
1114 "Failed to create new controls %d\n", ret
);
1119 list_for_each_entry(dai
, &component
->dai_list
, list
) {
1120 ret
= snd_soc_dapm_new_dai_widgets(dapm
, dai
);
1122 dev_err(component
->dev
,
1123 "Failed to create DAI widgets %d\n", ret
);
1128 if (component
->probe
) {
1129 ret
= component
->probe(component
);
1131 dev_err(component
->dev
,
1132 "ASoC: failed to probe component %d\n", ret
);
1136 WARN(dapm
->idle_bias_off
&&
1137 dapm
->bias_level
!= SND_SOC_BIAS_OFF
,
1138 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1142 if (component
->controls
)
1143 snd_soc_add_component_controls(component
, component
->controls
,
1144 component
->num_controls
);
1145 if (component
->dapm_routes
)
1146 snd_soc_dapm_add_routes(dapm
, component
->dapm_routes
,
1147 component
->num_dapm_routes
);
1149 component
->probed
= 1;
1150 list_add(&dapm
->list
, &card
->dapm_list
);
1152 /* This is a HACK and will be removed soon */
1153 if (component
->codec
)
1154 list_add(&component
->codec
->card_list
, &card
->codec_dev_list
);
1159 soc_cleanup_component_debugfs(component
);
1160 module_put(component
->dev
->driver
->owner
);
1165 static void rtd_release(struct device
*dev
)
1170 static int soc_post_component_init(struct snd_soc_pcm_runtime
*rtd
,
1175 /* register the rtd device */
1176 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1179 device_initialize(rtd
->dev
);
1180 rtd
->dev
->parent
= rtd
->card
->dev
;
1181 rtd
->dev
->release
= rtd_release
;
1182 dev_set_name(rtd
->dev
, "%s", name
);
1183 dev_set_drvdata(rtd
->dev
, rtd
);
1184 mutex_init(&rtd
->pcm_mutex
);
1185 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1186 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1187 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1188 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1189 ret
= device_add(rtd
->dev
);
1191 /* calling put_device() here to free the rtd->dev */
1192 put_device(rtd
->dev
);
1193 dev_err(rtd
->card
->dev
,
1194 "ASoC: failed to register runtime device: %d\n", ret
);
1197 rtd
->dev_registered
= 1;
1200 /* add DAPM sysfs entries for this codec */
1201 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1204 "ASoC: failed to add codec dapm sysfs entries: %d\n",
1207 /* add codec sysfs entries */
1208 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1211 "ASoC: failed to add codec sysfs files: %d\n",
1218 static int soc_probe_link_components(struct snd_soc_card
*card
, int num
,
1221 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1222 struct snd_soc_platform
*platform
= rtd
->platform
;
1223 struct snd_soc_component
*component
;
1226 /* probe the CPU-side component, if it is a CODEC */
1227 component
= rtd
->cpu_dai
->component
;
1228 if (component
->driver
->probe_order
== order
) {
1229 ret
= soc_probe_component(card
, component
);
1234 /* probe the CODEC-side components */
1235 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1236 component
= rtd
->codec_dais
[i
]->component
;
1237 if (component
->driver
->probe_order
== order
) {
1238 ret
= soc_probe_component(card
, component
);
1244 /* probe the platform */
1245 if (platform
->component
.driver
->probe_order
== order
) {
1246 ret
= soc_probe_component(card
, &platform
->component
);
1254 static int soc_probe_codec_dai(struct snd_soc_card
*card
,
1255 struct snd_soc_dai
*codec_dai
,
1260 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1261 if (codec_dai
->driver
->probe
) {
1262 ret
= codec_dai
->driver
->probe(codec_dai
);
1264 dev_err(codec_dai
->dev
,
1265 "ASoC: failed to probe CODEC DAI %s: %d\n",
1266 codec_dai
->name
, ret
);
1271 /* mark codec_dai as probed and add to card dai list */
1272 codec_dai
->probed
= 1;
1278 static int soc_link_dai_widgets(struct snd_soc_card
*card
,
1279 struct snd_soc_dai_link
*dai_link
,
1280 struct snd_soc_pcm_runtime
*rtd
)
1282 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1283 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1284 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1287 if (rtd
->num_codecs
> 1)
1288 dev_warn(card
->dev
, "ASoC: Multiple codecs not supported yet\n");
1290 /* link the DAI widgets */
1291 play_w
= codec_dai
->playback_widget
;
1292 capture_w
= cpu_dai
->capture_widget
;
1293 if (play_w
&& capture_w
) {
1294 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1297 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1298 play_w
->name
, capture_w
->name
, ret
);
1303 play_w
= cpu_dai
->playback_widget
;
1304 capture_w
= codec_dai
->capture_widget
;
1305 if (play_w
&& capture_w
) {
1306 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1309 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1310 play_w
->name
, capture_w
->name
, ret
);
1318 static int soc_probe_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1320 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1321 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1322 struct snd_soc_platform
*platform
= rtd
->platform
;
1323 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1326 dev_dbg(card
->dev
, "ASoC: probe %s dai link %d late %d\n",
1327 card
->name
, num
, order
);
1329 /* config components */
1330 cpu_dai
->platform
= platform
;
1331 cpu_dai
->card
= card
;
1332 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1333 rtd
->codec_dais
[i
]->card
= card
;
1335 /* set default power off timeout */
1336 rtd
->pmdown_time
= pmdown_time
;
1338 /* probe the cpu_dai */
1339 if (!cpu_dai
->probed
&&
1340 cpu_dai
->driver
->probe_order
== order
) {
1341 if (cpu_dai
->driver
->probe
) {
1342 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1344 dev_err(cpu_dai
->dev
,
1345 "ASoC: failed to probe CPU DAI %s: %d\n",
1346 cpu_dai
->name
, ret
);
1350 cpu_dai
->probed
= 1;
1353 /* probe the CODEC DAI */
1354 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1355 ret
= soc_probe_codec_dai(card
, rtd
->codec_dais
[i
], order
);
1360 /* complete DAI probe during last probe */
1361 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1364 /* do machine specific initialization */
1365 if (dai_link
->init
) {
1366 ret
= dai_link
->init(rtd
);
1368 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n",
1369 dai_link
->name
, ret
);
1374 ret
= soc_post_component_init(rtd
, dai_link
->name
);
1378 #ifdef CONFIG_DEBUG_FS
1379 /* add DPCM sysfs entries */
1380 if (dai_link
->dynamic
) {
1381 ret
= soc_dpcm_debugfs_add(rtd
);
1384 "ASoC: failed to add dpcm sysfs entries: %d\n",
1391 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1393 dev_warn(rtd
->dev
, "ASoC: failed to add pmdown_time sysfs: %d\n",
1396 if (cpu_dai
->driver
->compress_dai
) {
1397 /*create compress_device"*/
1398 ret
= soc_new_compress(rtd
, num
);
1400 dev_err(card
->dev
, "ASoC: can't create compress %s\n",
1401 dai_link
->stream_name
);
1406 if (!dai_link
->params
) {
1407 /* create the pcm */
1408 ret
= soc_new_pcm(rtd
, num
);
1410 dev_err(card
->dev
, "ASoC: can't create pcm %s :%d\n",
1411 dai_link
->stream_name
, ret
);
1415 INIT_DELAYED_WORK(&rtd
->delayed_work
,
1416 codec2codec_close_delayed_work
);
1418 /* link the DAI widgets */
1419 ret
= soc_link_dai_widgets(card
, dai_link
, rtd
);
1425 /* add platform data for AC97 devices */
1426 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1427 if (rtd
->codec_dais
[i
]->driver
->ac97_control
)
1428 snd_ac97_dev_add_pdata(rtd
->codec_dais
[i
]->codec
->ac97
,
1429 rtd
->cpu_dai
->ac97_pdata
);
1435 #ifdef CONFIG_SND_SOC_AC97_BUS
1436 static int soc_register_ac97_codec(struct snd_soc_codec
*codec
,
1437 struct snd_soc_dai
*codec_dai
)
1441 /* Only instantiate AC97 if not already done by the adaptor
1442 * for the generic AC97 subsystem.
1444 if (codec_dai
->driver
->ac97_control
&& !codec
->ac97_registered
) {
1446 * It is possible that the AC97 device is already registered to
1447 * the device subsystem. This happens when the device is created
1448 * via snd_ac97_mixer(). Currently only SoC codec that does so
1449 * is the generic AC97 glue but others migh emerge.
1451 * In those cases we don't try to register the device again.
1453 if (!codec
->ac97_created
)
1456 ret
= soc_ac97_dev_register(codec
);
1459 "ASoC: AC97 device register failed: %d\n", ret
);
1463 codec
->ac97_registered
= 1;
1468 static void soc_unregister_ac97_codec(struct snd_soc_codec
*codec
)
1470 if (codec
->ac97_registered
) {
1471 soc_ac97_dev_unregister(codec
);
1472 codec
->ac97_registered
= 0;
1476 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1480 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1481 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[i
];
1483 ret
= soc_register_ac97_codec(codec_dai
->codec
, codec_dai
);
1486 soc_unregister_ac97_codec(codec_dai
->codec
);
1494 static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1498 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1499 soc_unregister_ac97_codec(rtd
->codec_dais
[i
]->codec
);
1503 static int soc_bind_aux_dev(struct snd_soc_card
*card
, int num
)
1505 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1506 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1507 const char *name
= aux_dev
->codec_name
;
1509 rtd
->component
= soc_find_component(aux_dev
->codec_of_node
, name
);
1510 if (!rtd
->component
) {
1511 if (aux_dev
->codec_of_node
)
1512 name
= of_node_full_name(aux_dev
->codec_of_node
);
1514 dev_err(card
->dev
, "ASoC: %s not registered\n", name
);
1515 return -EPROBE_DEFER
;
1519 * Some places still reference rtd->codec, so we have to keep that
1520 * initialized if the component is a CODEC. Once all those references
1521 * have been removed, this code can be removed as well.
1523 rtd
->codec
= rtd
->component
->codec
;
1528 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1530 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1531 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1534 ret
= soc_probe_component(card
, rtd
->component
);
1538 /* do machine specific initialization */
1539 if (aux_dev
->init
) {
1540 ret
= aux_dev
->init(rtd
->component
);
1542 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n",
1543 aux_dev
->name
, ret
);
1548 return soc_post_component_init(rtd
, aux_dev
->name
);
1551 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1553 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1554 struct snd_soc_component
*component
= rtd
->component
;
1556 /* unregister the rtd device */
1557 if (rtd
->dev_registered
) {
1558 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1559 device_unregister(rtd
->dev
);
1560 rtd
->dev_registered
= 0;
1563 if (component
&& component
->probed
)
1564 soc_remove_component(component
);
1567 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
)
1571 if (codec
->cache_init
)
1574 ret
= snd_soc_cache_init(codec
);
1577 "ASoC: Failed to set cache compression type: %d\n",
1581 codec
->cache_init
= 1;
1585 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1587 struct snd_soc_codec
*codec
;
1588 struct snd_soc_dai_link
*dai_link
;
1589 int ret
, i
, order
, dai_fmt
;
1591 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1594 for (i
= 0; i
< card
->num_links
; i
++) {
1595 ret
= soc_bind_dai_link(card
, i
);
1600 /* bind aux_devs too */
1601 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1602 ret
= soc_bind_aux_dev(card
, i
);
1607 /* initialize the register cache for each available codec */
1608 list_for_each_entry(codec
, &codec_list
, list
) {
1609 if (codec
->cache_init
)
1611 ret
= snd_soc_init_codec_cache(codec
);
1616 /* card bind complete so register a sound card */
1617 ret
= snd_card_new(card
->dev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1618 card
->owner
, 0, &card
->snd_card
);
1621 "ASoC: can't create sound card for card %s: %d\n",
1626 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1627 card
->dapm
.dev
= card
->dev
;
1628 card
->dapm
.card
= card
;
1629 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1631 #ifdef CONFIG_DEBUG_FS
1632 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1635 #ifdef CONFIG_PM_SLEEP
1636 /* deferred resume work */
1637 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1640 if (card
->dapm_widgets
)
1641 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1642 card
->num_dapm_widgets
);
1644 /* initialise the sound card only once */
1646 ret
= card
->probe(card
);
1648 goto card_probe_error
;
1651 /* probe all components used by DAI links on this card */
1652 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1654 for (i
= 0; i
< card
->num_links
; i
++) {
1655 ret
= soc_probe_link_components(card
, i
, order
);
1658 "ASoC: failed to instantiate card %d\n",
1665 /* probe all DAI links on this card */
1666 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1668 for (i
= 0; i
< card
->num_links
; i
++) {
1669 ret
= soc_probe_link_dais(card
, i
, order
);
1672 "ASoC: failed to instantiate card %d\n",
1679 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1680 ret
= soc_probe_aux_dev(card
, i
);
1683 "ASoC: failed to add auxiliary devices %d\n",
1685 goto probe_aux_dev_err
;
1689 snd_soc_dapm_link_dai_widgets(card
);
1690 snd_soc_dapm_connect_dai_link_widgets(card
);
1693 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1695 if (card
->dapm_routes
)
1696 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1697 card
->num_dapm_routes
);
1699 for (i
= 0; i
< card
->num_links
; i
++) {
1700 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1701 dai_link
= &card
->dai_link
[i
];
1702 dai_fmt
= dai_link
->dai_fmt
;
1705 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
1708 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
1709 struct snd_soc_dai
*codec_dai
= codec_dais
[j
];
1711 ret
= snd_soc_dai_set_fmt(codec_dai
, dai_fmt
);
1712 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1713 dev_warn(codec_dai
->dev
,
1714 "ASoC: Failed to set DAI format: %d\n",
1719 /* If this is a regular CPU link there will be a platform */
1721 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1722 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1724 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1725 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1726 "ASoC: Failed to set DAI format: %d\n",
1728 } else if (dai_fmt
) {
1729 /* Flip the polarity for the "CPU" end */
1730 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1731 switch (dai_link
->dai_fmt
&
1732 SND_SOC_DAIFMT_MASTER_MASK
) {
1733 case SND_SOC_DAIFMT_CBM_CFM
:
1734 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1736 case SND_SOC_DAIFMT_CBM_CFS
:
1737 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1739 case SND_SOC_DAIFMT_CBS_CFM
:
1740 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1742 case SND_SOC_DAIFMT_CBS_CFS
:
1743 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1747 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1749 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1750 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1751 "ASoC: Failed to set DAI format: %d\n",
1756 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1758 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1759 "%s", card
->long_name
? card
->long_name
: card
->name
);
1760 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1761 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1762 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1763 switch (card
->snd_card
->driver
[i
]) {
1769 if (!isalnum(card
->snd_card
->driver
[i
]))
1770 card
->snd_card
->driver
[i
] = '_';
1775 if (card
->late_probe
) {
1776 ret
= card
->late_probe(card
);
1778 dev_err(card
->dev
, "ASoC: %s late_probe() failed: %d\n",
1780 goto probe_aux_dev_err
;
1784 if (card
->fully_routed
)
1785 snd_soc_dapm_auto_nc_pins(card
);
1787 snd_soc_dapm_new_widgets(card
);
1789 ret
= snd_card_register(card
->snd_card
);
1791 dev_err(card
->dev
, "ASoC: failed to register soundcard %d\n",
1793 goto probe_aux_dev_err
;
1796 #ifdef CONFIG_SND_SOC_AC97_BUS
1797 /* register any AC97 codecs */
1798 for (i
= 0; i
< card
->num_rtd
; i
++) {
1799 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1802 "ASoC: failed to register AC97: %d\n", ret
);
1804 soc_unregister_ac97_dai_link(&card
->rtd
[i
]);
1805 goto probe_aux_dev_err
;
1810 card
->instantiated
= 1;
1811 snd_soc_dapm_sync(&card
->dapm
);
1812 mutex_unlock(&card
->mutex
);
1817 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1818 soc_remove_aux_dev(card
, i
);
1821 soc_remove_dai_links(card
);
1827 snd_card_free(card
->snd_card
);
1830 mutex_unlock(&card
->mutex
);
1835 /* probes a new socdev */
1836 static int soc_probe(struct platform_device
*pdev
)
1838 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1841 * no card, so machine driver should be registering card
1842 * we should not be here in that case so ret error
1847 dev_warn(&pdev
->dev
,
1848 "ASoC: machine %s should use snd_soc_register_card()\n",
1851 /* Bodge while we unpick instantiation */
1852 card
->dev
= &pdev
->dev
;
1854 return snd_soc_register_card(card
);
1857 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1861 /* make sure any delayed work runs */
1862 for (i
= 0; i
< card
->num_rtd
; i
++) {
1863 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1864 flush_delayed_work(&rtd
->delayed_work
);
1867 /* remove auxiliary devices */
1868 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1869 soc_remove_aux_dev(card
, i
);
1871 /* remove and free each DAI */
1872 soc_remove_dai_links(card
);
1874 soc_cleanup_card_debugfs(card
);
1876 /* remove the card */
1880 snd_soc_dapm_free(&card
->dapm
);
1882 snd_card_free(card
->snd_card
);
1887 /* removes a socdev */
1888 static int soc_remove(struct platform_device
*pdev
)
1890 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1892 snd_soc_unregister_card(card
);
1896 int snd_soc_poweroff(struct device
*dev
)
1898 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1901 if (!card
->instantiated
)
1904 /* Flush out pmdown_time work - we actually do want to run it
1905 * now, we're shutting down so no imminent restart. */
1906 for (i
= 0; i
< card
->num_rtd
; i
++) {
1907 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1908 flush_delayed_work(&rtd
->delayed_work
);
1911 snd_soc_dapm_shutdown(card
);
1913 /* deactivate pins to sleep state */
1914 for (i
= 0; i
< card
->num_rtd
; i
++) {
1915 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1916 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1919 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
1920 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
1921 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[j
];
1922 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
1928 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1930 const struct dev_pm_ops snd_soc_pm_ops
= {
1931 .suspend
= snd_soc_suspend
,
1932 .resume
= snd_soc_resume
,
1933 .freeze
= snd_soc_suspend
,
1934 .thaw
= snd_soc_resume
,
1935 .poweroff
= snd_soc_poweroff
,
1936 .restore
= snd_soc_resume
,
1938 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1940 /* ASoC platform driver */
1941 static struct platform_driver soc_driver
= {
1943 .name
= "soc-audio",
1944 .owner
= THIS_MODULE
,
1945 .pm
= &snd_soc_pm_ops
,
1948 .remove
= soc_remove
,
1952 * snd_soc_new_ac97_codec - initailise AC97 device
1953 * @codec: audio codec
1954 * @ops: AC97 bus operations
1955 * @num: AC97 codec number
1957 * Initialises AC97 codec resources for use by ad-hoc devices only.
1959 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1960 struct snd_ac97_bus_ops
*ops
, int num
)
1962 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1963 if (codec
->ac97
== NULL
)
1966 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1967 if (codec
->ac97
->bus
== NULL
) {
1973 codec
->ac97
->bus
->ops
= ops
;
1974 codec
->ac97
->num
= num
;
1977 * Mark the AC97 device to be created by us. This way we ensure that the
1978 * device will be registered with the device subsystem later on.
1980 codec
->ac97_created
= 1;
1984 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1986 static struct snd_ac97_reset_cfg snd_ac97_rst_cfg
;
1988 static void snd_soc_ac97_warm_reset(struct snd_ac97
*ac97
)
1990 struct pinctrl
*pctl
= snd_ac97_rst_cfg
.pctl
;
1992 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_warm_reset
);
1994 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 1);
1998 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 0);
2000 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_run
);
2004 static void snd_soc_ac97_reset(struct snd_ac97
*ac97
)
2006 struct pinctrl
*pctl
= snd_ac97_rst_cfg
.pctl
;
2008 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_reset
);
2010 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 0);
2011 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sdata
, 0);
2012 gpio_direction_output(snd_ac97_rst_cfg
.gpio_reset
, 0);
2016 gpio_direction_output(snd_ac97_rst_cfg
.gpio_reset
, 1);
2018 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_run
);
2022 static int snd_soc_ac97_parse_pinctl(struct device
*dev
,
2023 struct snd_ac97_reset_cfg
*cfg
)
2026 struct pinctrl_state
*state
;
2030 p
= devm_pinctrl_get(dev
);
2032 dev_err(dev
, "Failed to get pinctrl\n");
2037 state
= pinctrl_lookup_state(p
, "ac97-reset");
2038 if (IS_ERR(state
)) {
2039 dev_err(dev
, "Can't find pinctrl state ac97-reset\n");
2040 return PTR_ERR(state
);
2042 cfg
->pstate_reset
= state
;
2044 state
= pinctrl_lookup_state(p
, "ac97-warm-reset");
2045 if (IS_ERR(state
)) {
2046 dev_err(dev
, "Can't find pinctrl state ac97-warm-reset\n");
2047 return PTR_ERR(state
);
2049 cfg
->pstate_warm_reset
= state
;
2051 state
= pinctrl_lookup_state(p
, "ac97-running");
2052 if (IS_ERR(state
)) {
2053 dev_err(dev
, "Can't find pinctrl state ac97-running\n");
2054 return PTR_ERR(state
);
2056 cfg
->pstate_run
= state
;
2058 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 0);
2060 dev_err(dev
, "Can't find ac97-sync gpio\n");
2063 ret
= devm_gpio_request(dev
, gpio
, "AC97 link sync");
2065 dev_err(dev
, "Failed requesting ac97-sync gpio\n");
2068 cfg
->gpio_sync
= gpio
;
2070 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 1);
2072 dev_err(dev
, "Can't find ac97-sdata gpio %d\n", gpio
);
2075 ret
= devm_gpio_request(dev
, gpio
, "AC97 link sdata");
2077 dev_err(dev
, "Failed requesting ac97-sdata gpio\n");
2080 cfg
->gpio_sdata
= gpio
;
2082 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 2);
2084 dev_err(dev
, "Can't find ac97-reset gpio\n");
2087 ret
= devm_gpio_request(dev
, gpio
, "AC97 link reset");
2089 dev_err(dev
, "Failed requesting ac97-reset gpio\n");
2092 cfg
->gpio_reset
= gpio
;
2097 struct snd_ac97_bus_ops
*soc_ac97_ops
;
2098 EXPORT_SYMBOL_GPL(soc_ac97_ops
);
2100 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops
*ops
)
2102 if (ops
== soc_ac97_ops
)
2105 if (soc_ac97_ops
&& ops
)
2112 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops
);
2115 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
2117 * This function sets the reset and warm_reset properties of ops and parses
2118 * the device node of pdev to get pinctrl states and gpio numbers to use.
2120 int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops
*ops
,
2121 struct platform_device
*pdev
)
2123 struct device
*dev
= &pdev
->dev
;
2124 struct snd_ac97_reset_cfg cfg
;
2127 ret
= snd_soc_ac97_parse_pinctl(dev
, &cfg
);
2131 ret
= snd_soc_set_ac97_ops(ops
);
2135 ops
->warm_reset
= snd_soc_ac97_warm_reset
;
2136 ops
->reset
= snd_soc_ac97_reset
;
2138 snd_ac97_rst_cfg
= cfg
;
2141 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset
);
2144 * snd_soc_free_ac97_codec - free AC97 codec device
2145 * @codec: audio codec
2147 * Frees AC97 codec device resources.
2149 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
2151 #ifdef CONFIG_SND_SOC_AC97_BUS
2152 soc_unregister_ac97_codec(codec
);
2154 kfree(codec
->ac97
->bus
);
2157 codec
->ac97_created
= 0;
2159 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
2162 * snd_soc_cnew - create new control
2163 * @_template: control template
2164 * @data: control private data
2165 * @long_name: control long name
2166 * @prefix: control name prefix
2168 * Create a new mixer control from a template control.
2170 * Returns 0 for success, else error.
2172 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2173 void *data
, const char *long_name
,
2176 struct snd_kcontrol_new
template;
2177 struct snd_kcontrol
*kcontrol
;
2180 memcpy(&template, _template
, sizeof(template));
2184 long_name
= template.name
;
2187 name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, long_name
);
2191 template.name
= name
;
2193 template.name
= long_name
;
2196 kcontrol
= snd_ctl_new1(&template, data
);
2202 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2204 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2205 const struct snd_kcontrol_new
*controls
, int num_controls
,
2206 const char *prefix
, void *data
)
2210 for (i
= 0; i
< num_controls
; i
++) {
2211 const struct snd_kcontrol_new
*control
= &controls
[i
];
2212 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2213 control
->name
, prefix
));
2215 dev_err(dev
, "ASoC: Failed to add %s: %d\n",
2216 control
->name
, err
);
2224 struct snd_kcontrol
*snd_soc_card_get_kcontrol(struct snd_soc_card
*soc_card
,
2227 struct snd_card
*card
= soc_card
->snd_card
;
2228 struct snd_kcontrol
*kctl
;
2230 if (unlikely(!name
))
2233 list_for_each_entry(kctl
, &card
->controls
, list
)
2234 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
)))
2238 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol
);
2241 * snd_soc_add_component_controls - Add an array of controls to a component.
2243 * @component: Component to add controls to
2244 * @controls: Array of controls to add
2245 * @num_controls: Number of elements in the array
2247 * Return: 0 for success, else error.
2249 int snd_soc_add_component_controls(struct snd_soc_component
*component
,
2250 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2252 struct snd_card
*card
= component
->card
->snd_card
;
2254 return snd_soc_add_controls(card
, component
->dev
, controls
,
2255 num_controls
, component
->name_prefix
, component
);
2257 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls
);
2260 * snd_soc_add_codec_controls - add an array of controls to a codec.
2261 * Convenience function to add a list of controls. Many codecs were
2262 * duplicating this code.
2264 * @codec: codec to add controls to
2265 * @controls: array of controls to add
2266 * @num_controls: number of elements in the array
2268 * Return 0 for success, else error.
2270 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2271 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2273 return snd_soc_add_component_controls(&codec
->component
, controls
,
2276 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2279 * snd_soc_add_platform_controls - add an array of controls to a platform.
2280 * Convenience function to add a list of controls.
2282 * @platform: platform to add controls to
2283 * @controls: array of controls to add
2284 * @num_controls: number of elements in the array
2286 * Return 0 for success, else error.
2288 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2289 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2291 return snd_soc_add_component_controls(&platform
->component
, controls
,
2294 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2297 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2298 * Convenience function to add a list of controls.
2300 * @soc_card: SoC card to add controls to
2301 * @controls: array of controls to add
2302 * @num_controls: number of elements in the array
2304 * Return 0 for success, else error.
2306 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2307 const struct snd_kcontrol_new
*controls
, int num_controls
)
2309 struct snd_card
*card
= soc_card
->snd_card
;
2311 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2314 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2317 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2318 * Convienience function to add a list of controls.
2320 * @dai: DAI to add controls to
2321 * @controls: array of controls to add
2322 * @num_controls: number of elements in the array
2324 * Return 0 for success, else error.
2326 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2327 const struct snd_kcontrol_new
*controls
, int num_controls
)
2329 struct snd_card
*card
= dai
->card
->snd_card
;
2331 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2334 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2337 * snd_soc_info_enum_double - enumerated double mixer info callback
2338 * @kcontrol: mixer control
2339 * @uinfo: control element information
2341 * Callback to provide information about a double enumerated
2344 * Returns 0 for success.
2346 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2347 struct snd_ctl_elem_info
*uinfo
)
2349 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2351 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2352 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2353 uinfo
->value
.enumerated
.items
= e
->items
;
2355 if (uinfo
->value
.enumerated
.item
>= e
->items
)
2356 uinfo
->value
.enumerated
.item
= e
->items
- 1;
2357 strlcpy(uinfo
->value
.enumerated
.name
,
2358 e
->texts
[uinfo
->value
.enumerated
.item
],
2359 sizeof(uinfo
->value
.enumerated
.name
));
2362 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2365 * snd_soc_get_enum_double - enumerated double mixer get callback
2366 * @kcontrol: mixer control
2367 * @ucontrol: control element information
2369 * Callback to get the value of a double enumerated mixer.
2371 * Returns 0 for success.
2373 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2374 struct snd_ctl_elem_value
*ucontrol
)
2376 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2377 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2378 unsigned int val
, item
;
2379 unsigned int reg_val
;
2382 ret
= snd_soc_component_read(component
, e
->reg
, ®_val
);
2385 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2386 item
= snd_soc_enum_val_to_item(e
, val
);
2387 ucontrol
->value
.enumerated
.item
[0] = item
;
2388 if (e
->shift_l
!= e
->shift_r
) {
2389 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2390 item
= snd_soc_enum_val_to_item(e
, val
);
2391 ucontrol
->value
.enumerated
.item
[1] = item
;
2396 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2399 * snd_soc_put_enum_double - enumerated double mixer put callback
2400 * @kcontrol: mixer control
2401 * @ucontrol: control element information
2403 * Callback to set the value of a double enumerated mixer.
2405 * Returns 0 for success.
2407 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2408 struct snd_ctl_elem_value
*ucontrol
)
2410 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2411 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2412 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
2416 if (item
[0] >= e
->items
)
2418 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
2419 mask
= e
->mask
<< e
->shift_l
;
2420 if (e
->shift_l
!= e
->shift_r
) {
2421 if (item
[1] >= e
->items
)
2423 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_r
;
2424 mask
|= e
->mask
<< e
->shift_r
;
2427 return snd_soc_component_update_bits(component
, e
->reg
, mask
, val
);
2429 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2432 * snd_soc_read_signed - Read a codec register and interprete as signed value
2433 * @component: component
2434 * @reg: Register to read
2435 * @mask: Mask to use after shifting the register value
2436 * @shift: Right shift of register value
2437 * @sign_bit: Bit that describes if a number is negative or not.
2438 * @signed_val: Pointer to where the read value should be stored
2440 * This functions reads a codec register. The register value is shifted right
2441 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2442 * the given registervalue into a signed integer if sign_bit is non-zero.
2444 * Returns 0 on sucess, otherwise an error value
2446 static int snd_soc_read_signed(struct snd_soc_component
*component
,
2447 unsigned int reg
, unsigned int mask
, unsigned int shift
,
2448 unsigned int sign_bit
, int *signed_val
)
2453 ret
= snd_soc_component_read(component
, reg
, &val
);
2457 val
= (val
>> shift
) & mask
;
2464 /* non-negative number */
2465 if (!(val
& BIT(sign_bit
))) {
2473 * The register most probably does not contain a full-sized int.
2474 * Instead we have an arbitrary number of bits in a signed
2475 * representation which has to be translated into a full-sized int.
2476 * This is done by filling up all bits above the sign-bit.
2478 ret
|= ~((int)(BIT(sign_bit
) - 1));
2486 * snd_soc_info_volsw - single mixer info callback
2487 * @kcontrol: mixer control
2488 * @uinfo: control element information
2490 * Callback to provide information about a single mixer control, or a double
2491 * mixer control that spans 2 registers.
2493 * Returns 0 for success.
2495 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2496 struct snd_ctl_elem_info
*uinfo
)
2498 struct soc_mixer_control
*mc
=
2499 (struct soc_mixer_control
*)kcontrol
->private_value
;
2502 if (!mc
->platform_max
)
2503 mc
->platform_max
= mc
->max
;
2504 platform_max
= mc
->platform_max
;
2506 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2507 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2509 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2511 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2512 uinfo
->value
.integer
.min
= 0;
2513 uinfo
->value
.integer
.max
= platform_max
- mc
->min
;
2516 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2519 * snd_soc_get_volsw - single mixer get callback
2520 * @kcontrol: mixer control
2521 * @ucontrol: control element information
2523 * Callback to get the value of a single mixer control, or a double mixer
2524 * control that spans 2 registers.
2526 * Returns 0 for success.
2528 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2529 struct snd_ctl_elem_value
*ucontrol
)
2531 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2532 struct soc_mixer_control
*mc
=
2533 (struct soc_mixer_control
*)kcontrol
->private_value
;
2534 unsigned int reg
= mc
->reg
;
2535 unsigned int reg2
= mc
->rreg
;
2536 unsigned int shift
= mc
->shift
;
2537 unsigned int rshift
= mc
->rshift
;
2540 int sign_bit
= mc
->sign_bit
;
2541 unsigned int mask
= (1 << fls(max
)) - 1;
2542 unsigned int invert
= mc
->invert
;
2547 mask
= BIT(sign_bit
+ 1) - 1;
2549 ret
= snd_soc_read_signed(component
, reg
, mask
, shift
, sign_bit
, &val
);
2553 ucontrol
->value
.integer
.value
[0] = val
- min
;
2555 ucontrol
->value
.integer
.value
[0] =
2556 max
- ucontrol
->value
.integer
.value
[0];
2558 if (snd_soc_volsw_is_stereo(mc
)) {
2560 ret
= snd_soc_read_signed(component
, reg
, mask
, rshift
,
2563 ret
= snd_soc_read_signed(component
, reg2
, mask
, shift
,
2568 ucontrol
->value
.integer
.value
[1] = val
- min
;
2570 ucontrol
->value
.integer
.value
[1] =
2571 max
- ucontrol
->value
.integer
.value
[1];
2576 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2579 * snd_soc_put_volsw - single mixer put callback
2580 * @kcontrol: mixer control
2581 * @ucontrol: control element information
2583 * Callback to set the value of a single mixer control, or a double mixer
2584 * control that spans 2 registers.
2586 * Returns 0 for success.
2588 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2589 struct snd_ctl_elem_value
*ucontrol
)
2591 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2592 struct soc_mixer_control
*mc
=
2593 (struct soc_mixer_control
*)kcontrol
->private_value
;
2594 unsigned int reg
= mc
->reg
;
2595 unsigned int reg2
= mc
->rreg
;
2596 unsigned int shift
= mc
->shift
;
2597 unsigned int rshift
= mc
->rshift
;
2600 unsigned int sign_bit
= mc
->sign_bit
;
2601 unsigned int mask
= (1 << fls(max
)) - 1;
2602 unsigned int invert
= mc
->invert
;
2604 bool type_2r
= false;
2605 unsigned int val2
= 0;
2606 unsigned int val
, val_mask
;
2609 mask
= BIT(sign_bit
+ 1) - 1;
2611 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2614 val_mask
= mask
<< shift
;
2616 if (snd_soc_volsw_is_stereo(mc
)) {
2617 val2
= ((ucontrol
->value
.integer
.value
[1] + min
) & mask
);
2621 val_mask
|= mask
<< rshift
;
2622 val
|= val2
<< rshift
;
2624 val2
= val2
<< shift
;
2628 err
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2633 err
= snd_soc_component_update_bits(component
, reg2
, val_mask
,
2638 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2641 * snd_soc_get_volsw_sx - single mixer get callback
2642 * @kcontrol: mixer control
2643 * @ucontrol: control element information
2645 * Callback to get the value of a single mixer control, or a double mixer
2646 * control that spans 2 registers.
2648 * Returns 0 for success.
2650 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2651 struct snd_ctl_elem_value
*ucontrol
)
2653 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2654 struct soc_mixer_control
*mc
=
2655 (struct soc_mixer_control
*)kcontrol
->private_value
;
2656 unsigned int reg
= mc
->reg
;
2657 unsigned int reg2
= mc
->rreg
;
2658 unsigned int shift
= mc
->shift
;
2659 unsigned int rshift
= mc
->rshift
;
2662 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2666 ret
= snd_soc_component_read(component
, reg
, &val
);
2670 ucontrol
->value
.integer
.value
[0] = ((val
>> shift
) - min
) & mask
;
2672 if (snd_soc_volsw_is_stereo(mc
)) {
2673 ret
= snd_soc_component_read(component
, reg2
, &val
);
2677 val
= ((val
>> rshift
) - min
) & mask
;
2678 ucontrol
->value
.integer
.value
[1] = val
;
2683 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2686 * snd_soc_put_volsw_sx - double mixer set callback
2687 * @kcontrol: mixer control
2688 * @uinfo: control element information
2690 * Callback to set the value of a double mixer control that spans 2 registers.
2692 * Returns 0 for success.
2694 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2695 struct snd_ctl_elem_value
*ucontrol
)
2697 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2698 struct soc_mixer_control
*mc
=
2699 (struct soc_mixer_control
*)kcontrol
->private_value
;
2701 unsigned int reg
= mc
->reg
;
2702 unsigned int reg2
= mc
->rreg
;
2703 unsigned int shift
= mc
->shift
;
2704 unsigned int rshift
= mc
->rshift
;
2707 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2709 unsigned int val
, val_mask
, val2
= 0;
2711 val_mask
= mask
<< shift
;
2712 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2715 err
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2719 if (snd_soc_volsw_is_stereo(mc
)) {
2720 val_mask
= mask
<< rshift
;
2721 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2722 val2
= val2
<< rshift
;
2724 err
= snd_soc_component_update_bits(component
, reg2
, val_mask
,
2729 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2732 * snd_soc_info_volsw_s8 - signed mixer info callback
2733 * @kcontrol: mixer control
2734 * @uinfo: control element information
2736 * Callback to provide information about a signed mixer control.
2738 * Returns 0 for success.
2740 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2741 struct snd_ctl_elem_info
*uinfo
)
2743 struct soc_mixer_control
*mc
=
2744 (struct soc_mixer_control
*)kcontrol
->private_value
;
2748 if (!mc
->platform_max
)
2749 mc
->platform_max
= mc
->max
;
2750 platform_max
= mc
->platform_max
;
2752 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2754 uinfo
->value
.integer
.min
= 0;
2755 uinfo
->value
.integer
.max
= platform_max
- min
;
2758 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2761 * snd_soc_get_volsw_s8 - signed mixer get callback
2762 * @kcontrol: mixer control
2763 * @ucontrol: control element information
2765 * Callback to get the value of a signed mixer control.
2767 * Returns 0 for success.
2769 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2770 struct snd_ctl_elem_value
*ucontrol
)
2772 struct soc_mixer_control
*mc
=
2773 (struct soc_mixer_control
*)kcontrol
->private_value
;
2774 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2775 unsigned int reg
= mc
->reg
;
2780 ret
= snd_soc_component_read(component
, reg
, &val
);
2784 ucontrol
->value
.integer
.value
[0] =
2785 ((signed char)(val
& 0xff))-min
;
2786 ucontrol
->value
.integer
.value
[1] =
2787 ((signed char)((val
>> 8) & 0xff))-min
;
2790 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2793 * snd_soc_put_volsw_sgn - signed mixer put callback
2794 * @kcontrol: mixer control
2795 * @ucontrol: control element information
2797 * Callback to set the value of a signed mixer control.
2799 * Returns 0 for success.
2801 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2802 struct snd_ctl_elem_value
*ucontrol
)
2804 struct soc_mixer_control
*mc
=
2805 (struct soc_mixer_control
*)kcontrol
->private_value
;
2806 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2807 unsigned int reg
= mc
->reg
;
2811 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2812 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2814 return snd_soc_component_update_bits(component
, reg
, 0xffff, val
);
2816 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2819 * snd_soc_info_volsw_range - single mixer info callback with range.
2820 * @kcontrol: mixer control
2821 * @uinfo: control element information
2823 * Callback to provide information, within a range, about a single
2826 * returns 0 for success.
2828 int snd_soc_info_volsw_range(struct snd_kcontrol
*kcontrol
,
2829 struct snd_ctl_elem_info
*uinfo
)
2831 struct soc_mixer_control
*mc
=
2832 (struct soc_mixer_control
*)kcontrol
->private_value
;
2836 if (!mc
->platform_max
)
2837 mc
->platform_max
= mc
->max
;
2838 platform_max
= mc
->platform_max
;
2840 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2841 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2842 uinfo
->value
.integer
.min
= 0;
2843 uinfo
->value
.integer
.max
= platform_max
- min
;
2847 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range
);
2850 * snd_soc_put_volsw_range - single mixer put value callback with range.
2851 * @kcontrol: mixer control
2852 * @ucontrol: control element information
2854 * Callback to set the value, within a range, for a single mixer control.
2856 * Returns 0 for success.
2858 int snd_soc_put_volsw_range(struct snd_kcontrol
*kcontrol
,
2859 struct snd_ctl_elem_value
*ucontrol
)
2861 struct soc_mixer_control
*mc
=
2862 (struct soc_mixer_control
*)kcontrol
->private_value
;
2863 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2864 unsigned int reg
= mc
->reg
;
2865 unsigned int rreg
= mc
->rreg
;
2866 unsigned int shift
= mc
->shift
;
2869 unsigned int mask
= (1 << fls(max
)) - 1;
2870 unsigned int invert
= mc
->invert
;
2871 unsigned int val
, val_mask
;
2875 val
= (max
- ucontrol
->value
.integer
.value
[0]) & mask
;
2877 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2878 val_mask
= mask
<< shift
;
2881 ret
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2885 if (snd_soc_volsw_is_stereo(mc
)) {
2887 val
= (max
- ucontrol
->value
.integer
.value
[1]) & mask
;
2889 val
= ((ucontrol
->value
.integer
.value
[1] + min
) & mask
);
2890 val_mask
= mask
<< shift
;
2893 ret
= snd_soc_component_update_bits(component
, rreg
, val_mask
,
2899 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range
);
2902 * snd_soc_get_volsw_range - single mixer get callback with range
2903 * @kcontrol: mixer control
2904 * @ucontrol: control element information
2906 * Callback to get the value, within a range, of a single mixer control.
2908 * Returns 0 for success.
2910 int snd_soc_get_volsw_range(struct snd_kcontrol
*kcontrol
,
2911 struct snd_ctl_elem_value
*ucontrol
)
2913 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2914 struct soc_mixer_control
*mc
=
2915 (struct soc_mixer_control
*)kcontrol
->private_value
;
2916 unsigned int reg
= mc
->reg
;
2917 unsigned int rreg
= mc
->rreg
;
2918 unsigned int shift
= mc
->shift
;
2921 unsigned int mask
= (1 << fls(max
)) - 1;
2922 unsigned int invert
= mc
->invert
;
2926 ret
= snd_soc_component_read(component
, reg
, &val
);
2930 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
2932 ucontrol
->value
.integer
.value
[0] =
2933 max
- ucontrol
->value
.integer
.value
[0];
2935 ucontrol
->value
.integer
.value
[0] =
2936 ucontrol
->value
.integer
.value
[0] - min
;
2938 if (snd_soc_volsw_is_stereo(mc
)) {
2939 ret
= snd_soc_component_read(component
, rreg
, &val
);
2943 ucontrol
->value
.integer
.value
[1] = (val
>> shift
) & mask
;
2945 ucontrol
->value
.integer
.value
[1] =
2946 max
- ucontrol
->value
.integer
.value
[1];
2948 ucontrol
->value
.integer
.value
[1] =
2949 ucontrol
->value
.integer
.value
[1] - min
;
2954 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range
);
2957 * snd_soc_limit_volume - Set new limit to an existing volume control.
2959 * @codec: where to look for the control
2960 * @name: Name of the control
2961 * @max: new maximum limit
2963 * Return 0 for success, else error.
2965 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2966 const char *name
, int max
)
2968 struct snd_card
*card
= codec
->component
.card
->snd_card
;
2969 struct snd_kcontrol
*kctl
;
2970 struct soc_mixer_control
*mc
;
2974 /* Sanity check for name and max */
2975 if (unlikely(!name
|| max
<= 0))
2978 list_for_each_entry(kctl
, &card
->controls
, list
) {
2979 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2985 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2986 if (max
<= mc
->max
) {
2987 mc
->platform_max
= max
;
2993 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2995 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
2996 struct snd_ctl_elem_info
*uinfo
)
2998 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2999 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3001 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3002 uinfo
->count
= params
->num_regs
* component
->val_bytes
;
3006 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
3008 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
3009 struct snd_ctl_elem_value
*ucontrol
)
3011 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3012 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3015 if (component
->regmap
)
3016 ret
= regmap_raw_read(component
->regmap
, params
->base
,
3017 ucontrol
->value
.bytes
.data
,
3018 params
->num_regs
* component
->val_bytes
);
3022 /* Hide any masked bytes to ensure consistent data reporting */
3023 if (ret
== 0 && params
->mask
) {
3024 switch (component
->val_bytes
) {
3026 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
3029 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
3030 &= cpu_to_be16(~params
->mask
);
3033 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
3034 &= cpu_to_be32(~params
->mask
);
3043 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
3045 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
3046 struct snd_ctl_elem_value
*ucontrol
)
3048 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3049 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3051 unsigned int val
, mask
;
3054 if (!component
->regmap
|| !params
->num_regs
)
3057 len
= params
->num_regs
* component
->val_bytes
;
3059 data
= kmemdup(ucontrol
->value
.bytes
.data
, len
, GFP_KERNEL
| GFP_DMA
);
3064 * If we've got a mask then we need to preserve the register
3065 * bits. We shouldn't modify the incoming data so take a
3069 ret
= regmap_read(component
->regmap
, params
->base
, &val
);
3073 val
&= params
->mask
;
3075 switch (component
->val_bytes
) {
3077 ((u8
*)data
)[0] &= ~params
->mask
;
3078 ((u8
*)data
)[0] |= val
;
3081 mask
= ~params
->mask
;
3082 ret
= regmap_parse_val(component
->regmap
,
3087 ((u16
*)data
)[0] &= mask
;
3089 ret
= regmap_parse_val(component
->regmap
,
3094 ((u16
*)data
)[0] |= val
;
3097 mask
= ~params
->mask
;
3098 ret
= regmap_parse_val(component
->regmap
,
3103 ((u32
*)data
)[0] &= mask
;
3105 ret
= regmap_parse_val(component
->regmap
,
3110 ((u32
*)data
)[0] |= val
;
3118 ret
= regmap_raw_write(component
->regmap
, params
->base
,
3126 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
3128 int snd_soc_bytes_info_ext(struct snd_kcontrol
*kcontrol
,
3129 struct snd_ctl_elem_info
*ucontrol
)
3131 struct soc_bytes_ext
*params
= (void *)kcontrol
->private_value
;
3133 ucontrol
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3134 ucontrol
->count
= params
->max
;
3138 EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext
);
3140 int snd_soc_bytes_tlv_callback(struct snd_kcontrol
*kcontrol
, int op_flag
,
3141 unsigned int size
, unsigned int __user
*tlv
)
3143 struct soc_bytes_ext
*params
= (void *)kcontrol
->private_value
;
3144 unsigned int count
= size
< params
->max
? size
: params
->max
;
3148 case SNDRV_CTL_TLV_OP_READ
:
3150 ret
= params
->get(tlv
, count
);
3152 case SNDRV_CTL_TLV_OP_WRITE
:
3154 ret
= params
->put(tlv
, count
);
3159 EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback
);
3162 * snd_soc_info_xr_sx - signed multi register info callback
3163 * @kcontrol: mreg control
3164 * @uinfo: control element information
3166 * Callback to provide information of a control that can
3167 * span multiple codec registers which together
3168 * forms a single signed value in a MSB/LSB manner.
3170 * Returns 0 for success.
3172 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
3173 struct snd_ctl_elem_info
*uinfo
)
3175 struct soc_mreg_control
*mc
=
3176 (struct soc_mreg_control
*)kcontrol
->private_value
;
3177 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3179 uinfo
->value
.integer
.min
= mc
->min
;
3180 uinfo
->value
.integer
.max
= mc
->max
;
3184 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
3187 * snd_soc_get_xr_sx - signed multi register get callback
3188 * @kcontrol: mreg control
3189 * @ucontrol: control element information
3191 * Callback to get the value of a control that can span
3192 * multiple codec registers which together forms a single
3193 * signed value in a MSB/LSB manner. The control supports
3194 * specifying total no of bits used to allow for bitfields
3195 * across the multiple codec registers.
3197 * Returns 0 for success.
3199 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
3200 struct snd_ctl_elem_value
*ucontrol
)
3202 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3203 struct soc_mreg_control
*mc
=
3204 (struct soc_mreg_control
*)kcontrol
->private_value
;
3205 unsigned int regbase
= mc
->regbase
;
3206 unsigned int regcount
= mc
->regcount
;
3207 unsigned int regwshift
= component
->val_bytes
* BITS_PER_BYTE
;
3208 unsigned int regwmask
= (1<<regwshift
)-1;
3209 unsigned int invert
= mc
->invert
;
3210 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3214 unsigned int regval
;
3218 for (i
= 0; i
< regcount
; i
++) {
3219 ret
= snd_soc_component_read(component
, regbase
+i
, ®val
);
3222 val
|= (regval
& regwmask
) << (regwshift
*(regcount
-i
-1));
3225 if (min
< 0 && val
> max
)
3229 ucontrol
->value
.integer
.value
[0] = val
;
3233 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3236 * snd_soc_put_xr_sx - signed multi register get callback
3237 * @kcontrol: mreg control
3238 * @ucontrol: control element information
3240 * Callback to set the value of a control that can span
3241 * multiple codec registers which together forms a single
3242 * signed value in a MSB/LSB manner. The control supports
3243 * specifying total no of bits used to allow for bitfields
3244 * across the multiple codec registers.
3246 * Returns 0 for success.
3248 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3249 struct snd_ctl_elem_value
*ucontrol
)
3251 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3252 struct soc_mreg_control
*mc
=
3253 (struct soc_mreg_control
*)kcontrol
->private_value
;
3254 unsigned int regbase
= mc
->regbase
;
3255 unsigned int regcount
= mc
->regcount
;
3256 unsigned int regwshift
= component
->val_bytes
* BITS_PER_BYTE
;
3257 unsigned int regwmask
= (1<<regwshift
)-1;
3258 unsigned int invert
= mc
->invert
;
3259 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3261 long val
= ucontrol
->value
.integer
.value
[0];
3262 unsigned int i
, regval
, regmask
;
3268 for (i
= 0; i
< regcount
; i
++) {
3269 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3270 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3271 err
= snd_soc_component_update_bits(component
, regbase
+i
,
3279 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3282 * snd_soc_get_strobe - strobe get callback
3283 * @kcontrol: mixer control
3284 * @ucontrol: control element information
3286 * Callback get the value of a strobe mixer control.
3288 * Returns 0 for success.
3290 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3291 struct snd_ctl_elem_value
*ucontrol
)
3293 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3294 struct soc_mixer_control
*mc
=
3295 (struct soc_mixer_control
*)kcontrol
->private_value
;
3296 unsigned int reg
= mc
->reg
;
3297 unsigned int shift
= mc
->shift
;
3298 unsigned int mask
= 1 << shift
;
3299 unsigned int invert
= mc
->invert
!= 0;
3303 ret
= snd_soc_component_read(component
, reg
, &val
);
3309 if (shift
!= 0 && val
!= 0)
3311 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3315 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3318 * snd_soc_put_strobe - strobe put callback
3319 * @kcontrol: mixer control
3320 * @ucontrol: control element information
3322 * Callback strobe a register bit to high then low (or the inverse)
3323 * in one pass of a single mixer enum control.
3325 * Returns 1 for success.
3327 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3328 struct snd_ctl_elem_value
*ucontrol
)
3330 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3331 struct soc_mixer_control
*mc
=
3332 (struct soc_mixer_control
*)kcontrol
->private_value
;
3333 unsigned int reg
= mc
->reg
;
3334 unsigned int shift
= mc
->shift
;
3335 unsigned int mask
= 1 << shift
;
3336 unsigned int invert
= mc
->invert
!= 0;
3337 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3338 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3339 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3342 err
= snd_soc_component_update_bits(component
, reg
, mask
, val1
);
3346 return snd_soc_component_update_bits(component
, reg
, mask
, val2
);
3348 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3351 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3353 * @clk_id: DAI specific clock ID
3354 * @freq: new clock frequency in Hz
3355 * @dir: new clock direction - input/output.
3357 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3359 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3360 unsigned int freq
, int dir
)
3362 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3363 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3364 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3365 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3370 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3373 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3375 * @clk_id: DAI specific clock ID
3376 * @source: Source for the clock
3377 * @freq: new clock frequency in Hz
3378 * @dir: new clock direction - input/output.
3380 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3382 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3383 int source
, unsigned int freq
, int dir
)
3385 if (codec
->driver
->set_sysclk
)
3386 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3391 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3394 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3396 * @div_id: DAI specific clock divider ID
3397 * @div: new clock divisor.
3399 * Configures the clock dividers. This is used to derive the best DAI bit and
3400 * frame clocks from the system or master clock. It's best to set the DAI bit
3401 * and frame clocks as low as possible to save system power.
3403 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3404 int div_id
, int div
)
3406 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3407 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3411 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3414 * snd_soc_dai_set_pll - configure DAI PLL.
3416 * @pll_id: DAI specific PLL ID
3417 * @source: DAI specific source for the PLL
3418 * @freq_in: PLL input clock frequency in Hz
3419 * @freq_out: requested PLL output clock frequency in Hz
3421 * Configures and enables PLL to generate output clock based on input clock.
3423 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3424 unsigned int freq_in
, unsigned int freq_out
)
3426 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3427 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3429 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3430 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3435 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3438 * snd_soc_codec_set_pll - configure codec PLL.
3440 * @pll_id: DAI specific PLL ID
3441 * @source: DAI specific source for the PLL
3442 * @freq_in: PLL input clock frequency in Hz
3443 * @freq_out: requested PLL output clock frequency in Hz
3445 * Configures and enables PLL to generate output clock based on input clock.
3447 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3448 unsigned int freq_in
, unsigned int freq_out
)
3450 if (codec
->driver
->set_pll
)
3451 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3456 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3459 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
3461 * @ratio Ratio of BCLK to Sample rate.
3463 * Configures the DAI for a preset BCLK to sample rate ratio.
3465 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai
*dai
, unsigned int ratio
)
3467 if (dai
->driver
&& dai
->driver
->ops
->set_bclk_ratio
)
3468 return dai
->driver
->ops
->set_bclk_ratio(dai
, ratio
);
3472 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio
);
3475 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3477 * @fmt: SND_SOC_DAIFMT_ format value.
3479 * Configures the DAI hardware format and clocking.
3481 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3483 if (dai
->driver
== NULL
)
3485 if (dai
->driver
->ops
->set_fmt
== NULL
)
3487 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3489 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3492 * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
3493 * @slots: Number of slots in use.
3494 * @tx_mask: bitmask representing active TX slots.
3495 * @rx_mask: bitmask representing active RX slots.
3497 * Generates the TDM tx and rx slot default masks for DAI.
3499 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots
,
3500 unsigned int *tx_mask
,
3501 unsigned int *rx_mask
)
3503 if (*tx_mask
|| *rx_mask
)
3509 *tx_mask
= (1 << slots
) - 1;
3510 *rx_mask
= (1 << slots
) - 1;
3516 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3518 * @tx_mask: bitmask representing active TX slots.
3519 * @rx_mask: bitmask representing active RX slots.
3520 * @slots: Number of slots in use.
3521 * @slot_width: Width in bits for each slot.
3523 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3526 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3527 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3529 if (dai
->driver
&& dai
->driver
->ops
->xlate_tdm_slot_mask
)
3530 dai
->driver
->ops
->xlate_tdm_slot_mask(slots
,
3531 &tx_mask
, &rx_mask
);
3533 snd_soc_xlate_tdm_slot_mask(slots
, &tx_mask
, &rx_mask
);
3535 dai
->tx_mask
= tx_mask
;
3536 dai
->rx_mask
= rx_mask
;
3538 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3539 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3544 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3547 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3549 * @tx_num: how many TX channels
3550 * @tx_slot: pointer to an array which imply the TX slot number channel
3552 * @rx_num: how many RX channels
3553 * @rx_slot: pointer to an array which imply the RX slot number channel
3556 * configure the relationship between channel number and TDM slot number.
3558 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3559 unsigned int tx_num
, unsigned int *tx_slot
,
3560 unsigned int rx_num
, unsigned int *rx_slot
)
3562 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3563 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3568 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3571 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3573 * @tristate: tristate enable
3575 * Tristates the DAI so that others can use it.
3577 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3579 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3580 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3584 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3587 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3589 * @mute: mute enable
3590 * @direction: stream to mute
3592 * Mutes the DAI DAC.
3594 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
,
3600 if (dai
->driver
->ops
->mute_stream
)
3601 return dai
->driver
->ops
->mute_stream(dai
, mute
, direction
);
3602 else if (direction
== SNDRV_PCM_STREAM_PLAYBACK
&&
3603 dai
->driver
->ops
->digital_mute
)
3604 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3608 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3610 static int snd_soc_init_multicodec(struct snd_soc_card
*card
,
3611 struct snd_soc_dai_link
*dai_link
)
3613 /* Legacy codec/codec_dai link is a single entry in multicodec */
3614 if (dai_link
->codec_name
|| dai_link
->codec_of_node
||
3615 dai_link
->codec_dai_name
) {
3616 dai_link
->num_codecs
= 1;
3618 dai_link
->codecs
= devm_kzalloc(card
->dev
,
3619 sizeof(struct snd_soc_dai_link_component
),
3621 if (!dai_link
->codecs
)
3624 dai_link
->codecs
[0].name
= dai_link
->codec_name
;
3625 dai_link
->codecs
[0].of_node
= dai_link
->codec_of_node
;
3626 dai_link
->codecs
[0].dai_name
= dai_link
->codec_dai_name
;
3629 if (!dai_link
->codecs
) {
3630 dev_err(card
->dev
, "ASoC: DAI link has no CODECs\n");
3638 * snd_soc_register_card - Register a card with the ASoC core
3640 * @card: Card to register
3643 int snd_soc_register_card(struct snd_soc_card
*card
)
3647 if (!card
->name
|| !card
->dev
)
3650 for (i
= 0; i
< card
->num_links
; i
++) {
3651 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3653 ret
= snd_soc_init_multicodec(card
, link
);
3655 dev_err(card
->dev
, "ASoC: failed to init multicodec\n");
3659 for (j
= 0; j
< link
->num_codecs
; j
++) {
3661 * Codec must be specified by 1 of name or OF node,
3662 * not both or neither.
3664 if (!!link
->codecs
[j
].name
==
3665 !!link
->codecs
[j
].of_node
) {
3666 dev_err(card
->dev
, "ASoC: Neither/both codec name/of_node are set for %s\n",
3670 /* Codec DAI name must be specified */
3671 if (!link
->codecs
[j
].dai_name
) {
3672 dev_err(card
->dev
, "ASoC: codec_dai_name not set for %s\n",
3679 * Platform may be specified by either name or OF node, but
3680 * can be left unspecified, and a dummy platform will be used.
3682 if (link
->platform_name
&& link
->platform_of_node
) {
3684 "ASoC: Both platform name/of_node are set for %s\n",
3690 * CPU device may be specified by either name or OF node, but
3691 * can be left unspecified, and will be matched based on DAI
3694 if (link
->cpu_name
&& link
->cpu_of_node
) {
3696 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3701 * At least one of CPU DAI name or CPU device name/node must be
3704 if (!link
->cpu_dai_name
&&
3705 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3707 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3713 dev_set_drvdata(card
->dev
, card
);
3715 snd_soc_initialize_card_lists(card
);
3717 soc_init_card_debugfs(card
);
3719 card
->rtd
= devm_kzalloc(card
->dev
,
3720 sizeof(struct snd_soc_pcm_runtime
) *
3721 (card
->num_links
+ card
->num_aux_devs
),
3723 if (card
->rtd
== NULL
)
3726 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3728 for (i
= 0; i
< card
->num_links
; i
++) {
3729 card
->rtd
[i
].card
= card
;
3730 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3731 card
->rtd
[i
].codec_dais
= devm_kzalloc(card
->dev
,
3732 sizeof(struct snd_soc_dai
*) *
3733 (card
->rtd
[i
].dai_link
->num_codecs
),
3735 if (card
->rtd
[i
].codec_dais
== NULL
)
3739 for (i
= 0; i
< card
->num_aux_devs
; i
++)
3740 card
->rtd_aux
[i
].card
= card
;
3742 INIT_LIST_HEAD(&card
->dapm_dirty
);
3743 card
->instantiated
= 0;
3744 mutex_init(&card
->mutex
);
3745 mutex_init(&card
->dapm_mutex
);
3747 ret
= snd_soc_instantiate_card(card
);
3749 soc_cleanup_card_debugfs(card
);
3751 /* deactivate pins to sleep state */
3752 for (i
= 0; i
< card
->num_rtd
; i
++) {
3753 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
3754 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3757 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
3758 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[j
];
3759 if (!codec_dai
->active
)
3760 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
3763 if (!cpu_dai
->active
)
3764 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
3769 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3772 * snd_soc_unregister_card - Unregister a card with the ASoC core
3774 * @card: Card to unregister
3777 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3779 if (card
->instantiated
) {
3780 card
->instantiated
= false;
3781 snd_soc_dapm_shutdown(card
);
3782 soc_cleanup_card_resources(card
);
3784 dev_dbg(card
->dev
, "ASoC: Unregistered card '%s'\n", card
->name
);
3788 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3791 * Simplify DAI link configuration by removing ".-1" from device names
3792 * and sanitizing names.
3794 static char *fmt_single_name(struct device
*dev
, int *id
)
3796 char *found
, name
[NAME_SIZE
];
3799 if (dev_name(dev
) == NULL
)
3802 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3804 /* are we a "%s.%d" name (platform and SPI components) */
3805 found
= strstr(name
, dev
->driver
->name
);
3808 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3810 /* discard ID from name if ID == -1 */
3812 found
[strlen(dev
->driver
->name
)] = '\0';
3816 /* I2C component devices are named "bus-addr" */
3817 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3818 char tmp
[NAME_SIZE
];
3820 /* create unique ID number from I2C addr and bus */
3821 *id
= ((id1
& 0xffff) << 16) + id2
;
3823 /* sanitize component name for DAI link creation */
3824 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3825 strlcpy(name
, tmp
, NAME_SIZE
);
3830 return kstrdup(name
, GFP_KERNEL
);
3834 * Simplify DAI link naming for single devices with multiple DAIs by removing
3835 * any ".-1" and using the DAI name (instead of device name).
3837 static inline char *fmt_multiple_name(struct device
*dev
,
3838 struct snd_soc_dai_driver
*dai_drv
)
3840 if (dai_drv
->name
== NULL
) {
3842 "ASoC: error - multiple DAI %s registered with no name\n",
3847 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3851 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
3853 * @component: The component for which the DAIs should be unregistered
3855 static void snd_soc_unregister_dais(struct snd_soc_component
*component
)
3857 struct snd_soc_dai
*dai
, *_dai
;
3859 list_for_each_entry_safe(dai
, _dai
, &component
->dai_list
, list
) {
3860 dev_dbg(component
->dev
, "ASoC: Unregistered DAI '%s'\n",
3862 list_del(&dai
->list
);
3869 * snd_soc_register_dais - Register a DAI with the ASoC core
3871 * @component: The component the DAIs are registered for
3872 * @dai_drv: DAI driver to use for the DAIs
3873 * @count: Number of DAIs
3874 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3877 static int snd_soc_register_dais(struct snd_soc_component
*component
,
3878 struct snd_soc_dai_driver
*dai_drv
, size_t count
,
3879 bool legacy_dai_naming
)
3881 struct device
*dev
= component
->dev
;
3882 struct snd_soc_dai
*dai
;
3886 dev_dbg(dev
, "ASoC: dai register %s #%Zu\n", dev_name(dev
), count
);
3888 component
->dai_drv
= dai_drv
;
3889 component
->num_dai
= count
;
3891 for (i
= 0; i
< count
; i
++) {
3893 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3900 * Back in the old days when we still had component-less DAIs,
3901 * instead of having a static name, component-less DAIs would
3902 * inherit the name of the parent device so it is possible to
3903 * register multiple instances of the DAI. We still need to keep
3904 * the same naming style even though those DAIs are not
3905 * component-less anymore.
3907 if (count
== 1 && legacy_dai_naming
) {
3908 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3910 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3912 dai
->id
= dai_drv
[i
].id
;
3916 if (dai
->name
== NULL
) {
3922 dai
->component
= component
;
3924 dai
->driver
= &dai_drv
[i
];
3925 if (!dai
->driver
->ops
)
3926 dai
->driver
->ops
= &null_dai_ops
;
3928 list_add(&dai
->list
, &component
->dai_list
);
3930 dev_dbg(dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3936 snd_soc_unregister_dais(component
);
3941 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context
*dapm
,
3942 enum snd_soc_dapm_type type
, int subseq
)
3944 struct snd_soc_component
*component
= dapm
->component
;
3946 component
->driver
->seq_notifier(component
, type
, subseq
);
3949 static int snd_soc_component_stream_event(struct snd_soc_dapm_context
*dapm
,
3952 struct snd_soc_component
*component
= dapm
->component
;
3954 return component
->driver
->stream_event(component
, event
);
3957 static int snd_soc_component_initialize(struct snd_soc_component
*component
,
3958 const struct snd_soc_component_driver
*driver
, struct device
*dev
)
3960 struct snd_soc_dapm_context
*dapm
;
3962 component
->name
= fmt_single_name(dev
, &component
->id
);
3963 if (!component
->name
) {
3964 dev_err(dev
, "ASoC: Failed to allocate name\n");
3968 component
->dev
= dev
;
3969 component
->driver
= driver
;
3970 component
->probe
= component
->driver
->probe
;
3971 component
->remove
= component
->driver
->remove
;
3973 if (!component
->dapm_ptr
)
3974 component
->dapm_ptr
= &component
->dapm
;
3976 dapm
= component
->dapm_ptr
;
3978 dapm
->component
= component
;
3979 dapm
->bias_level
= SND_SOC_BIAS_OFF
;
3980 dapm
->idle_bias_off
= true;
3981 if (driver
->seq_notifier
)
3982 dapm
->seq_notifier
= snd_soc_component_seq_notifier
;
3983 if (driver
->stream_event
)
3984 dapm
->stream_event
= snd_soc_component_stream_event
;
3986 component
->controls
= driver
->controls
;
3987 component
->num_controls
= driver
->num_controls
;
3988 component
->dapm_widgets
= driver
->dapm_widgets
;
3989 component
->num_dapm_widgets
= driver
->num_dapm_widgets
;
3990 component
->dapm_routes
= driver
->dapm_routes
;
3991 component
->num_dapm_routes
= driver
->num_dapm_routes
;
3993 INIT_LIST_HEAD(&component
->dai_list
);
3994 mutex_init(&component
->io_mutex
);
3999 static void snd_soc_component_init_regmap(struct snd_soc_component
*component
)
4001 if (!component
->regmap
)
4002 component
->regmap
= dev_get_regmap(component
->dev
, NULL
);
4003 if (component
->regmap
) {
4004 int val_bytes
= regmap_get_val_bytes(component
->regmap
);
4005 /* Errors are legitimate for non-integer byte multiples */
4007 component
->val_bytes
= val_bytes
;
4011 static void snd_soc_component_add_unlocked(struct snd_soc_component
*component
)
4013 if (!component
->write
&& !component
->read
)
4014 snd_soc_component_init_regmap(component
);
4016 list_add(&component
->list
, &component_list
);
4019 static void snd_soc_component_add(struct snd_soc_component
*component
)
4021 mutex_lock(&client_mutex
);
4022 snd_soc_component_add_unlocked(component
);
4023 mutex_unlock(&client_mutex
);
4026 static void snd_soc_component_cleanup(struct snd_soc_component
*component
)
4028 snd_soc_unregister_dais(component
);
4029 kfree(component
->name
);
4032 static void snd_soc_component_del_unlocked(struct snd_soc_component
*component
)
4034 list_del(&component
->list
);
4037 static void snd_soc_component_del(struct snd_soc_component
*component
)
4039 mutex_lock(&client_mutex
);
4040 snd_soc_component_del_unlocked(component
);
4041 mutex_unlock(&client_mutex
);
4044 int snd_soc_register_component(struct device
*dev
,
4045 const struct snd_soc_component_driver
*cmpnt_drv
,
4046 struct snd_soc_dai_driver
*dai_drv
,
4049 struct snd_soc_component
*cmpnt
;
4052 cmpnt
= kzalloc(sizeof(*cmpnt
), GFP_KERNEL
);
4054 dev_err(dev
, "ASoC: Failed to allocate memory\n");
4058 ret
= snd_soc_component_initialize(cmpnt
, cmpnt_drv
, dev
);
4062 cmpnt
->ignore_pmdown_time
= true;
4063 cmpnt
->registered_as_component
= true;
4065 ret
= snd_soc_register_dais(cmpnt
, dai_drv
, num_dai
, true);
4067 dev_err(dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4071 snd_soc_component_add(cmpnt
);
4076 snd_soc_component_cleanup(cmpnt
);
4081 EXPORT_SYMBOL_GPL(snd_soc_register_component
);
4084 * snd_soc_unregister_component - Unregister a component from the ASoC core
4087 void snd_soc_unregister_component(struct device
*dev
)
4089 struct snd_soc_component
*cmpnt
;
4091 list_for_each_entry(cmpnt
, &component_list
, list
) {
4092 if (dev
== cmpnt
->dev
&& cmpnt
->registered_as_component
)
4098 snd_soc_component_del(cmpnt
);
4099 snd_soc_component_cleanup(cmpnt
);
4102 EXPORT_SYMBOL_GPL(snd_soc_unregister_component
);
4104 static int snd_soc_platform_drv_probe(struct snd_soc_component
*component
)
4106 struct snd_soc_platform
*platform
= snd_soc_component_to_platform(component
);
4108 return platform
->driver
->probe(platform
);
4111 static void snd_soc_platform_drv_remove(struct snd_soc_component
*component
)
4113 struct snd_soc_platform
*platform
= snd_soc_component_to_platform(component
);
4115 platform
->driver
->remove(platform
);
4119 * snd_soc_add_platform - Add a platform to the ASoC core
4120 * @dev: The parent device for the platform
4121 * @platform: The platform to add
4122 * @platform_driver: The driver for the platform
4124 int snd_soc_add_platform(struct device
*dev
, struct snd_soc_platform
*platform
,
4125 const struct snd_soc_platform_driver
*platform_drv
)
4129 ret
= snd_soc_component_initialize(&platform
->component
,
4130 &platform_drv
->component_driver
, dev
);
4134 platform
->dev
= dev
;
4135 platform
->driver
= platform_drv
;
4137 if (platform_drv
->probe
)
4138 platform
->component
.probe
= snd_soc_platform_drv_probe
;
4139 if (platform_drv
->remove
)
4140 platform
->component
.remove
= snd_soc_platform_drv_remove
;
4142 #ifdef CONFIG_DEBUG_FS
4143 platform
->component
.debugfs_prefix
= "platform";
4146 mutex_lock(&client_mutex
);
4147 snd_soc_component_add_unlocked(&platform
->component
);
4148 list_add(&platform
->list
, &platform_list
);
4149 mutex_unlock(&client_mutex
);
4151 dev_dbg(dev
, "ASoC: Registered platform '%s'\n",
4152 platform
->component
.name
);
4156 EXPORT_SYMBOL_GPL(snd_soc_add_platform
);
4159 * snd_soc_register_platform - Register a platform with the ASoC core
4161 * @platform: platform to register
4163 int snd_soc_register_platform(struct device
*dev
,
4164 const struct snd_soc_platform_driver
*platform_drv
)
4166 struct snd_soc_platform
*platform
;
4169 dev_dbg(dev
, "ASoC: platform register %s\n", dev_name(dev
));
4171 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
4172 if (platform
== NULL
)
4175 ret
= snd_soc_add_platform(dev
, platform
, platform_drv
);
4181 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
4184 * snd_soc_remove_platform - Remove a platform from the ASoC core
4185 * @platform: the platform to remove
4187 void snd_soc_remove_platform(struct snd_soc_platform
*platform
)
4190 mutex_lock(&client_mutex
);
4191 list_del(&platform
->list
);
4192 snd_soc_component_del_unlocked(&platform
->component
);
4193 mutex_unlock(&client_mutex
);
4195 dev_dbg(platform
->dev
, "ASoC: Unregistered platform '%s'\n",
4196 platform
->component
.name
);
4198 snd_soc_component_cleanup(&platform
->component
);
4200 EXPORT_SYMBOL_GPL(snd_soc_remove_platform
);
4202 struct snd_soc_platform
*snd_soc_lookup_platform(struct device
*dev
)
4204 struct snd_soc_platform
*platform
;
4206 list_for_each_entry(platform
, &platform_list
, list
) {
4207 if (dev
== platform
->dev
)
4213 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform
);
4216 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
4218 * @platform: platform to unregister
4220 void snd_soc_unregister_platform(struct device
*dev
)
4222 struct snd_soc_platform
*platform
;
4224 platform
= snd_soc_lookup_platform(dev
);
4228 snd_soc_remove_platform(platform
);
4231 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
4233 static u64 codec_format_map
[] = {
4234 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
4235 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
4236 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
4237 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
4238 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
4239 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
4240 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4241 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4242 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
4243 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
4244 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
4245 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
4246 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
4247 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
4248 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
4249 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
4252 /* Fix up the DAI formats for endianness: codecs don't actually see
4253 * the endianness of the data but we're using the CPU format
4254 * definitions which do need to include endianness so we ensure that
4255 * codec DAIs always have both big and little endian variants set.
4257 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
4261 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
4262 if (stream
->formats
& codec_format_map
[i
])
4263 stream
->formats
|= codec_format_map
[i
];
4266 static int snd_soc_codec_drv_probe(struct snd_soc_component
*component
)
4268 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4270 return codec
->driver
->probe(codec
);
4273 static void snd_soc_codec_drv_remove(struct snd_soc_component
*component
)
4275 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4277 codec
->driver
->remove(codec
);
4280 static int snd_soc_codec_drv_write(struct snd_soc_component
*component
,
4281 unsigned int reg
, unsigned int val
)
4283 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4285 return codec
->driver
->write(codec
, reg
, val
);
4288 static int snd_soc_codec_drv_read(struct snd_soc_component
*component
,
4289 unsigned int reg
, unsigned int *val
)
4291 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4293 *val
= codec
->driver
->read(codec
, reg
);
4298 static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context
*dapm
,
4299 enum snd_soc_bias_level level
)
4301 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(dapm
);
4303 return codec
->driver
->set_bias_level(codec
, level
);
4307 * snd_soc_register_codec - Register a codec with the ASoC core
4309 * @codec: codec to register
4311 int snd_soc_register_codec(struct device
*dev
,
4312 const struct snd_soc_codec_driver
*codec_drv
,
4313 struct snd_soc_dai_driver
*dai_drv
,
4316 struct snd_soc_codec
*codec
;
4317 struct snd_soc_dai
*dai
;
4320 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
4322 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
4326 codec
->component
.dapm_ptr
= &codec
->dapm
;
4327 codec
->component
.codec
= codec
;
4329 ret
= snd_soc_component_initialize(&codec
->component
,
4330 &codec_drv
->component_driver
, dev
);
4334 if (codec_drv
->controls
) {
4335 codec
->component
.controls
= codec_drv
->controls
;
4336 codec
->component
.num_controls
= codec_drv
->num_controls
;
4338 if (codec_drv
->dapm_widgets
) {
4339 codec
->component
.dapm_widgets
= codec_drv
->dapm_widgets
;
4340 codec
->component
.num_dapm_widgets
= codec_drv
->num_dapm_widgets
;
4342 if (codec_drv
->dapm_routes
) {
4343 codec
->component
.dapm_routes
= codec_drv
->dapm_routes
;
4344 codec
->component
.num_dapm_routes
= codec_drv
->num_dapm_routes
;
4347 if (codec_drv
->probe
)
4348 codec
->component
.probe
= snd_soc_codec_drv_probe
;
4349 if (codec_drv
->remove
)
4350 codec
->component
.remove
= snd_soc_codec_drv_remove
;
4351 if (codec_drv
->write
)
4352 codec
->component
.write
= snd_soc_codec_drv_write
;
4353 if (codec_drv
->read
)
4354 codec
->component
.read
= snd_soc_codec_drv_read
;
4355 codec
->component
.ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
4356 codec
->dapm
.idle_bias_off
= codec_drv
->idle_bias_off
;
4357 codec
->dapm
.suspend_bias_off
= codec_drv
->suspend_bias_off
;
4358 if (codec_drv
->seq_notifier
)
4359 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
4360 if (codec_drv
->set_bias_level
)
4361 codec
->dapm
.set_bias_level
= snd_soc_codec_set_bias_level
;
4363 codec
->driver
= codec_drv
;
4364 codec
->component
.val_bytes
= codec_drv
->reg_word_size
;
4366 #ifdef CONFIG_DEBUG_FS
4367 codec
->component
.init_debugfs
= soc_init_codec_debugfs
;
4368 codec
->component
.debugfs_prefix
= "codec";
4371 if (codec_drv
->get_regmap
)
4372 codec
->component
.regmap
= codec_drv
->get_regmap(dev
);
4374 for (i
= 0; i
< num_dai
; i
++) {
4375 fixup_codec_formats(&dai_drv
[i
].playback
);
4376 fixup_codec_formats(&dai_drv
[i
].capture
);
4379 ret
= snd_soc_register_dais(&codec
->component
, dai_drv
, num_dai
, false);
4381 dev_err(dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4385 list_for_each_entry(dai
, &codec
->component
.dai_list
, list
)
4388 mutex_lock(&client_mutex
);
4389 snd_soc_component_add_unlocked(&codec
->component
);
4390 list_add(&codec
->list
, &codec_list
);
4391 mutex_unlock(&client_mutex
);
4393 dev_dbg(codec
->dev
, "ASoC: Registered codec '%s'\n",
4394 codec
->component
.name
);
4398 snd_soc_component_cleanup(&codec
->component
);
4403 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
4406 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4408 * @codec: codec to unregister
4410 void snd_soc_unregister_codec(struct device
*dev
)
4412 struct snd_soc_codec
*codec
;
4414 list_for_each_entry(codec
, &codec_list
, list
) {
4415 if (dev
== codec
->dev
)
4422 mutex_lock(&client_mutex
);
4423 list_del(&codec
->list
);
4424 snd_soc_component_del_unlocked(&codec
->component
);
4425 mutex_unlock(&client_mutex
);
4427 dev_dbg(codec
->dev
, "ASoC: Unregistered codec '%s'\n",
4428 codec
->component
.name
);
4430 snd_soc_component_cleanup(&codec
->component
);
4431 snd_soc_cache_exit(codec
);
4434 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
4436 /* Retrieve a card's name from device tree */
4437 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
4438 const char *propname
)
4440 struct device_node
*np
;
4444 pr_err("card->dev is not set before calling %s\n", __func__
);
4448 np
= card
->dev
->of_node
;
4450 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
4452 * EINVAL means the property does not exist. This is fine providing
4453 * card->name was previously set, which is checked later in
4454 * snd_soc_register_card.
4456 if (ret
< 0 && ret
!= -EINVAL
) {
4458 "ASoC: Property '%s' could not be read: %d\n",
4465 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
4467 static const struct snd_soc_dapm_widget simple_widgets
[] = {
4468 SND_SOC_DAPM_MIC("Microphone", NULL
),
4469 SND_SOC_DAPM_LINE("Line", NULL
),
4470 SND_SOC_DAPM_HP("Headphone", NULL
),
4471 SND_SOC_DAPM_SPK("Speaker", NULL
),
4474 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card
*card
,
4475 const char *propname
)
4477 struct device_node
*np
= card
->dev
->of_node
;
4478 struct snd_soc_dapm_widget
*widgets
;
4479 const char *template, *wname
;
4480 int i
, j
, num_widgets
, ret
;
4482 num_widgets
= of_property_count_strings(np
, propname
);
4483 if (num_widgets
< 0) {
4485 "ASoC: Property '%s' does not exist\n", propname
);
4488 if (num_widgets
& 1) {
4490 "ASoC: Property '%s' length is not even\n", propname
);
4496 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4501 widgets
= devm_kcalloc(card
->dev
, num_widgets
, sizeof(*widgets
),
4505 "ASoC: Could not allocate memory for widgets\n");
4509 for (i
= 0; i
< num_widgets
; i
++) {
4510 ret
= of_property_read_string_index(np
, propname
,
4514 "ASoC: Property '%s' index %d read error:%d\n",
4515 propname
, 2 * i
, ret
);
4519 for (j
= 0; j
< ARRAY_SIZE(simple_widgets
); j
++) {
4520 if (!strncmp(template, simple_widgets
[j
].name
,
4521 strlen(simple_widgets
[j
].name
))) {
4522 widgets
[i
] = simple_widgets
[j
];
4527 if (j
>= ARRAY_SIZE(simple_widgets
)) {
4529 "ASoC: DAPM widget '%s' is not supported\n",
4534 ret
= of_property_read_string_index(np
, propname
,
4539 "ASoC: Property '%s' index %d read error:%d\n",
4540 propname
, (2 * i
) + 1, ret
);
4544 widgets
[i
].name
= wname
;
4547 card
->dapm_widgets
= widgets
;
4548 card
->num_dapm_widgets
= num_widgets
;
4552 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets
);
4554 int snd_soc_of_parse_tdm_slot(struct device_node
*np
,
4555 unsigned int *slots
,
4556 unsigned int *slot_width
)
4561 if (of_property_read_bool(np
, "dai-tdm-slot-num")) {
4562 ret
= of_property_read_u32(np
, "dai-tdm-slot-num", &val
);
4570 if (of_property_read_bool(np
, "dai-tdm-slot-width")) {
4571 ret
= of_property_read_u32(np
, "dai-tdm-slot-width", &val
);
4581 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot
);
4583 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
4584 const char *propname
)
4586 struct device_node
*np
= card
->dev
->of_node
;
4588 struct snd_soc_dapm_route
*routes
;
4591 num_routes
= of_property_count_strings(np
, propname
);
4592 if (num_routes
< 0 || num_routes
& 1) {
4594 "ASoC: Property '%s' does not exist or its length is not even\n",
4600 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4605 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
4609 "ASoC: Could not allocate DAPM route table\n");
4613 for (i
= 0; i
< num_routes
; i
++) {
4614 ret
= of_property_read_string_index(np
, propname
,
4615 2 * i
, &routes
[i
].sink
);
4618 "ASoC: Property '%s' index %d could not be read: %d\n",
4619 propname
, 2 * i
, ret
);
4622 ret
= of_property_read_string_index(np
, propname
,
4623 (2 * i
) + 1, &routes
[i
].source
);
4626 "ASoC: Property '%s' index %d could not be read: %d\n",
4627 propname
, (2 * i
) + 1, ret
);
4632 card
->num_dapm_routes
= num_routes
;
4633 card
->dapm_routes
= routes
;
4637 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
4639 unsigned int snd_soc_of_parse_daifmt(struct device_node
*np
,
4641 struct device_node
**bitclkmaster
,
4642 struct device_node
**framemaster
)
4646 unsigned int format
= 0;
4652 } of_fmt_table
[] = {
4653 { "i2s", SND_SOC_DAIFMT_I2S
},
4654 { "right_j", SND_SOC_DAIFMT_RIGHT_J
},
4655 { "left_j", SND_SOC_DAIFMT_LEFT_J
},
4656 { "dsp_a", SND_SOC_DAIFMT_DSP_A
},
4657 { "dsp_b", SND_SOC_DAIFMT_DSP_B
},
4658 { "ac97", SND_SOC_DAIFMT_AC97
},
4659 { "pdm", SND_SOC_DAIFMT_PDM
},
4660 { "msb", SND_SOC_DAIFMT_MSB
},
4661 { "lsb", SND_SOC_DAIFMT_LSB
},
4668 * check "[prefix]format = xxx"
4669 * SND_SOC_DAIFMT_FORMAT_MASK area
4671 snprintf(prop
, sizeof(prop
), "%sformat", prefix
);
4672 ret
= of_property_read_string(np
, prop
, &str
);
4674 for (i
= 0; i
< ARRAY_SIZE(of_fmt_table
); i
++) {
4675 if (strcmp(str
, of_fmt_table
[i
].name
) == 0) {
4676 format
|= of_fmt_table
[i
].val
;
4683 * check "[prefix]continuous-clock"
4684 * SND_SOC_DAIFMT_CLOCK_MASK area
4686 snprintf(prop
, sizeof(prop
), "%scontinuous-clock", prefix
);
4687 if (of_get_property(np
, prop
, NULL
))
4688 format
|= SND_SOC_DAIFMT_CONT
;
4690 format
|= SND_SOC_DAIFMT_GATED
;
4693 * check "[prefix]bitclock-inversion"
4694 * check "[prefix]frame-inversion"
4695 * SND_SOC_DAIFMT_INV_MASK area
4697 snprintf(prop
, sizeof(prop
), "%sbitclock-inversion", prefix
);
4698 bit
= !!of_get_property(np
, prop
, NULL
);
4700 snprintf(prop
, sizeof(prop
), "%sframe-inversion", prefix
);
4701 frame
= !!of_get_property(np
, prop
, NULL
);
4703 switch ((bit
<< 4) + frame
) {
4705 format
|= SND_SOC_DAIFMT_IB_IF
;
4708 format
|= SND_SOC_DAIFMT_IB_NF
;
4711 format
|= SND_SOC_DAIFMT_NB_IF
;
4714 /* SND_SOC_DAIFMT_NB_NF is default */
4719 * check "[prefix]bitclock-master"
4720 * check "[prefix]frame-master"
4721 * SND_SOC_DAIFMT_MASTER_MASK area
4723 snprintf(prop
, sizeof(prop
), "%sbitclock-master", prefix
);
4724 bit
= !!of_get_property(np
, prop
, NULL
);
4725 if (bit
&& bitclkmaster
)
4726 *bitclkmaster
= of_parse_phandle(np
, prop
, 0);
4728 snprintf(prop
, sizeof(prop
), "%sframe-master", prefix
);
4729 frame
= !!of_get_property(np
, prop
, NULL
);
4730 if (frame
&& framemaster
)
4731 *framemaster
= of_parse_phandle(np
, prop
, 0);
4733 switch ((bit
<< 4) + frame
) {
4735 format
|= SND_SOC_DAIFMT_CBM_CFM
;
4738 format
|= SND_SOC_DAIFMT_CBM_CFS
;
4741 format
|= SND_SOC_DAIFMT_CBS_CFM
;
4744 format
|= SND_SOC_DAIFMT_CBS_CFS
;
4750 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt
);
4752 int snd_soc_of_get_dai_name(struct device_node
*of_node
,
4753 const char **dai_name
)
4755 struct snd_soc_component
*pos
;
4756 struct of_phandle_args args
;
4759 ret
= of_parse_phandle_with_args(of_node
, "sound-dai",
4760 "#sound-dai-cells", 0, &args
);
4764 ret
= -EPROBE_DEFER
;
4766 mutex_lock(&client_mutex
);
4767 list_for_each_entry(pos
, &component_list
, list
) {
4768 if (pos
->dev
->of_node
!= args
.np
)
4771 if (pos
->driver
->of_xlate_dai_name
) {
4772 ret
= pos
->driver
->of_xlate_dai_name(pos
, &args
, dai_name
);
4776 switch (args
.args_count
) {
4778 id
= 0; /* same as dai_drv[0] */
4788 if (id
< 0 || id
>= pos
->num_dai
) {
4795 *dai_name
= pos
->dai_drv
[id
].name
;
4797 *dai_name
= pos
->name
;
4802 mutex_unlock(&client_mutex
);
4804 of_node_put(args
.np
);
4808 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name
);
4810 static int __init
snd_soc_init(void)
4812 #ifdef CONFIG_DEBUG_FS
4813 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
4814 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
4815 pr_warn("ASoC: Failed to create debugfs directory\n");
4816 snd_soc_debugfs_root
= NULL
;
4819 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
4821 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4823 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
4825 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4827 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
4828 &platform_list_fops
))
4829 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4832 snd_soc_util_init();
4834 return platform_driver_register(&soc_driver
);
4836 module_init(snd_soc_init
);
4838 static void __exit
snd_soc_exit(void)
4840 snd_soc_util_exit();
4842 #ifdef CONFIG_DEBUG_FS
4843 debugfs_remove_recursive(snd_soc_debugfs_root
);
4845 platform_driver_unregister(&soc_driver
);
4847 module_exit(snd_soc_exit
);
4849 /* Module information */
4850 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4851 MODULE_DESCRIPTION("ALSA SoC Core");
4852 MODULE_LICENSE("GPL");
4853 MODULE_ALIAS("platform:soc-audio");