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_del(&codec
->ac97
->dev
);
511 /* register ac97 codec to bus */
512 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
516 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
517 codec
->ac97
->dev
.parent
= codec
->component
.card
->dev
;
519 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
520 codec
->component
.card
->snd_card
->number
, 0,
521 codec
->component
.name
);
522 err
= device_add(&codec
->ac97
->dev
);
524 dev_err(codec
->dev
, "ASoC: Can't register ac97 bus\n");
525 codec
->ac97
->dev
.bus
= NULL
;
532 static void codec2codec_close_delayed_work(struct work_struct
*work
)
534 /* Currently nothing to do for c2c links
535 * Since c2c links are internal nodes in the DAPM graph and
536 * don't interface with the outside world or application layer
537 * we don't have to do any special handling on close.
541 #ifdef CONFIG_PM_SLEEP
542 /* powers down audio subsystem for suspend */
543 int snd_soc_suspend(struct device
*dev
)
545 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
546 struct snd_soc_codec
*codec
;
549 /* If the card is not initialized yet there is nothing to do */
550 if (!card
->instantiated
)
553 /* Due to the resume being scheduled into a workqueue we could
554 * suspend before that's finished - wait for it to complete.
556 snd_power_lock(card
->snd_card
);
557 snd_power_wait(card
->snd_card
, SNDRV_CTL_POWER_D0
);
558 snd_power_unlock(card
->snd_card
);
560 /* we're going to block userspace touching us until resume completes */
561 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D3hot
);
563 /* mute any active DACs */
564 for (i
= 0; i
< card
->num_rtd
; i
++) {
566 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
569 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
570 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dais
[j
];
571 struct snd_soc_dai_driver
*drv
= dai
->driver
;
573 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
574 drv
->ops
->digital_mute(dai
, 1);
578 /* suspend all pcms */
579 for (i
= 0; i
< card
->num_rtd
; i
++) {
580 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
583 snd_pcm_suspend_all(card
->rtd
[i
].pcm
);
586 if (card
->suspend_pre
)
587 card
->suspend_pre(card
);
589 for (i
= 0; i
< card
->num_rtd
; i
++) {
590 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
591 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
593 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
596 if (cpu_dai
->driver
->suspend
&& !cpu_dai
->driver
->ac97_control
)
597 cpu_dai
->driver
->suspend(cpu_dai
);
598 if (platform
->driver
->suspend
&& !platform
->suspended
) {
599 platform
->driver
->suspend(cpu_dai
);
600 platform
->suspended
= 1;
604 /* close any waiting streams and save state */
605 for (i
= 0; i
< card
->num_rtd
; i
++) {
606 struct snd_soc_dai
**codec_dais
= card
->rtd
[i
].codec_dais
;
607 flush_delayed_work(&card
->rtd
[i
].delayed_work
);
608 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
609 codec_dais
[j
]->codec
->dapm
.suspend_bias_level
=
610 codec_dais
[j
]->codec
->dapm
.bias_level
;
614 for (i
= 0; i
< card
->num_rtd
; i
++) {
616 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
619 snd_soc_dapm_stream_event(&card
->rtd
[i
],
620 SNDRV_PCM_STREAM_PLAYBACK
,
621 SND_SOC_DAPM_STREAM_SUSPEND
);
623 snd_soc_dapm_stream_event(&card
->rtd
[i
],
624 SNDRV_PCM_STREAM_CAPTURE
,
625 SND_SOC_DAPM_STREAM_SUSPEND
);
628 /* Recheck all analogue paths too */
629 dapm_mark_io_dirty(&card
->dapm
);
630 snd_soc_dapm_sync(&card
->dapm
);
632 /* suspend all CODECs */
633 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
634 /* If there are paths active then the CODEC will be held with
635 * bias _ON and should not be suspended. */
636 if (!codec
->suspended
) {
637 switch (codec
->dapm
.bias_level
) {
638 case SND_SOC_BIAS_STANDBY
:
640 * If the CODEC is capable of idle
641 * bias off then being in STANDBY
642 * means it's doing something,
643 * otherwise fall through.
645 if (codec
->dapm
.idle_bias_off
) {
647 "ASoC: idle_bias_off CODEC on over suspend\n");
651 case SND_SOC_BIAS_OFF
:
652 if (codec
->driver
->suspend
)
653 codec
->driver
->suspend(codec
);
654 codec
->suspended
= 1;
655 codec
->cache_sync
= 1;
656 if (codec
->component
.regmap
)
657 regcache_mark_dirty(codec
->component
.regmap
);
658 /* deactivate pins to sleep state */
659 pinctrl_pm_select_sleep_state(codec
->dev
);
663 "ASoC: CODEC is on over suspend\n");
669 for (i
= 0; i
< card
->num_rtd
; i
++) {
670 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
672 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
675 if (cpu_dai
->driver
->suspend
&& cpu_dai
->driver
->ac97_control
)
676 cpu_dai
->driver
->suspend(cpu_dai
);
678 /* deactivate pins to sleep state */
679 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
682 if (card
->suspend_post
)
683 card
->suspend_post(card
);
687 EXPORT_SYMBOL_GPL(snd_soc_suspend
);
689 /* deferred resume work, so resume can complete before we finished
690 * setting our codec back up, which can be very slow on I2C
692 static void soc_resume_deferred(struct work_struct
*work
)
694 struct snd_soc_card
*card
=
695 container_of(work
, struct snd_soc_card
, deferred_resume_work
);
696 struct snd_soc_codec
*codec
;
699 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
700 * so userspace apps are blocked from touching us
703 dev_dbg(card
->dev
, "ASoC: starting resume work\n");
705 /* Bring us up into D2 so that DAPM starts enabling things */
706 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D2
);
708 if (card
->resume_pre
)
709 card
->resume_pre(card
);
711 /* resume AC97 DAIs */
712 for (i
= 0; i
< card
->num_rtd
; i
++) {
713 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
715 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
718 if (cpu_dai
->driver
->resume
&& cpu_dai
->driver
->ac97_control
)
719 cpu_dai
->driver
->resume(cpu_dai
);
722 list_for_each_entry(codec
, &card
->codec_dev_list
, card_list
) {
723 /* If the CODEC was idle over suspend then it will have been
724 * left with bias OFF or STANDBY and suspended so we must now
725 * resume. Otherwise the suspend was suppressed.
727 if (codec
->suspended
) {
728 switch (codec
->dapm
.bias_level
) {
729 case SND_SOC_BIAS_STANDBY
:
730 case SND_SOC_BIAS_OFF
:
731 if (codec
->driver
->resume
)
732 codec
->driver
->resume(codec
);
733 codec
->suspended
= 0;
737 "ASoC: CODEC was on over suspend\n");
743 for (i
= 0; i
< card
->num_rtd
; i
++) {
745 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
748 snd_soc_dapm_stream_event(&card
->rtd
[i
],
749 SNDRV_PCM_STREAM_PLAYBACK
,
750 SND_SOC_DAPM_STREAM_RESUME
);
752 snd_soc_dapm_stream_event(&card
->rtd
[i
],
753 SNDRV_PCM_STREAM_CAPTURE
,
754 SND_SOC_DAPM_STREAM_RESUME
);
757 /* unmute any active DACs */
758 for (i
= 0; i
< card
->num_rtd
; i
++) {
760 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
763 for (j
= 0; j
< card
->rtd
[i
].num_codecs
; j
++) {
764 struct snd_soc_dai
*dai
= card
->rtd
[i
].codec_dais
[j
];
765 struct snd_soc_dai_driver
*drv
= dai
->driver
;
767 if (drv
->ops
->digital_mute
&& dai
->playback_active
)
768 drv
->ops
->digital_mute(dai
, 0);
772 for (i
= 0; i
< card
->num_rtd
; i
++) {
773 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
774 struct snd_soc_platform
*platform
= card
->rtd
[i
].platform
;
776 if (card
->rtd
[i
].dai_link
->ignore_suspend
)
779 if (cpu_dai
->driver
->resume
&& !cpu_dai
->driver
->ac97_control
)
780 cpu_dai
->driver
->resume(cpu_dai
);
781 if (platform
->driver
->resume
&& platform
->suspended
) {
782 platform
->driver
->resume(cpu_dai
);
783 platform
->suspended
= 0;
787 if (card
->resume_post
)
788 card
->resume_post(card
);
790 dev_dbg(card
->dev
, "ASoC: resume work completed\n");
792 /* userspace can access us now we are back as we were before */
793 snd_power_change_state(card
->snd_card
, SNDRV_CTL_POWER_D0
);
795 /* Recheck all analogue paths too */
796 dapm_mark_io_dirty(&card
->dapm
);
797 snd_soc_dapm_sync(&card
->dapm
);
800 /* powers up audio subsystem after a suspend */
801 int snd_soc_resume(struct device
*dev
)
803 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
804 int i
, ac97_control
= 0;
806 /* If the card is not initialized yet there is nothing to do */
807 if (!card
->instantiated
)
810 /* activate pins from sleep state */
811 for (i
= 0; i
< card
->num_rtd
; i
++) {
812 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
813 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
814 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
818 pinctrl_pm_select_default_state(cpu_dai
->dev
);
820 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
821 struct snd_soc_dai
*codec_dai
= codec_dais
[j
];
822 if (codec_dai
->active
)
823 pinctrl_pm_select_default_state(codec_dai
->dev
);
827 /* AC97 devices might have other drivers hanging off them so
828 * need to resume immediately. Other drivers don't have that
829 * problem and may take a substantial amount of time to resume
830 * due to I/O costs and anti-pop so handle them out of line.
832 for (i
= 0; i
< card
->num_rtd
; i
++) {
833 struct snd_soc_dai
*cpu_dai
= card
->rtd
[i
].cpu_dai
;
834 ac97_control
|= cpu_dai
->driver
->ac97_control
;
837 dev_dbg(dev
, "ASoC: Resuming AC97 immediately\n");
838 soc_resume_deferred(&card
->deferred_resume_work
);
840 dev_dbg(dev
, "ASoC: Scheduling resume work\n");
841 if (!schedule_work(&card
->deferred_resume_work
))
842 dev_err(dev
, "ASoC: resume work item may be lost\n");
847 EXPORT_SYMBOL_GPL(snd_soc_resume
);
849 #define snd_soc_suspend NULL
850 #define snd_soc_resume NULL
853 static const struct snd_soc_dai_ops null_dai_ops
= {
856 static struct snd_soc_component
*soc_find_component(
857 const struct device_node
*of_node
, const char *name
)
859 struct snd_soc_component
*component
;
861 list_for_each_entry(component
, &component_list
, list
) {
863 if (component
->dev
->of_node
== of_node
)
865 } else if (strcmp(component
->name
, name
) == 0) {
873 static struct snd_soc_dai
*snd_soc_find_dai(
874 const struct snd_soc_dai_link_component
*dlc
)
876 struct snd_soc_component
*component
;
877 struct snd_soc_dai
*dai
;
879 /* Find CPU DAI from registered DAIs*/
880 list_for_each_entry(component
, &component_list
, list
) {
881 if (dlc
->of_node
&& component
->dev
->of_node
!= dlc
->of_node
)
883 if (dlc
->name
&& strcmp(dev_name(component
->dev
), dlc
->name
))
885 list_for_each_entry(dai
, &component
->dai_list
, list
) {
886 if (dlc
->dai_name
&& strcmp(dai
->name
, dlc
->dai_name
))
896 static int soc_bind_dai_link(struct snd_soc_card
*card
, int num
)
898 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
899 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
900 struct snd_soc_dai_link_component
*codecs
= dai_link
->codecs
;
901 struct snd_soc_dai_link_component cpu_dai_component
;
902 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
903 struct snd_soc_platform
*platform
;
904 const char *platform_name
;
907 dev_dbg(card
->dev
, "ASoC: binding %s at idx %d\n", dai_link
->name
, num
);
909 cpu_dai_component
.name
= dai_link
->cpu_name
;
910 cpu_dai_component
.of_node
= dai_link
->cpu_of_node
;
911 cpu_dai_component
.dai_name
= dai_link
->cpu_dai_name
;
912 rtd
->cpu_dai
= snd_soc_find_dai(&cpu_dai_component
);
914 dev_err(card
->dev
, "ASoC: CPU DAI %s not registered\n",
915 dai_link
->cpu_dai_name
);
916 return -EPROBE_DEFER
;
919 rtd
->num_codecs
= dai_link
->num_codecs
;
921 /* Find CODEC from registered CODECs */
922 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
923 codec_dais
[i
] = snd_soc_find_dai(&codecs
[i
]);
924 if (!codec_dais
[i
]) {
925 dev_err(card
->dev
, "ASoC: CODEC DAI %s not registered\n",
927 return -EPROBE_DEFER
;
931 /* Single codec links expect codec and codec_dai in runtime data */
932 rtd
->codec_dai
= codec_dais
[0];
933 rtd
->codec
= rtd
->codec_dai
->codec
;
935 /* if there's no platform we match on the empty platform */
936 platform_name
= dai_link
->platform_name
;
937 if (!platform_name
&& !dai_link
->platform_of_node
)
938 platform_name
= "snd-soc-dummy";
940 /* find one from the set of registered platforms */
941 list_for_each_entry(platform
, &platform_list
, list
) {
942 if (dai_link
->platform_of_node
) {
943 if (platform
->dev
->of_node
!=
944 dai_link
->platform_of_node
)
947 if (strcmp(platform
->component
.name
, platform_name
))
951 rtd
->platform
= platform
;
953 if (!rtd
->platform
) {
954 dev_err(card
->dev
, "ASoC: platform %s not registered\n",
955 dai_link
->platform_name
);
956 return -EPROBE_DEFER
;
964 static void soc_remove_component(struct snd_soc_component
*component
)
966 if (!component
->probed
)
969 /* This is a HACK and will be removed soon */
970 if (component
->codec
)
971 list_del(&component
->codec
->card_list
);
973 if (component
->remove
)
974 component
->remove(component
);
976 snd_soc_dapm_free(snd_soc_component_get_dapm(component
));
978 soc_cleanup_component_debugfs(component
);
979 component
->probed
= 0;
980 module_put(component
->dev
->driver
->owner
);
983 static void soc_remove_dai(struct snd_soc_dai
*dai
, int order
)
987 if (dai
&& dai
->probed
&&
988 dai
->driver
->remove_order
== order
) {
989 if (dai
->driver
->remove
) {
990 err
= dai
->driver
->remove(dai
);
993 "ASoC: failed to remove %s: %d\n",
1000 static void soc_remove_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1002 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1005 /* unregister the rtd device */
1006 if (rtd
->dev_registered
) {
1007 device_remove_file(rtd
->dev
, &dev_attr_pmdown_time
);
1008 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1009 device_unregister(rtd
->dev
);
1010 rtd
->dev_registered
= 0;
1013 /* remove the CODEC DAI */
1014 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1015 soc_remove_dai(rtd
->codec_dais
[i
], order
);
1017 soc_remove_dai(rtd
->cpu_dai
, order
);
1020 static void soc_remove_link_components(struct snd_soc_card
*card
, int num
,
1023 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1024 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1025 struct snd_soc_platform
*platform
= rtd
->platform
;
1026 struct snd_soc_component
*component
;
1029 /* remove the platform */
1030 if (platform
&& platform
->component
.driver
->remove_order
== order
)
1031 soc_remove_component(&platform
->component
);
1033 /* remove the CODEC-side CODEC */
1034 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1035 component
= rtd
->codec_dais
[i
]->component
;
1036 if (component
->driver
->remove_order
== order
)
1037 soc_remove_component(component
);
1040 /* remove any CPU-side CODEC */
1042 if (cpu_dai
->component
->driver
->remove_order
== order
)
1043 soc_remove_component(cpu_dai
->component
);
1047 static void soc_remove_dai_links(struct snd_soc_card
*card
)
1051 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1053 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1054 soc_remove_link_dais(card
, dai
, order
);
1057 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1059 for (dai
= 0; dai
< card
->num_rtd
; dai
++)
1060 soc_remove_link_components(card
, dai
, order
);
1066 static void soc_set_name_prefix(struct snd_soc_card
*card
,
1067 struct snd_soc_component
*component
)
1071 if (card
->codec_conf
== NULL
)
1074 for (i
= 0; i
< card
->num_configs
; i
++) {
1075 struct snd_soc_codec_conf
*map
= &card
->codec_conf
[i
];
1076 if (map
->of_node
&& component
->dev
->of_node
!= map
->of_node
)
1078 if (map
->dev_name
&& strcmp(component
->name
, map
->dev_name
))
1080 component
->name_prefix
= map
->name_prefix
;
1085 static int soc_probe_component(struct snd_soc_card
*card
,
1086 struct snd_soc_component
*component
)
1088 struct snd_soc_dapm_context
*dapm
= snd_soc_component_get_dapm(component
);
1089 struct snd_soc_dai
*dai
;
1092 if (component
->probed
)
1095 component
->card
= card
;
1097 soc_set_name_prefix(card
, component
);
1099 if (!try_module_get(component
->dev
->driver
->owner
))
1102 soc_init_component_debugfs(component
);
1104 if (component
->dapm_widgets
) {
1105 ret
= snd_soc_dapm_new_controls(dapm
, component
->dapm_widgets
,
1106 component
->num_dapm_widgets
);
1109 dev_err(component
->dev
,
1110 "Failed to create new controls %d\n", ret
);
1115 list_for_each_entry(dai
, &component
->dai_list
, list
) {
1116 ret
= snd_soc_dapm_new_dai_widgets(dapm
, dai
);
1118 dev_err(component
->dev
,
1119 "Failed to create DAI widgets %d\n", ret
);
1124 if (component
->probe
) {
1125 ret
= component
->probe(component
);
1127 dev_err(component
->dev
,
1128 "ASoC: failed to probe component %d\n", ret
);
1132 WARN(dapm
->idle_bias_off
&&
1133 dapm
->bias_level
!= SND_SOC_BIAS_OFF
,
1134 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1138 if (component
->controls
)
1139 snd_soc_add_component_controls(component
, component
->controls
,
1140 component
->num_controls
);
1141 if (component
->dapm_routes
)
1142 snd_soc_dapm_add_routes(dapm
, component
->dapm_routes
,
1143 component
->num_dapm_routes
);
1145 component
->probed
= 1;
1146 list_add(&dapm
->list
, &card
->dapm_list
);
1148 /* This is a HACK and will be removed soon */
1149 if (component
->codec
)
1150 list_add(&component
->codec
->card_list
, &card
->codec_dev_list
);
1155 soc_cleanup_component_debugfs(component
);
1156 module_put(component
->dev
->driver
->owner
);
1161 static void rtd_release(struct device
*dev
)
1166 static int soc_post_component_init(struct snd_soc_pcm_runtime
*rtd
,
1171 /* register the rtd device */
1172 rtd
->dev
= kzalloc(sizeof(struct device
), GFP_KERNEL
);
1175 device_initialize(rtd
->dev
);
1176 rtd
->dev
->parent
= rtd
->card
->dev
;
1177 rtd
->dev
->release
= rtd_release
;
1178 dev_set_name(rtd
->dev
, "%s", name
);
1179 dev_set_drvdata(rtd
->dev
, rtd
);
1180 mutex_init(&rtd
->pcm_mutex
);
1181 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].be_clients
);
1182 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].be_clients
);
1183 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_PLAYBACK
].fe_clients
);
1184 INIT_LIST_HEAD(&rtd
->dpcm
[SNDRV_PCM_STREAM_CAPTURE
].fe_clients
);
1185 ret
= device_add(rtd
->dev
);
1187 /* calling put_device() here to free the rtd->dev */
1188 put_device(rtd
->dev
);
1189 dev_err(rtd
->card
->dev
,
1190 "ASoC: failed to register runtime device: %d\n", ret
);
1193 rtd
->dev_registered
= 1;
1196 /* add DAPM sysfs entries for this codec */
1197 ret
= snd_soc_dapm_sys_add(rtd
->dev
);
1200 "ASoC: failed to add codec dapm sysfs entries: %d\n",
1203 /* add codec sysfs entries */
1204 ret
= device_create_file(rtd
->dev
, &dev_attr_codec_reg
);
1207 "ASoC: failed to add codec sysfs files: %d\n",
1214 static int soc_probe_link_components(struct snd_soc_card
*card
, int num
,
1217 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1218 struct snd_soc_platform
*platform
= rtd
->platform
;
1219 struct snd_soc_component
*component
;
1222 /* probe the CPU-side component, if it is a CODEC */
1223 component
= rtd
->cpu_dai
->component
;
1224 if (component
->driver
->probe_order
== order
) {
1225 ret
= soc_probe_component(card
, component
);
1230 /* probe the CODEC-side components */
1231 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1232 component
= rtd
->codec_dais
[i
]->component
;
1233 if (component
->driver
->probe_order
== order
) {
1234 ret
= soc_probe_component(card
, component
);
1240 /* probe the platform */
1241 if (platform
->component
.driver
->probe_order
== order
) {
1242 ret
= soc_probe_component(card
, &platform
->component
);
1250 static int soc_probe_codec_dai(struct snd_soc_card
*card
,
1251 struct snd_soc_dai
*codec_dai
,
1256 if (!codec_dai
->probed
&& codec_dai
->driver
->probe_order
== order
) {
1257 if (codec_dai
->driver
->probe
) {
1258 ret
= codec_dai
->driver
->probe(codec_dai
);
1260 dev_err(codec_dai
->dev
,
1261 "ASoC: failed to probe CODEC DAI %s: %d\n",
1262 codec_dai
->name
, ret
);
1267 /* mark codec_dai as probed and add to card dai list */
1268 codec_dai
->probed
= 1;
1274 static int soc_link_dai_widgets(struct snd_soc_card
*card
,
1275 struct snd_soc_dai_link
*dai_link
,
1276 struct snd_soc_pcm_runtime
*rtd
)
1278 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1279 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
1280 struct snd_soc_dapm_widget
*play_w
, *capture_w
;
1283 if (rtd
->num_codecs
> 1)
1284 dev_warn(card
->dev
, "ASoC: Multiple codecs not supported yet\n");
1286 /* link the DAI widgets */
1287 play_w
= codec_dai
->playback_widget
;
1288 capture_w
= cpu_dai
->capture_widget
;
1289 if (play_w
&& capture_w
) {
1290 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1293 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1294 play_w
->name
, capture_w
->name
, ret
);
1299 play_w
= cpu_dai
->playback_widget
;
1300 capture_w
= codec_dai
->capture_widget
;
1301 if (play_w
&& capture_w
) {
1302 ret
= snd_soc_dapm_new_pcm(card
, dai_link
->params
,
1305 dev_err(card
->dev
, "ASoC: Can't link %s to %s: %d\n",
1306 play_w
->name
, capture_w
->name
, ret
);
1314 static int soc_probe_link_dais(struct snd_soc_card
*card
, int num
, int order
)
1316 struct snd_soc_dai_link
*dai_link
= &card
->dai_link
[num
];
1317 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[num
];
1318 struct snd_soc_platform
*platform
= rtd
->platform
;
1319 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1322 dev_dbg(card
->dev
, "ASoC: probe %s dai link %d late %d\n",
1323 card
->name
, num
, order
);
1325 /* config components */
1326 cpu_dai
->platform
= platform
;
1327 cpu_dai
->card
= card
;
1328 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1329 rtd
->codec_dais
[i
]->card
= card
;
1331 /* set default power off timeout */
1332 rtd
->pmdown_time
= pmdown_time
;
1334 /* probe the cpu_dai */
1335 if (!cpu_dai
->probed
&&
1336 cpu_dai
->driver
->probe_order
== order
) {
1337 if (cpu_dai
->driver
->probe
) {
1338 ret
= cpu_dai
->driver
->probe(cpu_dai
);
1340 dev_err(cpu_dai
->dev
,
1341 "ASoC: failed to probe CPU DAI %s: %d\n",
1342 cpu_dai
->name
, ret
);
1346 cpu_dai
->probed
= 1;
1349 /* probe the CODEC DAI */
1350 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1351 ret
= soc_probe_codec_dai(card
, rtd
->codec_dais
[i
], order
);
1356 /* complete DAI probe during last probe */
1357 if (order
!= SND_SOC_COMP_ORDER_LAST
)
1360 /* do machine specific initialization */
1361 if (dai_link
->init
) {
1362 ret
= dai_link
->init(rtd
);
1364 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n",
1365 dai_link
->name
, ret
);
1370 ret
= soc_post_component_init(rtd
, dai_link
->name
);
1374 #ifdef CONFIG_DEBUG_FS
1375 /* add DPCM sysfs entries */
1376 if (dai_link
->dynamic
) {
1377 ret
= soc_dpcm_debugfs_add(rtd
);
1380 "ASoC: failed to add dpcm sysfs entries: %d\n",
1387 ret
= device_create_file(rtd
->dev
, &dev_attr_pmdown_time
);
1389 dev_warn(rtd
->dev
, "ASoC: failed to add pmdown_time sysfs: %d\n",
1392 if (cpu_dai
->driver
->compress_dai
) {
1393 /*create compress_device"*/
1394 ret
= soc_new_compress(rtd
, num
);
1396 dev_err(card
->dev
, "ASoC: can't create compress %s\n",
1397 dai_link
->stream_name
);
1402 if (!dai_link
->params
) {
1403 /* create the pcm */
1404 ret
= soc_new_pcm(rtd
, num
);
1406 dev_err(card
->dev
, "ASoC: can't create pcm %s :%d\n",
1407 dai_link
->stream_name
, ret
);
1411 INIT_DELAYED_WORK(&rtd
->delayed_work
,
1412 codec2codec_close_delayed_work
);
1414 /* link the DAI widgets */
1415 ret
= soc_link_dai_widgets(card
, dai_link
, rtd
);
1421 /* add platform data for AC97 devices */
1422 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1423 if (rtd
->codec_dais
[i
]->driver
->ac97_control
)
1424 snd_ac97_dev_add_pdata(rtd
->codec_dais
[i
]->codec
->ac97
,
1425 rtd
->cpu_dai
->ac97_pdata
);
1431 #ifdef CONFIG_SND_SOC_AC97_BUS
1432 static int soc_register_ac97_codec(struct snd_soc_codec
*codec
,
1433 struct snd_soc_dai
*codec_dai
)
1437 /* Only instantiate AC97 if not already done by the adaptor
1438 * for the generic AC97 subsystem.
1440 if (codec_dai
->driver
->ac97_control
&& !codec
->ac97_registered
) {
1442 * It is possible that the AC97 device is already registered to
1443 * the device subsystem. This happens when the device is created
1444 * via snd_ac97_mixer(). Currently only SoC codec that does so
1445 * is the generic AC97 glue but others migh emerge.
1447 * In those cases we don't try to register the device again.
1449 if (!codec
->ac97_created
)
1452 ret
= soc_ac97_dev_register(codec
);
1455 "ASoC: AC97 device register failed: %d\n", ret
);
1459 codec
->ac97_registered
= 1;
1464 static void soc_unregister_ac97_codec(struct snd_soc_codec
*codec
)
1466 if (codec
->ac97_registered
) {
1467 soc_ac97_dev_unregister(codec
);
1468 codec
->ac97_registered
= 0;
1472 static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1476 for (i
= 0; i
< rtd
->num_codecs
; i
++) {
1477 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[i
];
1479 ret
= soc_register_ac97_codec(codec_dai
->codec
, codec_dai
);
1482 soc_unregister_ac97_codec(codec_dai
->codec
);
1490 static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime
*rtd
)
1494 for (i
= 0; i
< rtd
->num_codecs
; i
++)
1495 soc_unregister_ac97_codec(rtd
->codec_dais
[i
]->codec
);
1499 static int soc_bind_aux_dev(struct snd_soc_card
*card
, int num
)
1501 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1502 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1503 const char *name
= aux_dev
->codec_name
;
1505 rtd
->component
= soc_find_component(aux_dev
->codec_of_node
, name
);
1506 if (!rtd
->component
) {
1507 if (aux_dev
->codec_of_node
)
1508 name
= of_node_full_name(aux_dev
->codec_of_node
);
1510 dev_err(card
->dev
, "ASoC: %s not registered\n", name
);
1511 return -EPROBE_DEFER
;
1515 * Some places still reference rtd->codec, so we have to keep that
1516 * initialized if the component is a CODEC. Once all those references
1517 * have been removed, this code can be removed as well.
1519 rtd
->codec
= rtd
->component
->codec
;
1524 static int soc_probe_aux_dev(struct snd_soc_card
*card
, int num
)
1526 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1527 struct snd_soc_aux_dev
*aux_dev
= &card
->aux_dev
[num
];
1530 ret
= soc_probe_component(card
, rtd
->component
);
1534 /* do machine specific initialization */
1535 if (aux_dev
->init
) {
1536 ret
= aux_dev
->init(rtd
->component
);
1538 dev_err(card
->dev
, "ASoC: failed to init %s: %d\n",
1539 aux_dev
->name
, ret
);
1544 return soc_post_component_init(rtd
, aux_dev
->name
);
1547 static void soc_remove_aux_dev(struct snd_soc_card
*card
, int num
)
1549 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd_aux
[num
];
1550 struct snd_soc_component
*component
= rtd
->component
;
1552 /* unregister the rtd device */
1553 if (rtd
->dev_registered
) {
1554 device_remove_file(rtd
->dev
, &dev_attr_codec_reg
);
1555 device_unregister(rtd
->dev
);
1556 rtd
->dev_registered
= 0;
1559 if (component
&& component
->probed
)
1560 soc_remove_component(component
);
1563 static int snd_soc_init_codec_cache(struct snd_soc_codec
*codec
)
1567 if (codec
->cache_init
)
1570 ret
= snd_soc_cache_init(codec
);
1573 "ASoC: Failed to set cache compression type: %d\n",
1577 codec
->cache_init
= 1;
1581 static int snd_soc_instantiate_card(struct snd_soc_card
*card
)
1583 struct snd_soc_codec
*codec
;
1584 struct snd_soc_dai_link
*dai_link
;
1585 int ret
, i
, order
, dai_fmt
;
1587 mutex_lock_nested(&card
->mutex
, SND_SOC_CARD_CLASS_INIT
);
1590 for (i
= 0; i
< card
->num_links
; i
++) {
1591 ret
= soc_bind_dai_link(card
, i
);
1596 /* bind aux_devs too */
1597 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1598 ret
= soc_bind_aux_dev(card
, i
);
1603 /* initialize the register cache for each available codec */
1604 list_for_each_entry(codec
, &codec_list
, list
) {
1605 if (codec
->cache_init
)
1607 ret
= snd_soc_init_codec_cache(codec
);
1612 /* card bind complete so register a sound card */
1613 ret
= snd_card_new(card
->dev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
,
1614 card
->owner
, 0, &card
->snd_card
);
1617 "ASoC: can't create sound card for card %s: %d\n",
1622 card
->dapm
.bias_level
= SND_SOC_BIAS_OFF
;
1623 card
->dapm
.dev
= card
->dev
;
1624 card
->dapm
.card
= card
;
1625 list_add(&card
->dapm
.list
, &card
->dapm_list
);
1627 #ifdef CONFIG_DEBUG_FS
1628 snd_soc_dapm_debugfs_init(&card
->dapm
, card
->debugfs_card_root
);
1631 #ifdef CONFIG_PM_SLEEP
1632 /* deferred resume work */
1633 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
1636 if (card
->dapm_widgets
)
1637 snd_soc_dapm_new_controls(&card
->dapm
, card
->dapm_widgets
,
1638 card
->num_dapm_widgets
);
1640 /* initialise the sound card only once */
1642 ret
= card
->probe(card
);
1644 goto card_probe_error
;
1647 /* probe all components used by DAI links on this card */
1648 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1650 for (i
= 0; i
< card
->num_links
; i
++) {
1651 ret
= soc_probe_link_components(card
, i
, order
);
1654 "ASoC: failed to instantiate card %d\n",
1661 /* probe all DAI links on this card */
1662 for (order
= SND_SOC_COMP_ORDER_FIRST
; order
<= SND_SOC_COMP_ORDER_LAST
;
1664 for (i
= 0; i
< card
->num_links
; i
++) {
1665 ret
= soc_probe_link_dais(card
, i
, order
);
1668 "ASoC: failed to instantiate card %d\n",
1675 for (i
= 0; i
< card
->num_aux_devs
; i
++) {
1676 ret
= soc_probe_aux_dev(card
, i
);
1679 "ASoC: failed to add auxiliary devices %d\n",
1681 goto probe_aux_dev_err
;
1685 snd_soc_dapm_link_dai_widgets(card
);
1686 snd_soc_dapm_connect_dai_link_widgets(card
);
1689 snd_soc_add_card_controls(card
, card
->controls
, card
->num_controls
);
1691 if (card
->dapm_routes
)
1692 snd_soc_dapm_add_routes(&card
->dapm
, card
->dapm_routes
,
1693 card
->num_dapm_routes
);
1695 for (i
= 0; i
< card
->num_links
; i
++) {
1696 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1697 dai_link
= &card
->dai_link
[i
];
1698 dai_fmt
= dai_link
->dai_fmt
;
1701 struct snd_soc_dai
**codec_dais
= rtd
->codec_dais
;
1704 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
1705 struct snd_soc_dai
*codec_dai
= codec_dais
[j
];
1707 ret
= snd_soc_dai_set_fmt(codec_dai
, dai_fmt
);
1708 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1709 dev_warn(codec_dai
->dev
,
1710 "ASoC: Failed to set DAI format: %d\n",
1715 /* If this is a regular CPU link there will be a platform */
1717 (dai_link
->platform_name
|| dai_link
->platform_of_node
)) {
1718 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1720 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1721 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1722 "ASoC: Failed to set DAI format: %d\n",
1724 } else if (dai_fmt
) {
1725 /* Flip the polarity for the "CPU" end */
1726 dai_fmt
&= ~SND_SOC_DAIFMT_MASTER_MASK
;
1727 switch (dai_link
->dai_fmt
&
1728 SND_SOC_DAIFMT_MASTER_MASK
) {
1729 case SND_SOC_DAIFMT_CBM_CFM
:
1730 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
1732 case SND_SOC_DAIFMT_CBM_CFS
:
1733 dai_fmt
|= SND_SOC_DAIFMT_CBS_CFM
;
1735 case SND_SOC_DAIFMT_CBS_CFM
:
1736 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFS
;
1738 case SND_SOC_DAIFMT_CBS_CFS
:
1739 dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
1743 ret
= snd_soc_dai_set_fmt(card
->rtd
[i
].cpu_dai
,
1745 if (ret
!= 0 && ret
!= -ENOTSUPP
)
1746 dev_warn(card
->rtd
[i
].cpu_dai
->dev
,
1747 "ASoC: Failed to set DAI format: %d\n",
1752 snprintf(card
->snd_card
->shortname
, sizeof(card
->snd_card
->shortname
),
1754 snprintf(card
->snd_card
->longname
, sizeof(card
->snd_card
->longname
),
1755 "%s", card
->long_name
? card
->long_name
: card
->name
);
1756 snprintf(card
->snd_card
->driver
, sizeof(card
->snd_card
->driver
),
1757 "%s", card
->driver_name
? card
->driver_name
: card
->name
);
1758 for (i
= 0; i
< ARRAY_SIZE(card
->snd_card
->driver
); i
++) {
1759 switch (card
->snd_card
->driver
[i
]) {
1765 if (!isalnum(card
->snd_card
->driver
[i
]))
1766 card
->snd_card
->driver
[i
] = '_';
1771 if (card
->late_probe
) {
1772 ret
= card
->late_probe(card
);
1774 dev_err(card
->dev
, "ASoC: %s late_probe() failed: %d\n",
1776 goto probe_aux_dev_err
;
1780 if (card
->fully_routed
)
1781 snd_soc_dapm_auto_nc_pins(card
);
1783 snd_soc_dapm_new_widgets(card
);
1785 ret
= snd_card_register(card
->snd_card
);
1787 dev_err(card
->dev
, "ASoC: failed to register soundcard %d\n",
1789 goto probe_aux_dev_err
;
1792 #ifdef CONFIG_SND_SOC_AC97_BUS
1793 /* register any AC97 codecs */
1794 for (i
= 0; i
< card
->num_rtd
; i
++) {
1795 ret
= soc_register_ac97_dai_link(&card
->rtd
[i
]);
1798 "ASoC: failed to register AC97: %d\n", ret
);
1800 soc_unregister_ac97_dai_link(&card
->rtd
[i
]);
1801 goto probe_aux_dev_err
;
1806 card
->instantiated
= 1;
1807 snd_soc_dapm_sync(&card
->dapm
);
1808 mutex_unlock(&card
->mutex
);
1813 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1814 soc_remove_aux_dev(card
, i
);
1817 soc_remove_dai_links(card
);
1823 snd_card_free(card
->snd_card
);
1826 mutex_unlock(&card
->mutex
);
1831 /* probes a new socdev */
1832 static int soc_probe(struct platform_device
*pdev
)
1834 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1837 * no card, so machine driver should be registering card
1838 * we should not be here in that case so ret error
1843 dev_warn(&pdev
->dev
,
1844 "ASoC: machine %s should use snd_soc_register_card()\n",
1847 /* Bodge while we unpick instantiation */
1848 card
->dev
= &pdev
->dev
;
1850 return snd_soc_register_card(card
);
1853 static int soc_cleanup_card_resources(struct snd_soc_card
*card
)
1857 /* make sure any delayed work runs */
1858 for (i
= 0; i
< card
->num_rtd
; i
++) {
1859 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1860 flush_delayed_work(&rtd
->delayed_work
);
1863 /* remove auxiliary devices */
1864 for (i
= 0; i
< card
->num_aux_devs
; i
++)
1865 soc_remove_aux_dev(card
, i
);
1867 /* remove and free each DAI */
1868 soc_remove_dai_links(card
);
1870 soc_cleanup_card_debugfs(card
);
1872 /* remove the card */
1876 snd_soc_dapm_free(&card
->dapm
);
1878 snd_card_free(card
->snd_card
);
1883 /* removes a socdev */
1884 static int soc_remove(struct platform_device
*pdev
)
1886 struct snd_soc_card
*card
= platform_get_drvdata(pdev
);
1888 snd_soc_unregister_card(card
);
1892 int snd_soc_poweroff(struct device
*dev
)
1894 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
1897 if (!card
->instantiated
)
1900 /* Flush out pmdown_time work - we actually do want to run it
1901 * now, we're shutting down so no imminent restart. */
1902 for (i
= 0; i
< card
->num_rtd
; i
++) {
1903 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1904 flush_delayed_work(&rtd
->delayed_work
);
1907 snd_soc_dapm_shutdown(card
);
1909 /* deactivate pins to sleep state */
1910 for (i
= 0; i
< card
->num_rtd
; i
++) {
1911 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
1912 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
1915 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
1916 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
1917 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[j
];
1918 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
1924 EXPORT_SYMBOL_GPL(snd_soc_poweroff
);
1926 const struct dev_pm_ops snd_soc_pm_ops
= {
1927 .suspend
= snd_soc_suspend
,
1928 .resume
= snd_soc_resume
,
1929 .freeze
= snd_soc_suspend
,
1930 .thaw
= snd_soc_resume
,
1931 .poweroff
= snd_soc_poweroff
,
1932 .restore
= snd_soc_resume
,
1934 EXPORT_SYMBOL_GPL(snd_soc_pm_ops
);
1936 /* ASoC platform driver */
1937 static struct platform_driver soc_driver
= {
1939 .name
= "soc-audio",
1940 .owner
= THIS_MODULE
,
1941 .pm
= &snd_soc_pm_ops
,
1944 .remove
= soc_remove
,
1947 static void soc_ac97_device_release(struct device
*dev
)
1949 kfree(to_ac97_t(dev
));
1953 * snd_soc_new_ac97_codec - initailise AC97 device
1954 * @codec: audio codec
1955 * @ops: AC97 bus operations
1956 * @num: AC97 codec number
1958 * Initialises AC97 codec resources for use by ad-hoc devices only.
1960 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1961 struct snd_ac97_bus_ops
*ops
, int num
)
1963 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1964 if (codec
->ac97
== NULL
)
1967 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1968 if (codec
->ac97
->bus
== NULL
) {
1974 codec
->ac97
->bus
->ops
= ops
;
1975 codec
->ac97
->num
= num
;
1976 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
1979 * Mark the AC97 device to be created by us. This way we ensure that the
1980 * device will be registered with the device subsystem later on.
1982 codec
->ac97_created
= 1;
1983 device_initialize(&codec
->ac97
->dev
);
1987 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1989 static struct snd_ac97_reset_cfg snd_ac97_rst_cfg
;
1991 static void snd_soc_ac97_warm_reset(struct snd_ac97
*ac97
)
1993 struct pinctrl
*pctl
= snd_ac97_rst_cfg
.pctl
;
1995 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_warm_reset
);
1997 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 1);
2001 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 0);
2003 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_run
);
2007 static void snd_soc_ac97_reset(struct snd_ac97
*ac97
)
2009 struct pinctrl
*pctl
= snd_ac97_rst_cfg
.pctl
;
2011 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_reset
);
2013 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sync
, 0);
2014 gpio_direction_output(snd_ac97_rst_cfg
.gpio_sdata
, 0);
2015 gpio_direction_output(snd_ac97_rst_cfg
.gpio_reset
, 0);
2019 gpio_direction_output(snd_ac97_rst_cfg
.gpio_reset
, 1);
2021 pinctrl_select_state(pctl
, snd_ac97_rst_cfg
.pstate_run
);
2025 static int snd_soc_ac97_parse_pinctl(struct device
*dev
,
2026 struct snd_ac97_reset_cfg
*cfg
)
2029 struct pinctrl_state
*state
;
2033 p
= devm_pinctrl_get(dev
);
2035 dev_err(dev
, "Failed to get pinctrl\n");
2040 state
= pinctrl_lookup_state(p
, "ac97-reset");
2041 if (IS_ERR(state
)) {
2042 dev_err(dev
, "Can't find pinctrl state ac97-reset\n");
2043 return PTR_ERR(state
);
2045 cfg
->pstate_reset
= state
;
2047 state
= pinctrl_lookup_state(p
, "ac97-warm-reset");
2048 if (IS_ERR(state
)) {
2049 dev_err(dev
, "Can't find pinctrl state ac97-warm-reset\n");
2050 return PTR_ERR(state
);
2052 cfg
->pstate_warm_reset
= state
;
2054 state
= pinctrl_lookup_state(p
, "ac97-running");
2055 if (IS_ERR(state
)) {
2056 dev_err(dev
, "Can't find pinctrl state ac97-running\n");
2057 return PTR_ERR(state
);
2059 cfg
->pstate_run
= state
;
2061 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 0);
2063 dev_err(dev
, "Can't find ac97-sync gpio\n");
2066 ret
= devm_gpio_request(dev
, gpio
, "AC97 link sync");
2068 dev_err(dev
, "Failed requesting ac97-sync gpio\n");
2071 cfg
->gpio_sync
= gpio
;
2073 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 1);
2075 dev_err(dev
, "Can't find ac97-sdata gpio %d\n", gpio
);
2078 ret
= devm_gpio_request(dev
, gpio
, "AC97 link sdata");
2080 dev_err(dev
, "Failed requesting ac97-sdata gpio\n");
2083 cfg
->gpio_sdata
= gpio
;
2085 gpio
= of_get_named_gpio(dev
->of_node
, "ac97-gpios", 2);
2087 dev_err(dev
, "Can't find ac97-reset gpio\n");
2090 ret
= devm_gpio_request(dev
, gpio
, "AC97 link reset");
2092 dev_err(dev
, "Failed requesting ac97-reset gpio\n");
2095 cfg
->gpio_reset
= gpio
;
2100 struct snd_ac97_bus_ops
*soc_ac97_ops
;
2101 EXPORT_SYMBOL_GPL(soc_ac97_ops
);
2103 int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops
*ops
)
2105 if (ops
== soc_ac97_ops
)
2108 if (soc_ac97_ops
&& ops
)
2115 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops
);
2118 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
2120 * This function sets the reset and warm_reset properties of ops and parses
2121 * the device node of pdev to get pinctrl states and gpio numbers to use.
2123 int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops
*ops
,
2124 struct platform_device
*pdev
)
2126 struct device
*dev
= &pdev
->dev
;
2127 struct snd_ac97_reset_cfg cfg
;
2130 ret
= snd_soc_ac97_parse_pinctl(dev
, &cfg
);
2134 ret
= snd_soc_set_ac97_ops(ops
);
2138 ops
->warm_reset
= snd_soc_ac97_warm_reset
;
2139 ops
->reset
= snd_soc_ac97_reset
;
2141 snd_ac97_rst_cfg
= cfg
;
2144 EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset
);
2147 * snd_soc_free_ac97_codec - free AC97 codec device
2148 * @codec: audio codec
2150 * Frees AC97 codec device resources.
2152 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
2154 #ifdef CONFIG_SND_SOC_AC97_BUS
2155 soc_unregister_ac97_codec(codec
);
2157 kfree(codec
->ac97
->bus
);
2158 codec
->ac97
->bus
= NULL
;
2159 put_device(&codec
->ac97
->dev
);
2161 codec
->ac97_created
= 0;
2163 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
2166 * snd_soc_cnew - create new control
2167 * @_template: control template
2168 * @data: control private data
2169 * @long_name: control long name
2170 * @prefix: control name prefix
2172 * Create a new mixer control from a template control.
2174 * Returns 0 for success, else error.
2176 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
2177 void *data
, const char *long_name
,
2180 struct snd_kcontrol_new
template;
2181 struct snd_kcontrol
*kcontrol
;
2184 memcpy(&template, _template
, sizeof(template));
2188 long_name
= template.name
;
2191 name
= kasprintf(GFP_KERNEL
, "%s %s", prefix
, long_name
);
2195 template.name
= name
;
2197 template.name
= long_name
;
2200 kcontrol
= snd_ctl_new1(&template, data
);
2206 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
2208 static int snd_soc_add_controls(struct snd_card
*card
, struct device
*dev
,
2209 const struct snd_kcontrol_new
*controls
, int num_controls
,
2210 const char *prefix
, void *data
)
2214 for (i
= 0; i
< num_controls
; i
++) {
2215 const struct snd_kcontrol_new
*control
= &controls
[i
];
2216 err
= snd_ctl_add(card
, snd_soc_cnew(control
, data
,
2217 control
->name
, prefix
));
2219 dev_err(dev
, "ASoC: Failed to add %s: %d\n",
2220 control
->name
, err
);
2228 struct snd_kcontrol
*snd_soc_card_get_kcontrol(struct snd_soc_card
*soc_card
,
2231 struct snd_card
*card
= soc_card
->snd_card
;
2232 struct snd_kcontrol
*kctl
;
2234 if (unlikely(!name
))
2237 list_for_each_entry(kctl
, &card
->controls
, list
)
2238 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
)))
2242 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol
);
2245 * snd_soc_add_component_controls - Add an array of controls to a component.
2247 * @component: Component to add controls to
2248 * @controls: Array of controls to add
2249 * @num_controls: Number of elements in the array
2251 * Return: 0 for success, else error.
2253 int snd_soc_add_component_controls(struct snd_soc_component
*component
,
2254 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2256 struct snd_card
*card
= component
->card
->snd_card
;
2258 return snd_soc_add_controls(card
, component
->dev
, controls
,
2259 num_controls
, component
->name_prefix
, component
);
2261 EXPORT_SYMBOL_GPL(snd_soc_add_component_controls
);
2264 * snd_soc_add_codec_controls - add an array of controls to a codec.
2265 * Convenience function to add a list of controls. Many codecs were
2266 * duplicating this code.
2268 * @codec: codec to add controls to
2269 * @controls: array of controls to add
2270 * @num_controls: number of elements in the array
2272 * Return 0 for success, else error.
2274 int snd_soc_add_codec_controls(struct snd_soc_codec
*codec
,
2275 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2277 return snd_soc_add_component_controls(&codec
->component
, controls
,
2280 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls
);
2283 * snd_soc_add_platform_controls - add an array of controls to a platform.
2284 * Convenience function to add a list of controls.
2286 * @platform: platform to add controls to
2287 * @controls: array of controls to add
2288 * @num_controls: number of elements in the array
2290 * Return 0 for success, else error.
2292 int snd_soc_add_platform_controls(struct snd_soc_platform
*platform
,
2293 const struct snd_kcontrol_new
*controls
, unsigned int num_controls
)
2295 return snd_soc_add_component_controls(&platform
->component
, controls
,
2298 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls
);
2301 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2302 * Convenience function to add a list of controls.
2304 * @soc_card: SoC card to add controls to
2305 * @controls: array of controls to add
2306 * @num_controls: number of elements in the array
2308 * Return 0 for success, else error.
2310 int snd_soc_add_card_controls(struct snd_soc_card
*soc_card
,
2311 const struct snd_kcontrol_new
*controls
, int num_controls
)
2313 struct snd_card
*card
= soc_card
->snd_card
;
2315 return snd_soc_add_controls(card
, soc_card
->dev
, controls
, num_controls
,
2318 EXPORT_SYMBOL_GPL(snd_soc_add_card_controls
);
2321 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2322 * Convienience function to add a list of controls.
2324 * @dai: DAI to add controls to
2325 * @controls: array of controls to add
2326 * @num_controls: number of elements in the array
2328 * Return 0 for success, else error.
2330 int snd_soc_add_dai_controls(struct snd_soc_dai
*dai
,
2331 const struct snd_kcontrol_new
*controls
, int num_controls
)
2333 struct snd_card
*card
= dai
->card
->snd_card
;
2335 return snd_soc_add_controls(card
, dai
->dev
, controls
, num_controls
,
2338 EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls
);
2341 * snd_soc_info_enum_double - enumerated double mixer info callback
2342 * @kcontrol: mixer control
2343 * @uinfo: control element information
2345 * Callback to provide information about a double enumerated
2348 * Returns 0 for success.
2350 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
2351 struct snd_ctl_elem_info
*uinfo
)
2353 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2355 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2356 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
2357 uinfo
->value
.enumerated
.items
= e
->items
;
2359 if (uinfo
->value
.enumerated
.item
>= e
->items
)
2360 uinfo
->value
.enumerated
.item
= e
->items
- 1;
2361 strlcpy(uinfo
->value
.enumerated
.name
,
2362 e
->texts
[uinfo
->value
.enumerated
.item
],
2363 sizeof(uinfo
->value
.enumerated
.name
));
2366 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
2369 * snd_soc_get_enum_double - enumerated double mixer get callback
2370 * @kcontrol: mixer control
2371 * @ucontrol: control element information
2373 * Callback to get the value of a double enumerated mixer.
2375 * Returns 0 for success.
2377 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
2378 struct snd_ctl_elem_value
*ucontrol
)
2380 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2381 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2382 unsigned int val
, item
;
2383 unsigned int reg_val
;
2386 ret
= snd_soc_component_read(component
, e
->reg
, ®_val
);
2389 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2390 item
= snd_soc_enum_val_to_item(e
, val
);
2391 ucontrol
->value
.enumerated
.item
[0] = item
;
2392 if (e
->shift_l
!= e
->shift_r
) {
2393 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
2394 item
= snd_soc_enum_val_to_item(e
, val
);
2395 ucontrol
->value
.enumerated
.item
[1] = item
;
2400 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
2403 * snd_soc_put_enum_double - enumerated double mixer put callback
2404 * @kcontrol: mixer control
2405 * @ucontrol: control element information
2407 * Callback to set the value of a double enumerated mixer.
2409 * Returns 0 for success.
2411 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
2412 struct snd_ctl_elem_value
*ucontrol
)
2414 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2415 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
2416 unsigned int *item
= ucontrol
->value
.enumerated
.item
;
2420 if (item
[0] >= e
->items
)
2422 val
= snd_soc_enum_item_to_val(e
, item
[0]) << e
->shift_l
;
2423 mask
= e
->mask
<< e
->shift_l
;
2424 if (e
->shift_l
!= e
->shift_r
) {
2425 if (item
[1] >= e
->items
)
2427 val
|= snd_soc_enum_item_to_val(e
, item
[1]) << e
->shift_r
;
2428 mask
|= e
->mask
<< e
->shift_r
;
2431 return snd_soc_component_update_bits(component
, e
->reg
, mask
, val
);
2433 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
2436 * snd_soc_read_signed - Read a codec register and interprete as signed value
2437 * @component: component
2438 * @reg: Register to read
2439 * @mask: Mask to use after shifting the register value
2440 * @shift: Right shift of register value
2441 * @sign_bit: Bit that describes if a number is negative or not.
2442 * @signed_val: Pointer to where the read value should be stored
2444 * This functions reads a codec register. The register value is shifted right
2445 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2446 * the given registervalue into a signed integer if sign_bit is non-zero.
2448 * Returns 0 on sucess, otherwise an error value
2450 static int snd_soc_read_signed(struct snd_soc_component
*component
,
2451 unsigned int reg
, unsigned int mask
, unsigned int shift
,
2452 unsigned int sign_bit
, int *signed_val
)
2457 ret
= snd_soc_component_read(component
, reg
, &val
);
2461 val
= (val
>> shift
) & mask
;
2468 /* non-negative number */
2469 if (!(val
& BIT(sign_bit
))) {
2477 * The register most probably does not contain a full-sized int.
2478 * Instead we have an arbitrary number of bits in a signed
2479 * representation which has to be translated into a full-sized int.
2480 * This is done by filling up all bits above the sign-bit.
2482 ret
|= ~((int)(BIT(sign_bit
) - 1));
2490 * snd_soc_info_volsw - single mixer info callback
2491 * @kcontrol: mixer control
2492 * @uinfo: control element information
2494 * Callback to provide information about a single mixer control, or a double
2495 * mixer control that spans 2 registers.
2497 * Returns 0 for success.
2499 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
2500 struct snd_ctl_elem_info
*uinfo
)
2502 struct soc_mixer_control
*mc
=
2503 (struct soc_mixer_control
*)kcontrol
->private_value
;
2506 if (!mc
->platform_max
)
2507 mc
->platform_max
= mc
->max
;
2508 platform_max
= mc
->platform_max
;
2510 if (platform_max
== 1 && !strstr(kcontrol
->id
.name
, " Volume"))
2511 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
2513 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2515 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2516 uinfo
->value
.integer
.min
= 0;
2517 uinfo
->value
.integer
.max
= platform_max
- mc
->min
;
2520 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
2523 * snd_soc_get_volsw - single mixer get callback
2524 * @kcontrol: mixer control
2525 * @ucontrol: control element information
2527 * Callback to get the value of a single mixer control, or a double mixer
2528 * control that spans 2 registers.
2530 * Returns 0 for success.
2532 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
2533 struct snd_ctl_elem_value
*ucontrol
)
2535 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2536 struct soc_mixer_control
*mc
=
2537 (struct soc_mixer_control
*)kcontrol
->private_value
;
2538 unsigned int reg
= mc
->reg
;
2539 unsigned int reg2
= mc
->rreg
;
2540 unsigned int shift
= mc
->shift
;
2541 unsigned int rshift
= mc
->rshift
;
2544 int sign_bit
= mc
->sign_bit
;
2545 unsigned int mask
= (1 << fls(max
)) - 1;
2546 unsigned int invert
= mc
->invert
;
2551 mask
= BIT(sign_bit
+ 1) - 1;
2553 ret
= snd_soc_read_signed(component
, reg
, mask
, shift
, sign_bit
, &val
);
2557 ucontrol
->value
.integer
.value
[0] = val
- min
;
2559 ucontrol
->value
.integer
.value
[0] =
2560 max
- ucontrol
->value
.integer
.value
[0];
2562 if (snd_soc_volsw_is_stereo(mc
)) {
2564 ret
= snd_soc_read_signed(component
, reg
, mask
, rshift
,
2567 ret
= snd_soc_read_signed(component
, reg2
, mask
, shift
,
2572 ucontrol
->value
.integer
.value
[1] = val
- min
;
2574 ucontrol
->value
.integer
.value
[1] =
2575 max
- ucontrol
->value
.integer
.value
[1];
2580 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
2583 * snd_soc_put_volsw - single mixer put callback
2584 * @kcontrol: mixer control
2585 * @ucontrol: control element information
2587 * Callback to set the value of a single mixer control, or a double mixer
2588 * control that spans 2 registers.
2590 * Returns 0 for success.
2592 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
2593 struct snd_ctl_elem_value
*ucontrol
)
2595 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2596 struct soc_mixer_control
*mc
=
2597 (struct soc_mixer_control
*)kcontrol
->private_value
;
2598 unsigned int reg
= mc
->reg
;
2599 unsigned int reg2
= mc
->rreg
;
2600 unsigned int shift
= mc
->shift
;
2601 unsigned int rshift
= mc
->rshift
;
2604 unsigned int sign_bit
= mc
->sign_bit
;
2605 unsigned int mask
= (1 << fls(max
)) - 1;
2606 unsigned int invert
= mc
->invert
;
2608 bool type_2r
= false;
2609 unsigned int val2
= 0;
2610 unsigned int val
, val_mask
;
2613 mask
= BIT(sign_bit
+ 1) - 1;
2615 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2618 val_mask
= mask
<< shift
;
2620 if (snd_soc_volsw_is_stereo(mc
)) {
2621 val2
= ((ucontrol
->value
.integer
.value
[1] + min
) & mask
);
2625 val_mask
|= mask
<< rshift
;
2626 val
|= val2
<< rshift
;
2628 val2
= val2
<< shift
;
2632 err
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2637 err
= snd_soc_component_update_bits(component
, reg2
, val_mask
,
2642 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
2645 * snd_soc_get_volsw_sx - single mixer get callback
2646 * @kcontrol: mixer control
2647 * @ucontrol: control element information
2649 * Callback to get the value of a single mixer control, or a double mixer
2650 * control that spans 2 registers.
2652 * Returns 0 for success.
2654 int snd_soc_get_volsw_sx(struct snd_kcontrol
*kcontrol
,
2655 struct snd_ctl_elem_value
*ucontrol
)
2657 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2658 struct soc_mixer_control
*mc
=
2659 (struct soc_mixer_control
*)kcontrol
->private_value
;
2660 unsigned int reg
= mc
->reg
;
2661 unsigned int reg2
= mc
->rreg
;
2662 unsigned int shift
= mc
->shift
;
2663 unsigned int rshift
= mc
->rshift
;
2666 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2670 ret
= snd_soc_component_read(component
, reg
, &val
);
2674 ucontrol
->value
.integer
.value
[0] = ((val
>> shift
) - min
) & mask
;
2676 if (snd_soc_volsw_is_stereo(mc
)) {
2677 ret
= snd_soc_component_read(component
, reg2
, &val
);
2681 val
= ((val
>> rshift
) - min
) & mask
;
2682 ucontrol
->value
.integer
.value
[1] = val
;
2687 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx
);
2690 * snd_soc_put_volsw_sx - double mixer set callback
2691 * @kcontrol: mixer control
2692 * @uinfo: control element information
2694 * Callback to set the value of a double mixer control that spans 2 registers.
2696 * Returns 0 for success.
2698 int snd_soc_put_volsw_sx(struct snd_kcontrol
*kcontrol
,
2699 struct snd_ctl_elem_value
*ucontrol
)
2701 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2702 struct soc_mixer_control
*mc
=
2703 (struct soc_mixer_control
*)kcontrol
->private_value
;
2705 unsigned int reg
= mc
->reg
;
2706 unsigned int reg2
= mc
->rreg
;
2707 unsigned int shift
= mc
->shift
;
2708 unsigned int rshift
= mc
->rshift
;
2711 int mask
= (1 << (fls(min
+ max
) - 1)) - 1;
2713 unsigned int val
, val_mask
, val2
= 0;
2715 val_mask
= mask
<< shift
;
2716 val
= (ucontrol
->value
.integer
.value
[0] + min
) & mask
;
2719 err
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2723 if (snd_soc_volsw_is_stereo(mc
)) {
2724 val_mask
= mask
<< rshift
;
2725 val2
= (ucontrol
->value
.integer
.value
[1] + min
) & mask
;
2726 val2
= val2
<< rshift
;
2728 err
= snd_soc_component_update_bits(component
, reg2
, val_mask
,
2733 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx
);
2736 * snd_soc_info_volsw_s8 - signed mixer info callback
2737 * @kcontrol: mixer control
2738 * @uinfo: control element information
2740 * Callback to provide information about a signed mixer control.
2742 * Returns 0 for success.
2744 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
2745 struct snd_ctl_elem_info
*uinfo
)
2747 struct soc_mixer_control
*mc
=
2748 (struct soc_mixer_control
*)kcontrol
->private_value
;
2752 if (!mc
->platform_max
)
2753 mc
->platform_max
= mc
->max
;
2754 platform_max
= mc
->platform_max
;
2756 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2758 uinfo
->value
.integer
.min
= 0;
2759 uinfo
->value
.integer
.max
= platform_max
- min
;
2762 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
2765 * snd_soc_get_volsw_s8 - signed mixer get callback
2766 * @kcontrol: mixer control
2767 * @ucontrol: control element information
2769 * Callback to get the value of a signed mixer control.
2771 * Returns 0 for success.
2773 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
2774 struct snd_ctl_elem_value
*ucontrol
)
2776 struct soc_mixer_control
*mc
=
2777 (struct soc_mixer_control
*)kcontrol
->private_value
;
2778 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2779 unsigned int reg
= mc
->reg
;
2784 ret
= snd_soc_component_read(component
, reg
, &val
);
2788 ucontrol
->value
.integer
.value
[0] =
2789 ((signed char)(val
& 0xff))-min
;
2790 ucontrol
->value
.integer
.value
[1] =
2791 ((signed char)((val
>> 8) & 0xff))-min
;
2794 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2797 * snd_soc_put_volsw_sgn - signed mixer put callback
2798 * @kcontrol: mixer control
2799 * @ucontrol: control element information
2801 * Callback to set the value of a signed mixer control.
2803 * Returns 0 for success.
2805 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2806 struct snd_ctl_elem_value
*ucontrol
)
2808 struct soc_mixer_control
*mc
=
2809 (struct soc_mixer_control
*)kcontrol
->private_value
;
2810 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2811 unsigned int reg
= mc
->reg
;
2815 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2816 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2818 return snd_soc_component_update_bits(component
, reg
, 0xffff, val
);
2820 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2823 * snd_soc_info_volsw_range - single mixer info callback with range.
2824 * @kcontrol: mixer control
2825 * @uinfo: control element information
2827 * Callback to provide information, within a range, about a single
2830 * returns 0 for success.
2832 int snd_soc_info_volsw_range(struct snd_kcontrol
*kcontrol
,
2833 struct snd_ctl_elem_info
*uinfo
)
2835 struct soc_mixer_control
*mc
=
2836 (struct soc_mixer_control
*)kcontrol
->private_value
;
2840 if (!mc
->platform_max
)
2841 mc
->platform_max
= mc
->max
;
2842 platform_max
= mc
->platform_max
;
2844 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2845 uinfo
->count
= snd_soc_volsw_is_stereo(mc
) ? 2 : 1;
2846 uinfo
->value
.integer
.min
= 0;
2847 uinfo
->value
.integer
.max
= platform_max
- min
;
2851 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range
);
2854 * snd_soc_put_volsw_range - single mixer put value callback with range.
2855 * @kcontrol: mixer control
2856 * @ucontrol: control element information
2858 * Callback to set the value, within a range, for a single mixer control.
2860 * Returns 0 for success.
2862 int snd_soc_put_volsw_range(struct snd_kcontrol
*kcontrol
,
2863 struct snd_ctl_elem_value
*ucontrol
)
2865 struct soc_mixer_control
*mc
=
2866 (struct soc_mixer_control
*)kcontrol
->private_value
;
2867 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2868 unsigned int reg
= mc
->reg
;
2869 unsigned int rreg
= mc
->rreg
;
2870 unsigned int shift
= mc
->shift
;
2873 unsigned int mask
= (1 << fls(max
)) - 1;
2874 unsigned int invert
= mc
->invert
;
2875 unsigned int val
, val_mask
;
2879 val
= (max
- ucontrol
->value
.integer
.value
[0]) & mask
;
2881 val
= ((ucontrol
->value
.integer
.value
[0] + min
) & mask
);
2882 val_mask
= mask
<< shift
;
2885 ret
= snd_soc_component_update_bits(component
, reg
, val_mask
, val
);
2889 if (snd_soc_volsw_is_stereo(mc
)) {
2891 val
= (max
- ucontrol
->value
.integer
.value
[1]) & mask
;
2893 val
= ((ucontrol
->value
.integer
.value
[1] + min
) & mask
);
2894 val_mask
= mask
<< shift
;
2897 ret
= snd_soc_component_update_bits(component
, rreg
, val_mask
,
2903 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range
);
2906 * snd_soc_get_volsw_range - single mixer get callback with range
2907 * @kcontrol: mixer control
2908 * @ucontrol: control element information
2910 * Callback to get the value, within a range, of a single mixer control.
2912 * Returns 0 for success.
2914 int snd_soc_get_volsw_range(struct snd_kcontrol
*kcontrol
,
2915 struct snd_ctl_elem_value
*ucontrol
)
2917 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
2918 struct soc_mixer_control
*mc
=
2919 (struct soc_mixer_control
*)kcontrol
->private_value
;
2920 unsigned int reg
= mc
->reg
;
2921 unsigned int rreg
= mc
->rreg
;
2922 unsigned int shift
= mc
->shift
;
2925 unsigned int mask
= (1 << fls(max
)) - 1;
2926 unsigned int invert
= mc
->invert
;
2930 ret
= snd_soc_component_read(component
, reg
, &val
);
2934 ucontrol
->value
.integer
.value
[0] = (val
>> shift
) & mask
;
2936 ucontrol
->value
.integer
.value
[0] =
2937 max
- ucontrol
->value
.integer
.value
[0];
2939 ucontrol
->value
.integer
.value
[0] =
2940 ucontrol
->value
.integer
.value
[0] - min
;
2942 if (snd_soc_volsw_is_stereo(mc
)) {
2943 ret
= snd_soc_component_read(component
, rreg
, &val
);
2947 ucontrol
->value
.integer
.value
[1] = (val
>> shift
) & mask
;
2949 ucontrol
->value
.integer
.value
[1] =
2950 max
- ucontrol
->value
.integer
.value
[1];
2952 ucontrol
->value
.integer
.value
[1] =
2953 ucontrol
->value
.integer
.value
[1] - min
;
2958 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range
);
2961 * snd_soc_limit_volume - Set new limit to an existing volume control.
2963 * @codec: where to look for the control
2964 * @name: Name of the control
2965 * @max: new maximum limit
2967 * Return 0 for success, else error.
2969 int snd_soc_limit_volume(struct snd_soc_codec
*codec
,
2970 const char *name
, int max
)
2972 struct snd_card
*card
= codec
->component
.card
->snd_card
;
2973 struct snd_kcontrol
*kctl
;
2974 struct soc_mixer_control
*mc
;
2978 /* Sanity check for name and max */
2979 if (unlikely(!name
|| max
<= 0))
2982 list_for_each_entry(kctl
, &card
->controls
, list
) {
2983 if (!strncmp(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
))) {
2989 mc
= (struct soc_mixer_control
*)kctl
->private_value
;
2990 if (max
<= mc
->max
) {
2991 mc
->platform_max
= max
;
2997 EXPORT_SYMBOL_GPL(snd_soc_limit_volume
);
2999 int snd_soc_bytes_info(struct snd_kcontrol
*kcontrol
,
3000 struct snd_ctl_elem_info
*uinfo
)
3002 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3003 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3005 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3006 uinfo
->count
= params
->num_regs
* component
->val_bytes
;
3010 EXPORT_SYMBOL_GPL(snd_soc_bytes_info
);
3012 int snd_soc_bytes_get(struct snd_kcontrol
*kcontrol
,
3013 struct snd_ctl_elem_value
*ucontrol
)
3015 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3016 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3019 if (component
->regmap
)
3020 ret
= regmap_raw_read(component
->regmap
, params
->base
,
3021 ucontrol
->value
.bytes
.data
,
3022 params
->num_regs
* component
->val_bytes
);
3026 /* Hide any masked bytes to ensure consistent data reporting */
3027 if (ret
== 0 && params
->mask
) {
3028 switch (component
->val_bytes
) {
3030 ucontrol
->value
.bytes
.data
[0] &= ~params
->mask
;
3033 ((u16
*)(&ucontrol
->value
.bytes
.data
))[0]
3034 &= cpu_to_be16(~params
->mask
);
3037 ((u32
*)(&ucontrol
->value
.bytes
.data
))[0]
3038 &= cpu_to_be32(~params
->mask
);
3047 EXPORT_SYMBOL_GPL(snd_soc_bytes_get
);
3049 int snd_soc_bytes_put(struct snd_kcontrol
*kcontrol
,
3050 struct snd_ctl_elem_value
*ucontrol
)
3052 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3053 struct soc_bytes
*params
= (void *)kcontrol
->private_value
;
3055 unsigned int val
, mask
;
3058 if (!component
->regmap
|| !params
->num_regs
)
3061 len
= params
->num_regs
* component
->val_bytes
;
3063 data
= kmemdup(ucontrol
->value
.bytes
.data
, len
, GFP_KERNEL
| GFP_DMA
);
3068 * If we've got a mask then we need to preserve the register
3069 * bits. We shouldn't modify the incoming data so take a
3073 ret
= regmap_read(component
->regmap
, params
->base
, &val
);
3077 val
&= params
->mask
;
3079 switch (component
->val_bytes
) {
3081 ((u8
*)data
)[0] &= ~params
->mask
;
3082 ((u8
*)data
)[0] |= val
;
3085 mask
= ~params
->mask
;
3086 ret
= regmap_parse_val(component
->regmap
,
3091 ((u16
*)data
)[0] &= mask
;
3093 ret
= regmap_parse_val(component
->regmap
,
3098 ((u16
*)data
)[0] |= val
;
3101 mask
= ~params
->mask
;
3102 ret
= regmap_parse_val(component
->regmap
,
3107 ((u32
*)data
)[0] &= mask
;
3109 ret
= regmap_parse_val(component
->regmap
,
3114 ((u32
*)data
)[0] |= val
;
3122 ret
= regmap_raw_write(component
->regmap
, params
->base
,
3130 EXPORT_SYMBOL_GPL(snd_soc_bytes_put
);
3132 int snd_soc_bytes_info_ext(struct snd_kcontrol
*kcontrol
,
3133 struct snd_ctl_elem_info
*ucontrol
)
3135 struct soc_bytes_ext
*params
= (void *)kcontrol
->private_value
;
3137 ucontrol
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
3138 ucontrol
->count
= params
->max
;
3142 EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext
);
3144 int snd_soc_bytes_tlv_callback(struct snd_kcontrol
*kcontrol
, int op_flag
,
3145 unsigned int size
, unsigned int __user
*tlv
)
3147 struct soc_bytes_ext
*params
= (void *)kcontrol
->private_value
;
3148 unsigned int count
= size
< params
->max
? size
: params
->max
;
3152 case SNDRV_CTL_TLV_OP_READ
:
3154 ret
= params
->get(tlv
, count
);
3156 case SNDRV_CTL_TLV_OP_WRITE
:
3158 ret
= params
->put(tlv
, count
);
3163 EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback
);
3166 * snd_soc_info_xr_sx - signed multi register info callback
3167 * @kcontrol: mreg control
3168 * @uinfo: control element information
3170 * Callback to provide information of a control that can
3171 * span multiple codec registers which together
3172 * forms a single signed value in a MSB/LSB manner.
3174 * Returns 0 for success.
3176 int snd_soc_info_xr_sx(struct snd_kcontrol
*kcontrol
,
3177 struct snd_ctl_elem_info
*uinfo
)
3179 struct soc_mreg_control
*mc
=
3180 (struct soc_mreg_control
*)kcontrol
->private_value
;
3181 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3183 uinfo
->value
.integer
.min
= mc
->min
;
3184 uinfo
->value
.integer
.max
= mc
->max
;
3188 EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx
);
3191 * snd_soc_get_xr_sx - signed multi register get callback
3192 * @kcontrol: mreg control
3193 * @ucontrol: control element information
3195 * Callback to get the value of a control that can span
3196 * multiple codec registers which together forms a single
3197 * signed value in a MSB/LSB manner. The control supports
3198 * specifying total no of bits used to allow for bitfields
3199 * across the multiple codec registers.
3201 * Returns 0 for success.
3203 int snd_soc_get_xr_sx(struct snd_kcontrol
*kcontrol
,
3204 struct snd_ctl_elem_value
*ucontrol
)
3206 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3207 struct soc_mreg_control
*mc
=
3208 (struct soc_mreg_control
*)kcontrol
->private_value
;
3209 unsigned int regbase
= mc
->regbase
;
3210 unsigned int regcount
= mc
->regcount
;
3211 unsigned int regwshift
= component
->val_bytes
* BITS_PER_BYTE
;
3212 unsigned int regwmask
= (1<<regwshift
)-1;
3213 unsigned int invert
= mc
->invert
;
3214 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3218 unsigned int regval
;
3222 for (i
= 0; i
< regcount
; i
++) {
3223 ret
= snd_soc_component_read(component
, regbase
+i
, ®val
);
3226 val
|= (regval
& regwmask
) << (regwshift
*(regcount
-i
-1));
3229 if (min
< 0 && val
> max
)
3233 ucontrol
->value
.integer
.value
[0] = val
;
3237 EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx
);
3240 * snd_soc_put_xr_sx - signed multi register get callback
3241 * @kcontrol: mreg control
3242 * @ucontrol: control element information
3244 * Callback to set the value of a control that can span
3245 * multiple codec registers which together forms a single
3246 * signed value in a MSB/LSB manner. The control supports
3247 * specifying total no of bits used to allow for bitfields
3248 * across the multiple codec registers.
3250 * Returns 0 for success.
3252 int snd_soc_put_xr_sx(struct snd_kcontrol
*kcontrol
,
3253 struct snd_ctl_elem_value
*ucontrol
)
3255 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3256 struct soc_mreg_control
*mc
=
3257 (struct soc_mreg_control
*)kcontrol
->private_value
;
3258 unsigned int regbase
= mc
->regbase
;
3259 unsigned int regcount
= mc
->regcount
;
3260 unsigned int regwshift
= component
->val_bytes
* BITS_PER_BYTE
;
3261 unsigned int regwmask
= (1<<regwshift
)-1;
3262 unsigned int invert
= mc
->invert
;
3263 unsigned long mask
= (1UL<<mc
->nbits
)-1;
3265 long val
= ucontrol
->value
.integer
.value
[0];
3266 unsigned int i
, regval
, regmask
;
3272 for (i
= 0; i
< regcount
; i
++) {
3273 regval
= (val
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3274 regmask
= (mask
>> (regwshift
*(regcount
-i
-1))) & regwmask
;
3275 err
= snd_soc_component_update_bits(component
, regbase
+i
,
3283 EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx
);
3286 * snd_soc_get_strobe - strobe get callback
3287 * @kcontrol: mixer control
3288 * @ucontrol: control element information
3290 * Callback get the value of a strobe mixer control.
3292 * Returns 0 for success.
3294 int snd_soc_get_strobe(struct snd_kcontrol
*kcontrol
,
3295 struct snd_ctl_elem_value
*ucontrol
)
3297 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3298 struct soc_mixer_control
*mc
=
3299 (struct soc_mixer_control
*)kcontrol
->private_value
;
3300 unsigned int reg
= mc
->reg
;
3301 unsigned int shift
= mc
->shift
;
3302 unsigned int mask
= 1 << shift
;
3303 unsigned int invert
= mc
->invert
!= 0;
3307 ret
= snd_soc_component_read(component
, reg
, &val
);
3313 if (shift
!= 0 && val
!= 0)
3315 ucontrol
->value
.enumerated
.item
[0] = val
^ invert
;
3319 EXPORT_SYMBOL_GPL(snd_soc_get_strobe
);
3322 * snd_soc_put_strobe - strobe put callback
3323 * @kcontrol: mixer control
3324 * @ucontrol: control element information
3326 * Callback strobe a register bit to high then low (or the inverse)
3327 * in one pass of a single mixer enum control.
3329 * Returns 1 for success.
3331 int snd_soc_put_strobe(struct snd_kcontrol
*kcontrol
,
3332 struct snd_ctl_elem_value
*ucontrol
)
3334 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
3335 struct soc_mixer_control
*mc
=
3336 (struct soc_mixer_control
*)kcontrol
->private_value
;
3337 unsigned int reg
= mc
->reg
;
3338 unsigned int shift
= mc
->shift
;
3339 unsigned int mask
= 1 << shift
;
3340 unsigned int invert
= mc
->invert
!= 0;
3341 unsigned int strobe
= ucontrol
->value
.enumerated
.item
[0] != 0;
3342 unsigned int val1
= (strobe
^ invert
) ? mask
: 0;
3343 unsigned int val2
= (strobe
^ invert
) ? 0 : mask
;
3346 err
= snd_soc_component_update_bits(component
, reg
, mask
, val1
);
3350 return snd_soc_component_update_bits(component
, reg
, mask
, val2
);
3352 EXPORT_SYMBOL_GPL(snd_soc_put_strobe
);
3355 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3357 * @clk_id: DAI specific clock ID
3358 * @freq: new clock frequency in Hz
3359 * @dir: new clock direction - input/output.
3361 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3363 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
3364 unsigned int freq
, int dir
)
3366 if (dai
->driver
&& dai
->driver
->ops
->set_sysclk
)
3367 return dai
->driver
->ops
->set_sysclk(dai
, clk_id
, freq
, dir
);
3368 else if (dai
->codec
&& dai
->codec
->driver
->set_sysclk
)
3369 return dai
->codec
->driver
->set_sysclk(dai
->codec
, clk_id
, 0,
3374 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
3377 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3379 * @clk_id: DAI specific clock ID
3380 * @source: Source for the clock
3381 * @freq: new clock frequency in Hz
3382 * @dir: new clock direction - input/output.
3384 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3386 int snd_soc_codec_set_sysclk(struct snd_soc_codec
*codec
, int clk_id
,
3387 int source
, unsigned int freq
, int dir
)
3389 if (codec
->driver
->set_sysclk
)
3390 return codec
->driver
->set_sysclk(codec
, clk_id
, source
,
3395 EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk
);
3398 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3400 * @div_id: DAI specific clock divider ID
3401 * @div: new clock divisor.
3403 * Configures the clock dividers. This is used to derive the best DAI bit and
3404 * frame clocks from the system or master clock. It's best to set the DAI bit
3405 * and frame clocks as low as possible to save system power.
3407 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
3408 int div_id
, int div
)
3410 if (dai
->driver
&& dai
->driver
->ops
->set_clkdiv
)
3411 return dai
->driver
->ops
->set_clkdiv(dai
, div_id
, div
);
3415 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
3418 * snd_soc_dai_set_pll - configure DAI PLL.
3420 * @pll_id: DAI specific PLL ID
3421 * @source: DAI specific source for the PLL
3422 * @freq_in: PLL input clock frequency in Hz
3423 * @freq_out: requested PLL output clock frequency in Hz
3425 * Configures and enables PLL to generate output clock based on input clock.
3427 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
3428 unsigned int freq_in
, unsigned int freq_out
)
3430 if (dai
->driver
&& dai
->driver
->ops
->set_pll
)
3431 return dai
->driver
->ops
->set_pll(dai
, pll_id
, source
,
3433 else if (dai
->codec
&& dai
->codec
->driver
->set_pll
)
3434 return dai
->codec
->driver
->set_pll(dai
->codec
, pll_id
, source
,
3439 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
3442 * snd_soc_codec_set_pll - configure codec PLL.
3444 * @pll_id: DAI specific PLL ID
3445 * @source: DAI specific source for the PLL
3446 * @freq_in: PLL input clock frequency in Hz
3447 * @freq_out: requested PLL output clock frequency in Hz
3449 * Configures and enables PLL to generate output clock based on input clock.
3451 int snd_soc_codec_set_pll(struct snd_soc_codec
*codec
, int pll_id
, int source
,
3452 unsigned int freq_in
, unsigned int freq_out
)
3454 if (codec
->driver
->set_pll
)
3455 return codec
->driver
->set_pll(codec
, pll_id
, source
,
3460 EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll
);
3463 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
3465 * @ratio Ratio of BCLK to Sample rate.
3467 * Configures the DAI for a preset BCLK to sample rate ratio.
3469 int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai
*dai
, unsigned int ratio
)
3471 if (dai
->driver
&& dai
->driver
->ops
->set_bclk_ratio
)
3472 return dai
->driver
->ops
->set_bclk_ratio(dai
, ratio
);
3476 EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio
);
3479 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3481 * @fmt: SND_SOC_DAIFMT_ format value.
3483 * Configures the DAI hardware format and clocking.
3485 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
3487 if (dai
->driver
== NULL
)
3489 if (dai
->driver
->ops
->set_fmt
== NULL
)
3491 return dai
->driver
->ops
->set_fmt(dai
, fmt
);
3493 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
3496 * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
3497 * @slots: Number of slots in use.
3498 * @tx_mask: bitmask representing active TX slots.
3499 * @rx_mask: bitmask representing active RX slots.
3501 * Generates the TDM tx and rx slot default masks for DAI.
3503 static int snd_soc_xlate_tdm_slot_mask(unsigned int slots
,
3504 unsigned int *tx_mask
,
3505 unsigned int *rx_mask
)
3507 if (*tx_mask
|| *rx_mask
)
3513 *tx_mask
= (1 << slots
) - 1;
3514 *rx_mask
= (1 << slots
) - 1;
3520 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3522 * @tx_mask: bitmask representing active TX slots.
3523 * @rx_mask: bitmask representing active RX slots.
3524 * @slots: Number of slots in use.
3525 * @slot_width: Width in bits for each slot.
3527 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3530 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
3531 unsigned int tx_mask
, unsigned int rx_mask
, int slots
, int slot_width
)
3533 if (dai
->driver
&& dai
->driver
->ops
->xlate_tdm_slot_mask
)
3534 dai
->driver
->ops
->xlate_tdm_slot_mask(slots
,
3535 &tx_mask
, &rx_mask
);
3537 snd_soc_xlate_tdm_slot_mask(slots
, &tx_mask
, &rx_mask
);
3539 dai
->tx_mask
= tx_mask
;
3540 dai
->rx_mask
= rx_mask
;
3542 if (dai
->driver
&& dai
->driver
->ops
->set_tdm_slot
)
3543 return dai
->driver
->ops
->set_tdm_slot(dai
, tx_mask
, rx_mask
,
3548 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
3551 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3553 * @tx_num: how many TX channels
3554 * @tx_slot: pointer to an array which imply the TX slot number channel
3556 * @rx_num: how many RX channels
3557 * @rx_slot: pointer to an array which imply the RX slot number channel
3560 * configure the relationship between channel number and TDM slot number.
3562 int snd_soc_dai_set_channel_map(struct snd_soc_dai
*dai
,
3563 unsigned int tx_num
, unsigned int *tx_slot
,
3564 unsigned int rx_num
, unsigned int *rx_slot
)
3566 if (dai
->driver
&& dai
->driver
->ops
->set_channel_map
)
3567 return dai
->driver
->ops
->set_channel_map(dai
, tx_num
, tx_slot
,
3572 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map
);
3575 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3577 * @tristate: tristate enable
3579 * Tristates the DAI so that others can use it.
3581 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
3583 if (dai
->driver
&& dai
->driver
->ops
->set_tristate
)
3584 return dai
->driver
->ops
->set_tristate(dai
, tristate
);
3588 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
3591 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3593 * @mute: mute enable
3594 * @direction: stream to mute
3596 * Mutes the DAI DAC.
3598 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
,
3604 if (dai
->driver
->ops
->mute_stream
)
3605 return dai
->driver
->ops
->mute_stream(dai
, mute
, direction
);
3606 else if (direction
== SNDRV_PCM_STREAM_PLAYBACK
&&
3607 dai
->driver
->ops
->digital_mute
)
3608 return dai
->driver
->ops
->digital_mute(dai
, mute
);
3612 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
3614 static int snd_soc_init_multicodec(struct snd_soc_card
*card
,
3615 struct snd_soc_dai_link
*dai_link
)
3617 /* Legacy codec/codec_dai link is a single entry in multicodec */
3618 if (dai_link
->codec_name
|| dai_link
->codec_of_node
||
3619 dai_link
->codec_dai_name
) {
3620 dai_link
->num_codecs
= 1;
3622 dai_link
->codecs
= devm_kzalloc(card
->dev
,
3623 sizeof(struct snd_soc_dai_link_component
),
3625 if (!dai_link
->codecs
)
3628 dai_link
->codecs
[0].name
= dai_link
->codec_name
;
3629 dai_link
->codecs
[0].of_node
= dai_link
->codec_of_node
;
3630 dai_link
->codecs
[0].dai_name
= dai_link
->codec_dai_name
;
3633 if (!dai_link
->codecs
) {
3634 dev_err(card
->dev
, "ASoC: DAI link has no CODECs\n");
3642 * snd_soc_register_card - Register a card with the ASoC core
3644 * @card: Card to register
3647 int snd_soc_register_card(struct snd_soc_card
*card
)
3651 if (!card
->name
|| !card
->dev
)
3654 for (i
= 0; i
< card
->num_links
; i
++) {
3655 struct snd_soc_dai_link
*link
= &card
->dai_link
[i
];
3657 ret
= snd_soc_init_multicodec(card
, link
);
3659 dev_err(card
->dev
, "ASoC: failed to init multicodec\n");
3663 for (j
= 0; j
< link
->num_codecs
; j
++) {
3665 * Codec must be specified by 1 of name or OF node,
3666 * not both or neither.
3668 if (!!link
->codecs
[j
].name
==
3669 !!link
->codecs
[j
].of_node
) {
3670 dev_err(card
->dev
, "ASoC: Neither/both codec name/of_node are set for %s\n",
3674 /* Codec DAI name must be specified */
3675 if (!link
->codecs
[j
].dai_name
) {
3676 dev_err(card
->dev
, "ASoC: codec_dai_name not set for %s\n",
3683 * Platform may be specified by either name or OF node, but
3684 * can be left unspecified, and a dummy platform will be used.
3686 if (link
->platform_name
&& link
->platform_of_node
) {
3688 "ASoC: Both platform name/of_node are set for %s\n",
3694 * CPU device may be specified by either name or OF node, but
3695 * can be left unspecified, and will be matched based on DAI
3698 if (link
->cpu_name
&& link
->cpu_of_node
) {
3700 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3705 * At least one of CPU DAI name or CPU device name/node must be
3708 if (!link
->cpu_dai_name
&&
3709 !(link
->cpu_name
|| link
->cpu_of_node
)) {
3711 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3717 dev_set_drvdata(card
->dev
, card
);
3719 snd_soc_initialize_card_lists(card
);
3721 soc_init_card_debugfs(card
);
3723 card
->rtd
= devm_kzalloc(card
->dev
,
3724 sizeof(struct snd_soc_pcm_runtime
) *
3725 (card
->num_links
+ card
->num_aux_devs
),
3727 if (card
->rtd
== NULL
)
3730 card
->rtd_aux
= &card
->rtd
[card
->num_links
];
3732 for (i
= 0; i
< card
->num_links
; i
++) {
3733 card
->rtd
[i
].card
= card
;
3734 card
->rtd
[i
].dai_link
= &card
->dai_link
[i
];
3735 card
->rtd
[i
].codec_dais
= devm_kzalloc(card
->dev
,
3736 sizeof(struct snd_soc_dai
*) *
3737 (card
->rtd
[i
].dai_link
->num_codecs
),
3739 if (card
->rtd
[i
].codec_dais
== NULL
)
3743 for (i
= 0; i
< card
->num_aux_devs
; i
++)
3744 card
->rtd_aux
[i
].card
= card
;
3746 INIT_LIST_HEAD(&card
->dapm_dirty
);
3747 card
->instantiated
= 0;
3748 mutex_init(&card
->mutex
);
3749 mutex_init(&card
->dapm_mutex
);
3751 ret
= snd_soc_instantiate_card(card
);
3753 soc_cleanup_card_debugfs(card
);
3755 /* deactivate pins to sleep state */
3756 for (i
= 0; i
< card
->num_rtd
; i
++) {
3757 struct snd_soc_pcm_runtime
*rtd
= &card
->rtd
[i
];
3758 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
3761 for (j
= 0; j
< rtd
->num_codecs
; j
++) {
3762 struct snd_soc_dai
*codec_dai
= rtd
->codec_dais
[j
];
3763 if (!codec_dai
->active
)
3764 pinctrl_pm_select_sleep_state(codec_dai
->dev
);
3767 if (!cpu_dai
->active
)
3768 pinctrl_pm_select_sleep_state(cpu_dai
->dev
);
3773 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
3776 * snd_soc_unregister_card - Unregister a card with the ASoC core
3778 * @card: Card to unregister
3781 int snd_soc_unregister_card(struct snd_soc_card
*card
)
3783 if (card
->instantiated
) {
3784 card
->instantiated
= false;
3785 snd_soc_dapm_shutdown(card
);
3786 soc_cleanup_card_resources(card
);
3788 dev_dbg(card
->dev
, "ASoC: Unregistered card '%s'\n", card
->name
);
3792 EXPORT_SYMBOL_GPL(snd_soc_unregister_card
);
3795 * Simplify DAI link configuration by removing ".-1" from device names
3796 * and sanitizing names.
3798 static char *fmt_single_name(struct device
*dev
, int *id
)
3800 char *found
, name
[NAME_SIZE
];
3803 if (dev_name(dev
) == NULL
)
3806 strlcpy(name
, dev_name(dev
), NAME_SIZE
);
3808 /* are we a "%s.%d" name (platform and SPI components) */
3809 found
= strstr(name
, dev
->driver
->name
);
3812 if (sscanf(&found
[strlen(dev
->driver
->name
)], ".%d", id
) == 1) {
3814 /* discard ID from name if ID == -1 */
3816 found
[strlen(dev
->driver
->name
)] = '\0';
3820 /* I2C component devices are named "bus-addr" */
3821 if (sscanf(name
, "%x-%x", &id1
, &id2
) == 2) {
3822 char tmp
[NAME_SIZE
];
3824 /* create unique ID number from I2C addr and bus */
3825 *id
= ((id1
& 0xffff) << 16) + id2
;
3827 /* sanitize component name for DAI link creation */
3828 snprintf(tmp
, NAME_SIZE
, "%s.%s", dev
->driver
->name
, name
);
3829 strlcpy(name
, tmp
, NAME_SIZE
);
3834 return kstrdup(name
, GFP_KERNEL
);
3838 * Simplify DAI link naming for single devices with multiple DAIs by removing
3839 * any ".-1" and using the DAI name (instead of device name).
3841 static inline char *fmt_multiple_name(struct device
*dev
,
3842 struct snd_soc_dai_driver
*dai_drv
)
3844 if (dai_drv
->name
== NULL
) {
3846 "ASoC: error - multiple DAI %s registered with no name\n",
3851 return kstrdup(dai_drv
->name
, GFP_KERNEL
);
3855 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
3857 * @component: The component for which the DAIs should be unregistered
3859 static void snd_soc_unregister_dais(struct snd_soc_component
*component
)
3861 struct snd_soc_dai
*dai
, *_dai
;
3863 list_for_each_entry_safe(dai
, _dai
, &component
->dai_list
, list
) {
3864 dev_dbg(component
->dev
, "ASoC: Unregistered DAI '%s'\n",
3866 list_del(&dai
->list
);
3873 * snd_soc_register_dais - Register a DAI with the ASoC core
3875 * @component: The component the DAIs are registered for
3876 * @dai_drv: DAI driver to use for the DAIs
3877 * @count: Number of DAIs
3878 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3881 static int snd_soc_register_dais(struct snd_soc_component
*component
,
3882 struct snd_soc_dai_driver
*dai_drv
, size_t count
,
3883 bool legacy_dai_naming
)
3885 struct device
*dev
= component
->dev
;
3886 struct snd_soc_dai
*dai
;
3890 dev_dbg(dev
, "ASoC: dai register %s #%Zu\n", dev_name(dev
), count
);
3892 component
->dai_drv
= dai_drv
;
3893 component
->num_dai
= count
;
3895 for (i
= 0; i
< count
; i
++) {
3897 dai
= kzalloc(sizeof(struct snd_soc_dai
), GFP_KERNEL
);
3904 * Back in the old days when we still had component-less DAIs,
3905 * instead of having a static name, component-less DAIs would
3906 * inherit the name of the parent device so it is possible to
3907 * register multiple instances of the DAI. We still need to keep
3908 * the same naming style even though those DAIs are not
3909 * component-less anymore.
3911 if (count
== 1 && legacy_dai_naming
) {
3912 dai
->name
= fmt_single_name(dev
, &dai
->id
);
3914 dai
->name
= fmt_multiple_name(dev
, &dai_drv
[i
]);
3916 dai
->id
= dai_drv
[i
].id
;
3920 if (dai
->name
== NULL
) {
3926 dai
->component
= component
;
3928 dai
->driver
= &dai_drv
[i
];
3929 if (!dai
->driver
->ops
)
3930 dai
->driver
->ops
= &null_dai_ops
;
3932 list_add(&dai
->list
, &component
->dai_list
);
3934 dev_dbg(dev
, "ASoC: Registered DAI '%s'\n", dai
->name
);
3940 snd_soc_unregister_dais(component
);
3945 static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context
*dapm
,
3946 enum snd_soc_dapm_type type
, int subseq
)
3948 struct snd_soc_component
*component
= dapm
->component
;
3950 component
->driver
->seq_notifier(component
, type
, subseq
);
3953 static int snd_soc_component_stream_event(struct snd_soc_dapm_context
*dapm
,
3956 struct snd_soc_component
*component
= dapm
->component
;
3958 return component
->driver
->stream_event(component
, event
);
3961 static int snd_soc_component_initialize(struct snd_soc_component
*component
,
3962 const struct snd_soc_component_driver
*driver
, struct device
*dev
)
3964 struct snd_soc_dapm_context
*dapm
;
3966 component
->name
= fmt_single_name(dev
, &component
->id
);
3967 if (!component
->name
) {
3968 dev_err(dev
, "ASoC: Failed to allocate name\n");
3972 component
->dev
= dev
;
3973 component
->driver
= driver
;
3974 component
->probe
= component
->driver
->probe
;
3975 component
->remove
= component
->driver
->remove
;
3977 if (!component
->dapm_ptr
)
3978 component
->dapm_ptr
= &component
->dapm
;
3980 dapm
= component
->dapm_ptr
;
3982 dapm
->component
= component
;
3983 dapm
->bias_level
= SND_SOC_BIAS_OFF
;
3984 dapm
->idle_bias_off
= true;
3985 if (driver
->seq_notifier
)
3986 dapm
->seq_notifier
= snd_soc_component_seq_notifier
;
3987 if (driver
->stream_event
)
3988 dapm
->stream_event
= snd_soc_component_stream_event
;
3990 component
->controls
= driver
->controls
;
3991 component
->num_controls
= driver
->num_controls
;
3992 component
->dapm_widgets
= driver
->dapm_widgets
;
3993 component
->num_dapm_widgets
= driver
->num_dapm_widgets
;
3994 component
->dapm_routes
= driver
->dapm_routes
;
3995 component
->num_dapm_routes
= driver
->num_dapm_routes
;
3997 INIT_LIST_HEAD(&component
->dai_list
);
3998 mutex_init(&component
->io_mutex
);
4003 static void snd_soc_component_init_regmap(struct snd_soc_component
*component
)
4005 if (!component
->regmap
)
4006 component
->regmap
= dev_get_regmap(component
->dev
, NULL
);
4007 if (component
->regmap
) {
4008 int val_bytes
= regmap_get_val_bytes(component
->regmap
);
4009 /* Errors are legitimate for non-integer byte multiples */
4011 component
->val_bytes
= val_bytes
;
4015 static void snd_soc_component_add_unlocked(struct snd_soc_component
*component
)
4017 if (!component
->write
&& !component
->read
)
4018 snd_soc_component_init_regmap(component
);
4020 list_add(&component
->list
, &component_list
);
4023 static void snd_soc_component_add(struct snd_soc_component
*component
)
4025 mutex_lock(&client_mutex
);
4026 snd_soc_component_add_unlocked(component
);
4027 mutex_unlock(&client_mutex
);
4030 static void snd_soc_component_cleanup(struct snd_soc_component
*component
)
4032 snd_soc_unregister_dais(component
);
4033 kfree(component
->name
);
4036 static void snd_soc_component_del_unlocked(struct snd_soc_component
*component
)
4038 list_del(&component
->list
);
4041 static void snd_soc_component_del(struct snd_soc_component
*component
)
4043 mutex_lock(&client_mutex
);
4044 snd_soc_component_del_unlocked(component
);
4045 mutex_unlock(&client_mutex
);
4048 int snd_soc_register_component(struct device
*dev
,
4049 const struct snd_soc_component_driver
*cmpnt_drv
,
4050 struct snd_soc_dai_driver
*dai_drv
,
4053 struct snd_soc_component
*cmpnt
;
4056 cmpnt
= kzalloc(sizeof(*cmpnt
), GFP_KERNEL
);
4058 dev_err(dev
, "ASoC: Failed to allocate memory\n");
4062 ret
= snd_soc_component_initialize(cmpnt
, cmpnt_drv
, dev
);
4066 cmpnt
->ignore_pmdown_time
= true;
4067 cmpnt
->registered_as_component
= true;
4069 ret
= snd_soc_register_dais(cmpnt
, dai_drv
, num_dai
, true);
4071 dev_err(dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4075 snd_soc_component_add(cmpnt
);
4080 snd_soc_component_cleanup(cmpnt
);
4085 EXPORT_SYMBOL_GPL(snd_soc_register_component
);
4088 * snd_soc_unregister_component - Unregister a component from the ASoC core
4091 void snd_soc_unregister_component(struct device
*dev
)
4093 struct snd_soc_component
*cmpnt
;
4095 list_for_each_entry(cmpnt
, &component_list
, list
) {
4096 if (dev
== cmpnt
->dev
&& cmpnt
->registered_as_component
)
4102 snd_soc_component_del(cmpnt
);
4103 snd_soc_component_cleanup(cmpnt
);
4106 EXPORT_SYMBOL_GPL(snd_soc_unregister_component
);
4108 static int snd_soc_platform_drv_probe(struct snd_soc_component
*component
)
4110 struct snd_soc_platform
*platform
= snd_soc_component_to_platform(component
);
4112 return platform
->driver
->probe(platform
);
4115 static void snd_soc_platform_drv_remove(struct snd_soc_component
*component
)
4117 struct snd_soc_platform
*platform
= snd_soc_component_to_platform(component
);
4119 platform
->driver
->remove(platform
);
4123 * snd_soc_add_platform - Add a platform to the ASoC core
4124 * @dev: The parent device for the platform
4125 * @platform: The platform to add
4126 * @platform_driver: The driver for the platform
4128 int snd_soc_add_platform(struct device
*dev
, struct snd_soc_platform
*platform
,
4129 const struct snd_soc_platform_driver
*platform_drv
)
4133 ret
= snd_soc_component_initialize(&platform
->component
,
4134 &platform_drv
->component_driver
, dev
);
4138 platform
->dev
= dev
;
4139 platform
->driver
= platform_drv
;
4141 if (platform_drv
->probe
)
4142 platform
->component
.probe
= snd_soc_platform_drv_probe
;
4143 if (platform_drv
->remove
)
4144 platform
->component
.remove
= snd_soc_platform_drv_remove
;
4146 #ifdef CONFIG_DEBUG_FS
4147 platform
->component
.debugfs_prefix
= "platform";
4150 mutex_lock(&client_mutex
);
4151 snd_soc_component_add_unlocked(&platform
->component
);
4152 list_add(&platform
->list
, &platform_list
);
4153 mutex_unlock(&client_mutex
);
4155 dev_dbg(dev
, "ASoC: Registered platform '%s'\n",
4156 platform
->component
.name
);
4160 EXPORT_SYMBOL_GPL(snd_soc_add_platform
);
4163 * snd_soc_register_platform - Register a platform with the ASoC core
4165 * @platform: platform to register
4167 int snd_soc_register_platform(struct device
*dev
,
4168 const struct snd_soc_platform_driver
*platform_drv
)
4170 struct snd_soc_platform
*platform
;
4173 dev_dbg(dev
, "ASoC: platform register %s\n", dev_name(dev
));
4175 platform
= kzalloc(sizeof(struct snd_soc_platform
), GFP_KERNEL
);
4176 if (platform
== NULL
)
4179 ret
= snd_soc_add_platform(dev
, platform
, platform_drv
);
4185 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
4188 * snd_soc_remove_platform - Remove a platform from the ASoC core
4189 * @platform: the platform to remove
4191 void snd_soc_remove_platform(struct snd_soc_platform
*platform
)
4194 mutex_lock(&client_mutex
);
4195 list_del(&platform
->list
);
4196 snd_soc_component_del_unlocked(&platform
->component
);
4197 mutex_unlock(&client_mutex
);
4199 dev_dbg(platform
->dev
, "ASoC: Unregistered platform '%s'\n",
4200 platform
->component
.name
);
4202 snd_soc_component_cleanup(&platform
->component
);
4204 EXPORT_SYMBOL_GPL(snd_soc_remove_platform
);
4206 struct snd_soc_platform
*snd_soc_lookup_platform(struct device
*dev
)
4208 struct snd_soc_platform
*platform
;
4210 list_for_each_entry(platform
, &platform_list
, list
) {
4211 if (dev
== platform
->dev
)
4217 EXPORT_SYMBOL_GPL(snd_soc_lookup_platform
);
4220 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
4222 * @platform: platform to unregister
4224 void snd_soc_unregister_platform(struct device
*dev
)
4226 struct snd_soc_platform
*platform
;
4228 platform
= snd_soc_lookup_platform(dev
);
4232 snd_soc_remove_platform(platform
);
4235 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
4237 static u64 codec_format_map
[] = {
4238 SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S16_BE
,
4239 SNDRV_PCM_FMTBIT_U16_LE
| SNDRV_PCM_FMTBIT_U16_BE
,
4240 SNDRV_PCM_FMTBIT_S24_LE
| SNDRV_PCM_FMTBIT_S24_BE
,
4241 SNDRV_PCM_FMTBIT_U24_LE
| SNDRV_PCM_FMTBIT_U24_BE
,
4242 SNDRV_PCM_FMTBIT_S32_LE
| SNDRV_PCM_FMTBIT_S32_BE
,
4243 SNDRV_PCM_FMTBIT_U32_LE
| SNDRV_PCM_FMTBIT_U32_BE
,
4244 SNDRV_PCM_FMTBIT_S24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4245 SNDRV_PCM_FMTBIT_U24_3LE
| SNDRV_PCM_FMTBIT_U24_3BE
,
4246 SNDRV_PCM_FMTBIT_S20_3LE
| SNDRV_PCM_FMTBIT_S20_3BE
,
4247 SNDRV_PCM_FMTBIT_U20_3LE
| SNDRV_PCM_FMTBIT_U20_3BE
,
4248 SNDRV_PCM_FMTBIT_S18_3LE
| SNDRV_PCM_FMTBIT_S18_3BE
,
4249 SNDRV_PCM_FMTBIT_U18_3LE
| SNDRV_PCM_FMTBIT_U18_3BE
,
4250 SNDRV_PCM_FMTBIT_FLOAT_LE
| SNDRV_PCM_FMTBIT_FLOAT_BE
,
4251 SNDRV_PCM_FMTBIT_FLOAT64_LE
| SNDRV_PCM_FMTBIT_FLOAT64_BE
,
4252 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
4253 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
,
4256 /* Fix up the DAI formats for endianness: codecs don't actually see
4257 * the endianness of the data but we're using the CPU format
4258 * definitions which do need to include endianness so we ensure that
4259 * codec DAIs always have both big and little endian variants set.
4261 static void fixup_codec_formats(struct snd_soc_pcm_stream
*stream
)
4265 for (i
= 0; i
< ARRAY_SIZE(codec_format_map
); i
++)
4266 if (stream
->formats
& codec_format_map
[i
])
4267 stream
->formats
|= codec_format_map
[i
];
4270 static int snd_soc_codec_drv_probe(struct snd_soc_component
*component
)
4272 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4274 return codec
->driver
->probe(codec
);
4277 static void snd_soc_codec_drv_remove(struct snd_soc_component
*component
)
4279 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4281 codec
->driver
->remove(codec
);
4284 static int snd_soc_codec_drv_write(struct snd_soc_component
*component
,
4285 unsigned int reg
, unsigned int val
)
4287 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4289 return codec
->driver
->write(codec
, reg
, val
);
4292 static int snd_soc_codec_drv_read(struct snd_soc_component
*component
,
4293 unsigned int reg
, unsigned int *val
)
4295 struct snd_soc_codec
*codec
= snd_soc_component_to_codec(component
);
4297 *val
= codec
->driver
->read(codec
, reg
);
4302 static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context
*dapm
,
4303 enum snd_soc_bias_level level
)
4305 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(dapm
);
4307 return codec
->driver
->set_bias_level(codec
, level
);
4311 * snd_soc_register_codec - Register a codec with the ASoC core
4313 * @codec: codec to register
4315 int snd_soc_register_codec(struct device
*dev
,
4316 const struct snd_soc_codec_driver
*codec_drv
,
4317 struct snd_soc_dai_driver
*dai_drv
,
4320 struct snd_soc_codec
*codec
;
4321 struct snd_soc_dai
*dai
;
4324 dev_dbg(dev
, "codec register %s\n", dev_name(dev
));
4326 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
4330 codec
->component
.dapm_ptr
= &codec
->dapm
;
4331 codec
->component
.codec
= codec
;
4333 ret
= snd_soc_component_initialize(&codec
->component
,
4334 &codec_drv
->component_driver
, dev
);
4338 if (codec_drv
->controls
) {
4339 codec
->component
.controls
= codec_drv
->controls
;
4340 codec
->component
.num_controls
= codec_drv
->num_controls
;
4342 if (codec_drv
->dapm_widgets
) {
4343 codec
->component
.dapm_widgets
= codec_drv
->dapm_widgets
;
4344 codec
->component
.num_dapm_widgets
= codec_drv
->num_dapm_widgets
;
4346 if (codec_drv
->dapm_routes
) {
4347 codec
->component
.dapm_routes
= codec_drv
->dapm_routes
;
4348 codec
->component
.num_dapm_routes
= codec_drv
->num_dapm_routes
;
4351 if (codec_drv
->probe
)
4352 codec
->component
.probe
= snd_soc_codec_drv_probe
;
4353 if (codec_drv
->remove
)
4354 codec
->component
.remove
= snd_soc_codec_drv_remove
;
4355 if (codec_drv
->write
)
4356 codec
->component
.write
= snd_soc_codec_drv_write
;
4357 if (codec_drv
->read
)
4358 codec
->component
.read
= snd_soc_codec_drv_read
;
4359 codec
->component
.ignore_pmdown_time
= codec_drv
->ignore_pmdown_time
;
4360 codec
->dapm
.idle_bias_off
= codec_drv
->idle_bias_off
;
4361 codec
->dapm
.suspend_bias_off
= codec_drv
->suspend_bias_off
;
4362 if (codec_drv
->seq_notifier
)
4363 codec
->dapm
.seq_notifier
= codec_drv
->seq_notifier
;
4364 if (codec_drv
->set_bias_level
)
4365 codec
->dapm
.set_bias_level
= snd_soc_codec_set_bias_level
;
4367 codec
->driver
= codec_drv
;
4368 codec
->component
.val_bytes
= codec_drv
->reg_word_size
;
4369 mutex_init(&codec
->mutex
);
4371 #ifdef CONFIG_DEBUG_FS
4372 codec
->component
.init_debugfs
= soc_init_codec_debugfs
;
4373 codec
->component
.debugfs_prefix
= "codec";
4376 if (codec_drv
->get_regmap
)
4377 codec
->component
.regmap
= codec_drv
->get_regmap(dev
);
4379 for (i
= 0; i
< num_dai
; i
++) {
4380 fixup_codec_formats(&dai_drv
[i
].playback
);
4381 fixup_codec_formats(&dai_drv
[i
].capture
);
4384 ret
= snd_soc_register_dais(&codec
->component
, dai_drv
, num_dai
, false);
4386 dev_err(dev
, "ASoC: Failed to regster DAIs: %d\n", ret
);
4390 list_for_each_entry(dai
, &codec
->component
.dai_list
, list
)
4393 mutex_lock(&client_mutex
);
4394 snd_soc_component_add_unlocked(&codec
->component
);
4395 list_add(&codec
->list
, &codec_list
);
4396 mutex_unlock(&client_mutex
);
4398 dev_dbg(codec
->dev
, "ASoC: Registered codec '%s'\n",
4399 codec
->component
.name
);
4403 snd_soc_component_cleanup(&codec
->component
);
4408 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
4411 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4413 * @codec: codec to unregister
4415 void snd_soc_unregister_codec(struct device
*dev
)
4417 struct snd_soc_codec
*codec
;
4419 list_for_each_entry(codec
, &codec_list
, list
) {
4420 if (dev
== codec
->dev
)
4427 mutex_lock(&client_mutex
);
4428 list_del(&codec
->list
);
4429 snd_soc_component_del_unlocked(&codec
->component
);
4430 mutex_unlock(&client_mutex
);
4432 dev_dbg(codec
->dev
, "ASoC: Unregistered codec '%s'\n",
4433 codec
->component
.name
);
4435 snd_soc_component_cleanup(&codec
->component
);
4436 snd_soc_cache_exit(codec
);
4439 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
4441 /* Retrieve a card's name from device tree */
4442 int snd_soc_of_parse_card_name(struct snd_soc_card
*card
,
4443 const char *propname
)
4445 struct device_node
*np
;
4449 pr_err("card->dev is not set before calling %s\n", __func__
);
4453 np
= card
->dev
->of_node
;
4455 ret
= of_property_read_string_index(np
, propname
, 0, &card
->name
);
4457 * EINVAL means the property does not exist. This is fine providing
4458 * card->name was previously set, which is checked later in
4459 * snd_soc_register_card.
4461 if (ret
< 0 && ret
!= -EINVAL
) {
4463 "ASoC: Property '%s' could not be read: %d\n",
4470 EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name
);
4472 static const struct snd_soc_dapm_widget simple_widgets
[] = {
4473 SND_SOC_DAPM_MIC("Microphone", NULL
),
4474 SND_SOC_DAPM_LINE("Line", NULL
),
4475 SND_SOC_DAPM_HP("Headphone", NULL
),
4476 SND_SOC_DAPM_SPK("Speaker", NULL
),
4479 int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card
*card
,
4480 const char *propname
)
4482 struct device_node
*np
= card
->dev
->of_node
;
4483 struct snd_soc_dapm_widget
*widgets
;
4484 const char *template, *wname
;
4485 int i
, j
, num_widgets
, ret
;
4487 num_widgets
= of_property_count_strings(np
, propname
);
4488 if (num_widgets
< 0) {
4490 "ASoC: Property '%s' does not exist\n", propname
);
4493 if (num_widgets
& 1) {
4495 "ASoC: Property '%s' length is not even\n", propname
);
4501 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4506 widgets
= devm_kcalloc(card
->dev
, num_widgets
, sizeof(*widgets
),
4510 "ASoC: Could not allocate memory for widgets\n");
4514 for (i
= 0; i
< num_widgets
; i
++) {
4515 ret
= of_property_read_string_index(np
, propname
,
4519 "ASoC: Property '%s' index %d read error:%d\n",
4520 propname
, 2 * i
, ret
);
4524 for (j
= 0; j
< ARRAY_SIZE(simple_widgets
); j
++) {
4525 if (!strncmp(template, simple_widgets
[j
].name
,
4526 strlen(simple_widgets
[j
].name
))) {
4527 widgets
[i
] = simple_widgets
[j
];
4532 if (j
>= ARRAY_SIZE(simple_widgets
)) {
4534 "ASoC: DAPM widget '%s' is not supported\n",
4539 ret
= of_property_read_string_index(np
, propname
,
4544 "ASoC: Property '%s' index %d read error:%d\n",
4545 propname
, (2 * i
) + 1, ret
);
4549 widgets
[i
].name
= wname
;
4552 card
->dapm_widgets
= widgets
;
4553 card
->num_dapm_widgets
= num_widgets
;
4557 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets
);
4559 int snd_soc_of_parse_tdm_slot(struct device_node
*np
,
4560 unsigned int *slots
,
4561 unsigned int *slot_width
)
4566 if (of_property_read_bool(np
, "dai-tdm-slot-num")) {
4567 ret
= of_property_read_u32(np
, "dai-tdm-slot-num", &val
);
4575 if (of_property_read_bool(np
, "dai-tdm-slot-width")) {
4576 ret
= of_property_read_u32(np
, "dai-tdm-slot-width", &val
);
4586 EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot
);
4588 int snd_soc_of_parse_audio_routing(struct snd_soc_card
*card
,
4589 const char *propname
)
4591 struct device_node
*np
= card
->dev
->of_node
;
4593 struct snd_soc_dapm_route
*routes
;
4596 num_routes
= of_property_count_strings(np
, propname
);
4597 if (num_routes
< 0 || num_routes
& 1) {
4599 "ASoC: Property '%s' does not exist or its length is not even\n",
4605 dev_err(card
->dev
, "ASoC: Property '%s's length is zero\n",
4610 routes
= devm_kzalloc(card
->dev
, num_routes
* sizeof(*routes
),
4614 "ASoC: Could not allocate DAPM route table\n");
4618 for (i
= 0; i
< num_routes
; i
++) {
4619 ret
= of_property_read_string_index(np
, propname
,
4620 2 * i
, &routes
[i
].sink
);
4623 "ASoC: Property '%s' index %d could not be read: %d\n",
4624 propname
, 2 * i
, ret
);
4627 ret
= of_property_read_string_index(np
, propname
,
4628 (2 * i
) + 1, &routes
[i
].source
);
4631 "ASoC: Property '%s' index %d could not be read: %d\n",
4632 propname
, (2 * i
) + 1, ret
);
4637 card
->num_dapm_routes
= num_routes
;
4638 card
->dapm_routes
= routes
;
4642 EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing
);
4644 unsigned int snd_soc_of_parse_daifmt(struct device_node
*np
,
4646 struct device_node
**bitclkmaster
,
4647 struct device_node
**framemaster
)
4651 unsigned int format
= 0;
4657 } of_fmt_table
[] = {
4658 { "i2s", SND_SOC_DAIFMT_I2S
},
4659 { "right_j", SND_SOC_DAIFMT_RIGHT_J
},
4660 { "left_j", SND_SOC_DAIFMT_LEFT_J
},
4661 { "dsp_a", SND_SOC_DAIFMT_DSP_A
},
4662 { "dsp_b", SND_SOC_DAIFMT_DSP_B
},
4663 { "ac97", SND_SOC_DAIFMT_AC97
},
4664 { "pdm", SND_SOC_DAIFMT_PDM
},
4665 { "msb", SND_SOC_DAIFMT_MSB
},
4666 { "lsb", SND_SOC_DAIFMT_LSB
},
4673 * check "[prefix]format = xxx"
4674 * SND_SOC_DAIFMT_FORMAT_MASK area
4676 snprintf(prop
, sizeof(prop
), "%sformat", prefix
);
4677 ret
= of_property_read_string(np
, prop
, &str
);
4679 for (i
= 0; i
< ARRAY_SIZE(of_fmt_table
); i
++) {
4680 if (strcmp(str
, of_fmt_table
[i
].name
) == 0) {
4681 format
|= of_fmt_table
[i
].val
;
4688 * check "[prefix]continuous-clock"
4689 * SND_SOC_DAIFMT_CLOCK_MASK area
4691 snprintf(prop
, sizeof(prop
), "%scontinuous-clock", prefix
);
4692 if (of_get_property(np
, prop
, NULL
))
4693 format
|= SND_SOC_DAIFMT_CONT
;
4695 format
|= SND_SOC_DAIFMT_GATED
;
4698 * check "[prefix]bitclock-inversion"
4699 * check "[prefix]frame-inversion"
4700 * SND_SOC_DAIFMT_INV_MASK area
4702 snprintf(prop
, sizeof(prop
), "%sbitclock-inversion", prefix
);
4703 bit
= !!of_get_property(np
, prop
, NULL
);
4705 snprintf(prop
, sizeof(prop
), "%sframe-inversion", prefix
);
4706 frame
= !!of_get_property(np
, prop
, NULL
);
4708 switch ((bit
<< 4) + frame
) {
4710 format
|= SND_SOC_DAIFMT_IB_IF
;
4713 format
|= SND_SOC_DAIFMT_IB_NF
;
4716 format
|= SND_SOC_DAIFMT_NB_IF
;
4719 /* SND_SOC_DAIFMT_NB_NF is default */
4724 * check "[prefix]bitclock-master"
4725 * check "[prefix]frame-master"
4726 * SND_SOC_DAIFMT_MASTER_MASK area
4728 snprintf(prop
, sizeof(prop
), "%sbitclock-master", prefix
);
4729 bit
= !!of_get_property(np
, prop
, NULL
);
4730 if (bit
&& bitclkmaster
)
4731 *bitclkmaster
= of_parse_phandle(np
, prop
, 0);
4733 snprintf(prop
, sizeof(prop
), "%sframe-master", prefix
);
4734 frame
= !!of_get_property(np
, prop
, NULL
);
4735 if (frame
&& framemaster
)
4736 *framemaster
= of_parse_phandle(np
, prop
, 0);
4738 switch ((bit
<< 4) + frame
) {
4740 format
|= SND_SOC_DAIFMT_CBM_CFM
;
4743 format
|= SND_SOC_DAIFMT_CBM_CFS
;
4746 format
|= SND_SOC_DAIFMT_CBS_CFM
;
4749 format
|= SND_SOC_DAIFMT_CBS_CFS
;
4755 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt
);
4757 int snd_soc_of_get_dai_name(struct device_node
*of_node
,
4758 const char **dai_name
)
4760 struct snd_soc_component
*pos
;
4761 struct of_phandle_args args
;
4764 ret
= of_parse_phandle_with_args(of_node
, "sound-dai",
4765 "#sound-dai-cells", 0, &args
);
4769 ret
= -EPROBE_DEFER
;
4771 mutex_lock(&client_mutex
);
4772 list_for_each_entry(pos
, &component_list
, list
) {
4773 if (pos
->dev
->of_node
!= args
.np
)
4776 if (pos
->driver
->of_xlate_dai_name
) {
4777 ret
= pos
->driver
->of_xlate_dai_name(pos
, &args
, dai_name
);
4781 switch (args
.args_count
) {
4783 id
= 0; /* same as dai_drv[0] */
4793 if (id
< 0 || id
>= pos
->num_dai
) {
4800 *dai_name
= pos
->dai_drv
[id
].name
;
4802 *dai_name
= pos
->name
;
4807 mutex_unlock(&client_mutex
);
4809 of_node_put(args
.np
);
4813 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name
);
4815 static int __init
snd_soc_init(void)
4817 #ifdef CONFIG_DEBUG_FS
4818 snd_soc_debugfs_root
= debugfs_create_dir("asoc", NULL
);
4819 if (IS_ERR(snd_soc_debugfs_root
) || !snd_soc_debugfs_root
) {
4820 pr_warn("ASoC: Failed to create debugfs directory\n");
4821 snd_soc_debugfs_root
= NULL
;
4824 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root
, NULL
,
4826 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4828 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root
, NULL
,
4830 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
4832 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root
, NULL
,
4833 &platform_list_fops
))
4834 pr_warn("ASoC: Failed to create platform list debugfs file\n");
4837 snd_soc_util_init();
4839 return platform_driver_register(&soc_driver
);
4841 module_init(snd_soc_init
);
4843 static void __exit
snd_soc_exit(void)
4845 snd_soc_util_exit();
4847 #ifdef CONFIG_DEBUG_FS
4848 debugfs_remove_recursive(snd_soc_debugfs_root
);
4850 platform_driver_unregister(&soc_driver
);
4852 module_exit(snd_soc_exit
);
4854 /* Module information */
4855 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
4856 MODULE_DESCRIPTION("ALSA SoC Core");
4857 MODULE_LICENSE("GPL");
4858 MODULE_ALIAS("platform:soc-audio");