2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 * with code, comments and ideas from :-
9 * Richard Purdie <richard@openedhand.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 * o Add hw rules to enforce rates, etc.
18 * o More testing with other codecs/machines.
19 * o Add more codecs and platforms to ensure good API coverage.
20 * o Support TDM on PCM and I2S
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
28 #include <linux/bitops.h>
29 #include <linux/debugfs.h>
30 #include <linux/platform_device.h>
31 #include <sound/core.h>
32 #include <sound/pcm.h>
33 #include <sound/pcm_params.h>
34 #include <sound/soc.h>
35 #include <sound/soc-dapm.h>
36 #include <sound/initval.h>
38 static DEFINE_MUTEX(pcm_mutex
);
39 static DEFINE_MUTEX(io_mutex
);
40 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
42 #ifdef CONFIG_DEBUG_FS
43 static struct dentry
*debugfs_root
;
46 static DEFINE_MUTEX(client_mutex
);
47 static LIST_HEAD(card_list
);
48 static LIST_HEAD(dai_list
);
49 static LIST_HEAD(platform_list
);
50 static LIST_HEAD(codec_list
);
52 static int snd_soc_register_card(struct snd_soc_card
*card
);
53 static int snd_soc_unregister_card(struct snd_soc_card
*card
);
56 * This is a timeout to do a DAPM powerdown after a stream is closed().
57 * It can be used to eliminate pops between different playback streams, e.g.
58 * between two audio tracks.
60 static int pmdown_time
= 5000;
61 module_param(pmdown_time
, int, 0);
62 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
65 * This function forces any delayed work to be queued and run.
67 static int run_delayed_work(struct delayed_work
*dwork
)
71 /* cancel any work waiting to be queued. */
72 ret
= cancel_delayed_work(dwork
);
74 /* if there was any work waiting then we run it now and
75 * wait for it's completion */
77 schedule_delayed_work(dwork
, 0);
78 flush_scheduled_work();
83 #ifdef CONFIG_SND_SOC_AC97_BUS
84 /* unregister ac97 codec */
85 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
87 if (codec
->ac97
->dev
.bus
)
88 device_unregister(&codec
->ac97
->dev
);
92 /* stop no dev release warning */
93 static void soc_ac97_device_release(struct device
*dev
){}
95 /* register ac97 codec to bus */
96 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
100 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
101 codec
->ac97
->dev
.parent
= NULL
;
102 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
104 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
105 codec
->card
->number
, 0, codec
->name
);
106 err
= device_register(&codec
->ac97
->dev
);
108 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
109 codec
->ac97
->dev
.bus
= NULL
;
117 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
118 * then initialized and any private data can be allocated. This also calls
119 * startup for the cpu DAI, platform, machine and codec DAI.
121 static int soc_pcm_open(struct snd_pcm_substream
*substream
)
123 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
124 struct snd_soc_device
*socdev
= rtd
->socdev
;
125 struct snd_soc_card
*card
= socdev
->card
;
126 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
127 struct snd_soc_dai_link
*machine
= rtd
->dai
;
128 struct snd_soc_platform
*platform
= card
->platform
;
129 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
130 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
133 mutex_lock(&pcm_mutex
);
135 /* startup the audio subsystem */
136 if (cpu_dai
->ops
.startup
) {
137 ret
= cpu_dai
->ops
.startup(substream
, cpu_dai
);
139 printk(KERN_ERR
"asoc: can't open interface %s\n",
145 if (platform
->pcm_ops
->open
) {
146 ret
= platform
->pcm_ops
->open(substream
);
148 printk(KERN_ERR
"asoc: can't open platform %s\n", platform
->name
);
153 if (codec_dai
->ops
.startup
) {
154 ret
= codec_dai
->ops
.startup(substream
, codec_dai
);
156 printk(KERN_ERR
"asoc: can't open codec %s\n",
162 if (machine
->ops
&& machine
->ops
->startup
) {
163 ret
= machine
->ops
->startup(substream
);
165 printk(KERN_ERR
"asoc: %s startup failed\n", machine
->name
);
170 /* Check that the codec and cpu DAI's are compatible */
171 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
172 runtime
->hw
.rate_min
=
173 max(codec_dai
->playback
.rate_min
,
174 cpu_dai
->playback
.rate_min
);
175 runtime
->hw
.rate_max
=
176 min(codec_dai
->playback
.rate_max
,
177 cpu_dai
->playback
.rate_max
);
178 runtime
->hw
.channels_min
=
179 max(codec_dai
->playback
.channels_min
,
180 cpu_dai
->playback
.channels_min
);
181 runtime
->hw
.channels_max
=
182 min(codec_dai
->playback
.channels_max
,
183 cpu_dai
->playback
.channels_max
);
184 runtime
->hw
.formats
=
185 codec_dai
->playback
.formats
& cpu_dai
->playback
.formats
;
187 codec_dai
->playback
.rates
& cpu_dai
->playback
.rates
;
189 runtime
->hw
.rate_min
=
190 max(codec_dai
->capture
.rate_min
,
191 cpu_dai
->capture
.rate_min
);
192 runtime
->hw
.rate_max
=
193 min(codec_dai
->capture
.rate_max
,
194 cpu_dai
->capture
.rate_max
);
195 runtime
->hw
.channels_min
=
196 max(codec_dai
->capture
.channels_min
,
197 cpu_dai
->capture
.channels_min
);
198 runtime
->hw
.channels_max
=
199 min(codec_dai
->capture
.channels_max
,
200 cpu_dai
->capture
.channels_max
);
201 runtime
->hw
.formats
=
202 codec_dai
->capture
.formats
& cpu_dai
->capture
.formats
;
204 codec_dai
->capture
.rates
& cpu_dai
->capture
.rates
;
207 snd_pcm_limit_hw_rates(runtime
);
208 if (!runtime
->hw
.rates
) {
209 printk(KERN_ERR
"asoc: %s <-> %s No matching rates\n",
210 codec_dai
->name
, cpu_dai
->name
);
213 if (!runtime
->hw
.formats
) {
214 printk(KERN_ERR
"asoc: %s <-> %s No matching formats\n",
215 codec_dai
->name
, cpu_dai
->name
);
218 if (!runtime
->hw
.channels_min
|| !runtime
->hw
.channels_max
) {
219 printk(KERN_ERR
"asoc: %s <-> %s No matching channels\n",
220 codec_dai
->name
, cpu_dai
->name
);
224 pr_debug("asoc: %s <-> %s info:\n", codec_dai
->name
, cpu_dai
->name
);
225 pr_debug("asoc: rate mask 0x%x\n", runtime
->hw
.rates
);
226 pr_debug("asoc: min ch %d max ch %d\n", runtime
->hw
.channels_min
,
227 runtime
->hw
.channels_max
);
228 pr_debug("asoc: min rate %d max rate %d\n", runtime
->hw
.rate_min
,
229 runtime
->hw
.rate_max
);
231 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
232 cpu_dai
->playback
.active
= codec_dai
->playback
.active
= 1;
234 cpu_dai
->capture
.active
= codec_dai
->capture
.active
= 1;
235 cpu_dai
->active
= codec_dai
->active
= 1;
236 cpu_dai
->runtime
= runtime
;
237 card
->codec
->active
++;
238 mutex_unlock(&pcm_mutex
);
242 if (machine
->ops
&& machine
->ops
->shutdown
)
243 machine
->ops
->shutdown(substream
);
246 if (platform
->pcm_ops
->close
)
247 platform
->pcm_ops
->close(substream
);
250 if (cpu_dai
->ops
.shutdown
)
251 cpu_dai
->ops
.shutdown(substream
, cpu_dai
);
253 mutex_unlock(&pcm_mutex
);
258 * Power down the audio subsystem pmdown_time msecs after close is called.
259 * This is to ensure there are no pops or clicks in between any music tracks
260 * due to DAPM power cycling.
262 static void close_delayed_work(struct work_struct
*work
)
264 struct snd_soc_card
*card
= container_of(work
, struct snd_soc_card
,
266 struct snd_soc_device
*socdev
= card
->socdev
;
267 struct snd_soc_codec
*codec
= card
->codec
;
268 struct snd_soc_dai
*codec_dai
;
271 mutex_lock(&pcm_mutex
);
272 for (i
= 0; i
< codec
->num_dai
; i
++) {
273 codec_dai
= &codec
->dai
[i
];
275 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
276 codec_dai
->playback
.stream_name
,
277 codec_dai
->playback
.active
? "active" : "inactive",
278 codec_dai
->pop_wait
? "yes" : "no");
280 /* are we waiting on this codec DAI stream */
281 if (codec_dai
->pop_wait
== 1) {
283 /* Reduce power if no longer active */
284 if (codec
->active
== 0) {
285 pr_debug("pop wq D1 %s %s\n", codec
->name
,
286 codec_dai
->playback
.stream_name
);
287 snd_soc_dapm_set_bias_level(socdev
,
288 SND_SOC_BIAS_PREPARE
);
291 codec_dai
->pop_wait
= 0;
292 snd_soc_dapm_stream_event(codec
,
293 codec_dai
->playback
.stream_name
,
294 SND_SOC_DAPM_STREAM_STOP
);
296 /* Fall into standby if no longer active */
297 if (codec
->active
== 0) {
298 pr_debug("pop wq D3 %s %s\n", codec
->name
,
299 codec_dai
->playback
.stream_name
);
300 snd_soc_dapm_set_bias_level(socdev
,
301 SND_SOC_BIAS_STANDBY
);
305 mutex_unlock(&pcm_mutex
);
309 * Called by ALSA when a PCM substream is closed. Private data can be
310 * freed here. The cpu DAI, codec DAI, machine and platform are also
313 static int soc_codec_close(struct snd_pcm_substream
*substream
)
315 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
316 struct snd_soc_device
*socdev
= rtd
->socdev
;
317 struct snd_soc_card
*card
= socdev
->card
;
318 struct snd_soc_dai_link
*machine
= rtd
->dai
;
319 struct snd_soc_platform
*platform
= card
->platform
;
320 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
321 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
322 struct snd_soc_codec
*codec
= card
->codec
;
324 mutex_lock(&pcm_mutex
);
326 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
327 cpu_dai
->playback
.active
= codec_dai
->playback
.active
= 0;
329 cpu_dai
->capture
.active
= codec_dai
->capture
.active
= 0;
331 if (codec_dai
->playback
.active
== 0 &&
332 codec_dai
->capture
.active
== 0) {
333 cpu_dai
->active
= codec_dai
->active
= 0;
337 /* Muting the DAC suppresses artifacts caused during digital
338 * shutdown, for example from stopping clocks.
340 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
341 snd_soc_dai_digital_mute(codec_dai
, 1);
343 if (cpu_dai
->ops
.shutdown
)
344 cpu_dai
->ops
.shutdown(substream
, cpu_dai
);
346 if (codec_dai
->ops
.shutdown
)
347 codec_dai
->ops
.shutdown(substream
, codec_dai
);
349 if (machine
->ops
&& machine
->ops
->shutdown
)
350 machine
->ops
->shutdown(substream
);
352 if (platform
->pcm_ops
->close
)
353 platform
->pcm_ops
->close(substream
);
354 cpu_dai
->runtime
= NULL
;
356 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
357 /* start delayed pop wq here for playback streams */
358 codec_dai
->pop_wait
= 1;
359 schedule_delayed_work(&card
->delayed_work
,
360 msecs_to_jiffies(pmdown_time
));
362 /* capture streams can be powered down now */
363 snd_soc_dapm_stream_event(codec
,
364 codec_dai
->capture
.stream_name
,
365 SND_SOC_DAPM_STREAM_STOP
);
367 if (codec
->active
== 0 && codec_dai
->pop_wait
== 0)
368 snd_soc_dapm_set_bias_level(socdev
,
369 SND_SOC_BIAS_STANDBY
);
372 mutex_unlock(&pcm_mutex
);
377 * Called by ALSA when the PCM substream is prepared, can set format, sample
378 * rate, etc. This function is non atomic and can be called multiple times,
379 * it can refer to the runtime info.
381 static int soc_pcm_prepare(struct snd_pcm_substream
*substream
)
383 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
384 struct snd_soc_device
*socdev
= rtd
->socdev
;
385 struct snd_soc_card
*card
= socdev
->card
;
386 struct snd_soc_dai_link
*machine
= rtd
->dai
;
387 struct snd_soc_platform
*platform
= card
->platform
;
388 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
389 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
390 struct snd_soc_codec
*codec
= card
->codec
;
393 mutex_lock(&pcm_mutex
);
395 if (machine
->ops
&& machine
->ops
->prepare
) {
396 ret
= machine
->ops
->prepare(substream
);
398 printk(KERN_ERR
"asoc: machine prepare error\n");
403 if (platform
->pcm_ops
->prepare
) {
404 ret
= platform
->pcm_ops
->prepare(substream
);
406 printk(KERN_ERR
"asoc: platform prepare error\n");
411 if (codec_dai
->ops
.prepare
) {
412 ret
= codec_dai
->ops
.prepare(substream
, codec_dai
);
414 printk(KERN_ERR
"asoc: codec DAI prepare error\n");
419 if (cpu_dai
->ops
.prepare
) {
420 ret
= cpu_dai
->ops
.prepare(substream
, cpu_dai
);
422 printk(KERN_ERR
"asoc: cpu DAI prepare error\n");
427 /* cancel any delayed stream shutdown that is pending */
428 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
429 codec_dai
->pop_wait
) {
430 codec_dai
->pop_wait
= 0;
431 cancel_delayed_work(&card
->delayed_work
);
434 /* do we need to power up codec */
435 if (codec
->bias_level
!= SND_SOC_BIAS_ON
) {
436 snd_soc_dapm_set_bias_level(socdev
,
437 SND_SOC_BIAS_PREPARE
);
439 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
440 snd_soc_dapm_stream_event(codec
,
441 codec_dai
->playback
.stream_name
,
442 SND_SOC_DAPM_STREAM_START
);
444 snd_soc_dapm_stream_event(codec
,
445 codec_dai
->capture
.stream_name
,
446 SND_SOC_DAPM_STREAM_START
);
448 snd_soc_dapm_set_bias_level(socdev
, SND_SOC_BIAS_ON
);
449 snd_soc_dai_digital_mute(codec_dai
, 0);
452 /* codec already powered - power on widgets */
453 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
454 snd_soc_dapm_stream_event(codec
,
455 codec_dai
->playback
.stream_name
,
456 SND_SOC_DAPM_STREAM_START
);
458 snd_soc_dapm_stream_event(codec
,
459 codec_dai
->capture
.stream_name
,
460 SND_SOC_DAPM_STREAM_START
);
462 snd_soc_dai_digital_mute(codec_dai
, 0);
466 mutex_unlock(&pcm_mutex
);
471 * Called by ALSA when the hardware params are set by application. This
472 * function can also be called multiple times and can allocate buffers
473 * (using snd_pcm_lib_* ). It's non-atomic.
475 static int soc_pcm_hw_params(struct snd_pcm_substream
*substream
,
476 struct snd_pcm_hw_params
*params
)
478 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
479 struct snd_soc_device
*socdev
= rtd
->socdev
;
480 struct snd_soc_dai_link
*machine
= rtd
->dai
;
481 struct snd_soc_card
*card
= socdev
->card
;
482 struct snd_soc_platform
*platform
= card
->platform
;
483 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
484 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
487 mutex_lock(&pcm_mutex
);
489 if (machine
->ops
&& machine
->ops
->hw_params
) {
490 ret
= machine
->ops
->hw_params(substream
, params
);
492 printk(KERN_ERR
"asoc: machine hw_params failed\n");
497 if (codec_dai
->ops
.hw_params
) {
498 ret
= codec_dai
->ops
.hw_params(substream
, params
, codec_dai
);
500 printk(KERN_ERR
"asoc: can't set codec %s hw params\n",
506 if (cpu_dai
->ops
.hw_params
) {
507 ret
= cpu_dai
->ops
.hw_params(substream
, params
, cpu_dai
);
509 printk(KERN_ERR
"asoc: interface %s hw params failed\n",
515 if (platform
->pcm_ops
->hw_params
) {
516 ret
= platform
->pcm_ops
->hw_params(substream
, params
);
518 printk(KERN_ERR
"asoc: platform %s hw params failed\n",
525 mutex_unlock(&pcm_mutex
);
529 if (cpu_dai
->ops
.hw_free
)
530 cpu_dai
->ops
.hw_free(substream
, cpu_dai
);
533 if (codec_dai
->ops
.hw_free
)
534 codec_dai
->ops
.hw_free(substream
, codec_dai
);
537 if (machine
->ops
&& machine
->ops
->hw_free
)
538 machine
->ops
->hw_free(substream
);
540 mutex_unlock(&pcm_mutex
);
545 * Free's resources allocated by hw_params, can be called multiple times
547 static int soc_pcm_hw_free(struct snd_pcm_substream
*substream
)
549 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
550 struct snd_soc_device
*socdev
= rtd
->socdev
;
551 struct snd_soc_dai_link
*machine
= rtd
->dai
;
552 struct snd_soc_card
*card
= socdev
->card
;
553 struct snd_soc_platform
*platform
= card
->platform
;
554 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
555 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
556 struct snd_soc_codec
*codec
= card
->codec
;
558 mutex_lock(&pcm_mutex
);
560 /* apply codec digital mute */
562 snd_soc_dai_digital_mute(codec_dai
, 1);
564 /* free any machine hw params */
565 if (machine
->ops
&& machine
->ops
->hw_free
)
566 machine
->ops
->hw_free(substream
);
568 /* free any DMA resources */
569 if (platform
->pcm_ops
->hw_free
)
570 platform
->pcm_ops
->hw_free(substream
);
572 /* now free hw params for the DAI's */
573 if (codec_dai
->ops
.hw_free
)
574 codec_dai
->ops
.hw_free(substream
, codec_dai
);
576 if (cpu_dai
->ops
.hw_free
)
577 cpu_dai
->ops
.hw_free(substream
, cpu_dai
);
579 mutex_unlock(&pcm_mutex
);
583 static int soc_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
585 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
586 struct snd_soc_device
*socdev
= rtd
->socdev
;
587 struct snd_soc_card
*card
= socdev
->card
;
588 struct snd_soc_dai_link
*machine
= rtd
->dai
;
589 struct snd_soc_platform
*platform
= card
->platform
;
590 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
591 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
594 if (codec_dai
->ops
.trigger
) {
595 ret
= codec_dai
->ops
.trigger(substream
, cmd
, codec_dai
);
600 if (platform
->pcm_ops
->trigger
) {
601 ret
= platform
->pcm_ops
->trigger(substream
, cmd
);
606 if (cpu_dai
->ops
.trigger
) {
607 ret
= cpu_dai
->ops
.trigger(substream
, cmd
, cpu_dai
);
614 /* ASoC PCM operations */
615 static struct snd_pcm_ops soc_pcm_ops
= {
616 .open
= soc_pcm_open
,
617 .close
= soc_codec_close
,
618 .hw_params
= soc_pcm_hw_params
,
619 .hw_free
= soc_pcm_hw_free
,
620 .prepare
= soc_pcm_prepare
,
621 .trigger
= soc_pcm_trigger
,
625 /* powers down audio subsystem for suspend */
626 static int soc_suspend(struct platform_device
*pdev
, pm_message_t state
)
628 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
629 struct snd_soc_card
*card
= socdev
->card
;
630 struct snd_soc_platform
*platform
= card
->platform
;
631 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
632 struct snd_soc_codec
*codec
= card
->codec
;
635 /* Due to the resume being scheduled into a workqueue we could
636 * suspend before that's finished - wait for it to complete.
638 snd_power_lock(codec
->card
);
639 snd_power_wait(codec
->card
, SNDRV_CTL_POWER_D0
);
640 snd_power_unlock(codec
->card
);
642 /* we're going to block userspace touching us until resume completes */
643 snd_power_change_state(codec
->card
, SNDRV_CTL_POWER_D3hot
);
645 /* mute any active DAC's */
646 for (i
= 0; i
< card
->num_links
; i
++) {
647 struct snd_soc_dai
*dai
= card
->dai_link
[i
].codec_dai
;
648 if (dai
->ops
.digital_mute
&& dai
->playback
.active
)
649 dai
->ops
.digital_mute(dai
, 1);
652 /* suspend all pcms */
653 for (i
= 0; i
< card
->num_links
; i
++)
654 snd_pcm_suspend_all(card
->dai_link
[i
].pcm
);
656 if (card
->suspend_pre
)
657 card
->suspend_pre(pdev
, state
);
659 for (i
= 0; i
< card
->num_links
; i
++) {
660 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
661 if (cpu_dai
->suspend
&& !cpu_dai
->ac97_control
)
662 cpu_dai
->suspend(cpu_dai
);
663 if (platform
->suspend
)
664 platform
->suspend(cpu_dai
);
667 /* close any waiting streams and save state */
668 run_delayed_work(&card
->delayed_work
);
669 codec
->suspend_bias_level
= codec
->bias_level
;
671 for (i
= 0; i
< codec
->num_dai
; i
++) {
672 char *stream
= codec
->dai
[i
].playback
.stream_name
;
674 snd_soc_dapm_stream_event(codec
, stream
,
675 SND_SOC_DAPM_STREAM_SUSPEND
);
676 stream
= codec
->dai
[i
].capture
.stream_name
;
678 snd_soc_dapm_stream_event(codec
, stream
,
679 SND_SOC_DAPM_STREAM_SUSPEND
);
682 if (codec_dev
->suspend
)
683 codec_dev
->suspend(pdev
, state
);
685 for (i
= 0; i
< card
->num_links
; i
++) {
686 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
687 if (cpu_dai
->suspend
&& cpu_dai
->ac97_control
)
688 cpu_dai
->suspend(cpu_dai
);
691 if (card
->suspend_post
)
692 card
->suspend_post(pdev
, state
);
697 /* deferred resume work, so resume can complete before we finished
698 * setting our codec back up, which can be very slow on I2C
700 static void soc_resume_deferred(struct work_struct
*work
)
702 struct snd_soc_card
*card
= container_of(work
,
704 deferred_resume_work
);
705 struct snd_soc_device
*socdev
= card
->socdev
;
706 struct snd_soc_platform
*platform
= card
->platform
;
707 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
708 struct snd_soc_codec
*codec
= card
->codec
;
709 struct platform_device
*pdev
= to_platform_device(socdev
->dev
);
712 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
713 * so userspace apps are blocked from touching us
716 dev_dbg(socdev
->dev
, "starting resume work\n");
718 if (card
->resume_pre
)
719 card
->resume_pre(pdev
);
721 for (i
= 0; i
< card
->num_links
; i
++) {
722 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
723 if (cpu_dai
->resume
&& cpu_dai
->ac97_control
)
724 cpu_dai
->resume(cpu_dai
);
727 if (codec_dev
->resume
)
728 codec_dev
->resume(pdev
);
730 for (i
= 0; i
< codec
->num_dai
; i
++) {
731 char *stream
= codec
->dai
[i
].playback
.stream_name
;
733 snd_soc_dapm_stream_event(codec
, stream
,
734 SND_SOC_DAPM_STREAM_RESUME
);
735 stream
= codec
->dai
[i
].capture
.stream_name
;
737 snd_soc_dapm_stream_event(codec
, stream
,
738 SND_SOC_DAPM_STREAM_RESUME
);
741 /* unmute any active DACs */
742 for (i
= 0; i
< card
->num_links
; i
++) {
743 struct snd_soc_dai
*dai
= card
->dai_link
[i
].codec_dai
;
744 if (dai
->ops
.digital_mute
&& dai
->playback
.active
)
745 dai
->ops
.digital_mute(dai
, 0);
748 for (i
= 0; i
< card
->num_links
; i
++) {
749 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
750 if (cpu_dai
->resume
&& !cpu_dai
->ac97_control
)
751 cpu_dai
->resume(cpu_dai
);
752 if (platform
->resume
)
753 platform
->resume(cpu_dai
);
756 if (card
->resume_post
)
757 card
->resume_post(pdev
);
759 dev_dbg(socdev
->dev
, "resume work completed\n");
761 /* userspace can access us now we are back as we were before */
762 snd_power_change_state(codec
->card
, SNDRV_CTL_POWER_D0
);
765 /* powers up audio subsystem after a suspend */
766 static int soc_resume(struct platform_device
*pdev
)
768 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
769 struct snd_soc_card
*card
= socdev
->card
;
771 dev_dbg(socdev
->dev
, "scheduling resume work\n");
773 if (!schedule_work(&card
->deferred_resume_work
))
774 dev_err(socdev
->dev
, "resume work item may be lost\n");
780 #define soc_suspend NULL
781 #define soc_resume NULL
784 static void snd_soc_instantiate_card(struct snd_soc_card
*card
)
786 struct platform_device
*pdev
= container_of(card
->dev
,
787 struct platform_device
,
789 struct snd_soc_codec_device
*codec_dev
= card
->socdev
->codec_dev
;
790 struct snd_soc_platform
*platform
;
791 struct snd_soc_dai
*dai
;
792 int i
, found
, ret
, ac97
;
794 if (card
->instantiated
)
798 list_for_each_entry(platform
, &platform_list
, list
)
799 if (card
->platform
== platform
) {
804 dev_dbg(card
->dev
, "Platform %s not registered\n",
805 card
->platform
->name
);
810 for (i
= 0; i
< card
->num_links
; i
++) {
812 list_for_each_entry(dai
, &dai_list
, list
)
813 if (card
->dai_link
[i
].cpu_dai
== dai
) {
818 dev_dbg(card
->dev
, "DAI %s not registered\n",
819 card
->dai_link
[i
].cpu_dai
->name
);
823 if (card
->dai_link
[i
].cpu_dai
->ac97_control
)
827 /* If we have AC97 in the system then don't wait for the
828 * codec. This will need revisiting if we have to handle
829 * systems with mixed AC97 and non-AC97 parts. Only check for
830 * DAIs currently; we can't do this per link since some AC97
831 * codecs have non-AC97 DAIs.
834 for (i
= 0; i
< card
->num_links
; i
++) {
836 list_for_each_entry(dai
, &dai_list
, list
)
837 if (card
->dai_link
[i
].codec_dai
== dai
) {
842 dev_dbg(card
->dev
, "DAI %s not registered\n",
843 card
->dai_link
[i
].codec_dai
->name
);
848 /* Note that we do not current check for codec components */
850 dev_dbg(card
->dev
, "All components present, instantiating\n");
852 /* Found everything, bring it up */
854 ret
= card
->probe(pdev
);
859 for (i
= 0; i
< card
->num_links
; i
++) {
860 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
861 if (cpu_dai
->probe
) {
862 ret
= cpu_dai
->probe(pdev
, cpu_dai
);
868 if (codec_dev
->probe
) {
869 ret
= codec_dev
->probe(pdev
);
874 if (platform
->probe
) {
875 ret
= platform
->probe(pdev
);
880 /* DAPM stream work */
881 INIT_DELAYED_WORK(&card
->delayed_work
, close_delayed_work
);
883 /* deferred resume work */
884 INIT_WORK(&card
->deferred_resume_work
, soc_resume_deferred
);
887 card
->instantiated
= 1;
892 if (codec_dev
->remove
)
893 codec_dev
->remove(pdev
);
896 for (i
--; i
>= 0; i
--) {
897 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
899 cpu_dai
->remove(pdev
, cpu_dai
);
907 * Attempt to initialise any uninitalised cards. Must be called with
910 static void snd_soc_instantiate_cards(void)
912 struct snd_soc_card
*card
;
913 list_for_each_entry(card
, &card_list
, list
)
914 snd_soc_instantiate_card(card
);
917 /* probes a new socdev */
918 static int soc_probe(struct platform_device
*pdev
)
921 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
922 struct snd_soc_card
*card
= socdev
->card
;
924 /* Bodge while we push things out of socdev */
925 card
->socdev
= socdev
;
927 /* Bodge while we unpick instantiation */
928 card
->dev
= &pdev
->dev
;
929 ret
= snd_soc_register_card(card
);
931 dev_err(&pdev
->dev
, "Failed to register card\n");
938 /* removes a socdev */
939 static int soc_remove(struct platform_device
*pdev
)
942 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
943 struct snd_soc_card
*card
= socdev
->card
;
944 struct snd_soc_platform
*platform
= card
->platform
;
945 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
947 run_delayed_work(&card
->delayed_work
);
949 if (platform
->remove
)
950 platform
->remove(pdev
);
952 if (codec_dev
->remove
)
953 codec_dev
->remove(pdev
);
955 for (i
= 0; i
< card
->num_links
; i
++) {
956 struct snd_soc_dai
*cpu_dai
= card
->dai_link
[i
].cpu_dai
;
958 cpu_dai
->remove(pdev
, cpu_dai
);
964 snd_soc_unregister_card(card
);
969 /* ASoC platform driver */
970 static struct platform_driver soc_driver
= {
973 .owner
= THIS_MODULE
,
976 .remove
= soc_remove
,
977 .suspend
= soc_suspend
,
978 .resume
= soc_resume
,
981 /* create a new pcm */
982 static int soc_new_pcm(struct snd_soc_device
*socdev
,
983 struct snd_soc_dai_link
*dai_link
, int num
)
985 struct snd_soc_card
*card
= socdev
->card
;
986 struct snd_soc_codec
*codec
= card
->codec
;
987 struct snd_soc_platform
*platform
= card
->platform
;
988 struct snd_soc_dai
*codec_dai
= dai_link
->codec_dai
;
989 struct snd_soc_dai
*cpu_dai
= dai_link
->cpu_dai
;
990 struct snd_soc_pcm_runtime
*rtd
;
993 int ret
= 0, playback
= 0, capture
= 0;
995 rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
), GFP_KERNEL
);
1000 rtd
->socdev
= socdev
;
1001 codec_dai
->codec
= card
->codec
;
1003 /* check client and interface hw capabilities */
1004 sprintf(new_name
, "%s %s-%d", dai_link
->stream_name
, codec_dai
->name
,
1007 if (codec_dai
->playback
.channels_min
)
1009 if (codec_dai
->capture
.channels_min
)
1012 ret
= snd_pcm_new(codec
->card
, new_name
, codec
->pcm_devs
++, playback
,
1015 printk(KERN_ERR
"asoc: can't create pcm for codec %s\n",
1021 dai_link
->pcm
= pcm
;
1022 pcm
->private_data
= rtd
;
1023 soc_pcm_ops
.mmap
= platform
->pcm_ops
->mmap
;
1024 soc_pcm_ops
.pointer
= platform
->pcm_ops
->pointer
;
1025 soc_pcm_ops
.ioctl
= platform
->pcm_ops
->ioctl
;
1026 soc_pcm_ops
.copy
= platform
->pcm_ops
->copy
;
1027 soc_pcm_ops
.silence
= platform
->pcm_ops
->silence
;
1028 soc_pcm_ops
.ack
= platform
->pcm_ops
->ack
;
1029 soc_pcm_ops
.page
= platform
->pcm_ops
->page
;
1032 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &soc_pcm_ops
);
1035 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &soc_pcm_ops
);
1037 ret
= platform
->pcm_new(codec
->card
, codec_dai
, pcm
);
1039 printk(KERN_ERR
"asoc: platform pcm constructor failed\n");
1044 pcm
->private_free
= platform
->pcm_free
;
1045 printk(KERN_INFO
"asoc: %s <-> %s mapping ok\n", codec_dai
->name
,
1050 /* codec register dump */
1051 static ssize_t
soc_codec_reg_show(struct snd_soc_codec
*codec
, char *buf
)
1053 int i
, step
= 1, count
= 0;
1055 if (!codec
->reg_cache_size
)
1058 if (codec
->reg_cache_step
)
1059 step
= codec
->reg_cache_step
;
1061 count
+= sprintf(buf
, "%s registers\n", codec
->name
);
1062 for (i
= 0; i
< codec
->reg_cache_size
; i
+= step
) {
1063 count
+= sprintf(buf
+ count
, "%2x: ", i
);
1064 if (count
>= PAGE_SIZE
- 1)
1067 if (codec
->display_register
)
1068 count
+= codec
->display_register(codec
, buf
+ count
,
1069 PAGE_SIZE
- count
, i
);
1071 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
1072 "%4x", codec
->read(codec
, i
));
1074 if (count
>= PAGE_SIZE
- 1)
1077 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "\n");
1078 if (count
>= PAGE_SIZE
- 1)
1082 /* Truncate count; min() would cause a warning */
1083 if (count
>= PAGE_SIZE
)
1084 count
= PAGE_SIZE
- 1;
1088 static ssize_t
codec_reg_show(struct device
*dev
,
1089 struct device_attribute
*attr
, char *buf
)
1091 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
1092 return soc_codec_reg_show(devdata
->card
->codec
, buf
);
1095 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
1097 #ifdef CONFIG_DEBUG_FS
1098 static int codec_reg_open_file(struct inode
*inode
, struct file
*file
)
1100 file
->private_data
= inode
->i_private
;
1104 static ssize_t
codec_reg_read_file(struct file
*file
, char __user
*user_buf
,
1105 size_t count
, loff_t
*ppos
)
1108 struct snd_soc_codec
*codec
= file
->private_data
;
1109 char *buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1112 ret
= soc_codec_reg_show(codec
, buf
);
1114 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, ret
);
1119 static ssize_t
codec_reg_write_file(struct file
*file
,
1120 const char __user
*user_buf
, size_t count
, loff_t
*ppos
)
1125 unsigned long reg
, value
;
1127 struct snd_soc_codec
*codec
= file
->private_data
;
1129 buf_size
= min(count
, (sizeof(buf
)-1));
1130 if (copy_from_user(buf
, user_buf
, buf_size
))
1134 if (codec
->reg_cache_step
)
1135 step
= codec
->reg_cache_step
;
1137 while (*start
== ' ')
1139 reg
= simple_strtoul(start
, &start
, 16);
1140 if ((reg
>= codec
->reg_cache_size
) || (reg
% step
))
1142 while (*start
== ' ')
1144 if (strict_strtoul(start
, 16, &value
))
1146 codec
->write(codec
, reg
, value
);
1150 static const struct file_operations codec_reg_fops
= {
1151 .open
= codec_reg_open_file
,
1152 .read
= codec_reg_read_file
,
1153 .write
= codec_reg_write_file
,
1156 static void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
1158 codec
->debugfs_reg
= debugfs_create_file("codec_reg", 0644,
1159 debugfs_root
, codec
,
1161 if (!codec
->debugfs_reg
)
1163 "ASoC: Failed to create codec register debugfs file\n");
1165 codec
->debugfs_pop_time
= debugfs_create_u32("dapm_pop_time", 0744,
1168 if (!codec
->debugfs_pop_time
)
1170 "Failed to create pop time debugfs file\n");
1173 static void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
1175 debugfs_remove(codec
->debugfs_pop_time
);
1176 debugfs_remove(codec
->debugfs_reg
);
1181 static inline void soc_init_codec_debugfs(struct snd_soc_codec
*codec
)
1185 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec
*codec
)
1191 * snd_soc_new_ac97_codec - initailise AC97 device
1192 * @codec: audio codec
1193 * @ops: AC97 bus operations
1194 * @num: AC97 codec number
1196 * Initialises AC97 codec resources for use by ad-hoc devices only.
1198 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1199 struct snd_ac97_bus_ops
*ops
, int num
)
1201 mutex_lock(&codec
->mutex
);
1203 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1204 if (codec
->ac97
== NULL
) {
1205 mutex_unlock(&codec
->mutex
);
1209 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1210 if (codec
->ac97
->bus
== NULL
) {
1213 mutex_unlock(&codec
->mutex
);
1217 codec
->ac97
->bus
->ops
= ops
;
1218 codec
->ac97
->num
= num
;
1219 mutex_unlock(&codec
->mutex
);
1222 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1225 * snd_soc_free_ac97_codec - free AC97 codec device
1226 * @codec: audio codec
1228 * Frees AC97 codec device resources.
1230 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1232 mutex_lock(&codec
->mutex
);
1233 kfree(codec
->ac97
->bus
);
1236 mutex_unlock(&codec
->mutex
);
1238 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1241 * snd_soc_update_bits - update codec register bits
1242 * @codec: audio codec
1243 * @reg: codec register
1244 * @mask: register mask
1247 * Writes new register value.
1249 * Returns 1 for change else 0.
1251 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1252 unsigned short mask
, unsigned short value
)
1255 unsigned short old
, new;
1257 mutex_lock(&io_mutex
);
1258 old
= snd_soc_read(codec
, reg
);
1259 new = (old
& ~mask
) | value
;
1260 change
= old
!= new;
1262 snd_soc_write(codec
, reg
, new);
1264 mutex_unlock(&io_mutex
);
1267 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1270 * snd_soc_test_bits - test register for change
1271 * @codec: audio codec
1272 * @reg: codec register
1273 * @mask: register mask
1276 * Tests a register with a new value and checks if the new value is
1277 * different from the old value.
1279 * Returns 1 for change else 0.
1281 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1282 unsigned short mask
, unsigned short value
)
1285 unsigned short old
, new;
1287 mutex_lock(&io_mutex
);
1288 old
= snd_soc_read(codec
, reg
);
1289 new = (old
& ~mask
) | value
;
1290 change
= old
!= new;
1291 mutex_unlock(&io_mutex
);
1295 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1298 * snd_soc_new_pcms - create new sound card and pcms
1299 * @socdev: the SoC audio device
1300 * @idx: ALSA card index
1301 * @xid: card identification
1303 * Create a new sound card based upon the codec and interface pcms.
1305 * Returns 0 for success, else error.
1307 int snd_soc_new_pcms(struct snd_soc_device
*socdev
, int idx
, const char *xid
)
1309 struct snd_soc_card
*card
= socdev
->card
;
1310 struct snd_soc_codec
*codec
= card
->codec
;
1313 mutex_lock(&codec
->mutex
);
1315 /* register a sound card */
1316 ret
= snd_card_create(idx
, xid
, codec
->owner
, 0, &codec
->card
);
1318 printk(KERN_ERR
"asoc: can't create sound card for codec %s\n",
1320 mutex_unlock(&codec
->mutex
);
1324 codec
->card
->dev
= socdev
->dev
;
1325 codec
->card
->private_data
= codec
;
1326 strncpy(codec
->card
->driver
, codec
->name
, sizeof(codec
->card
->driver
));
1328 /* create the pcms */
1329 for (i
= 0; i
< card
->num_links
; i
++) {
1330 ret
= soc_new_pcm(socdev
, &card
->dai_link
[i
], i
);
1332 printk(KERN_ERR
"asoc: can't create pcm %s\n",
1333 card
->dai_link
[i
].stream_name
);
1334 mutex_unlock(&codec
->mutex
);
1339 mutex_unlock(&codec
->mutex
);
1342 EXPORT_SYMBOL_GPL(snd_soc_new_pcms
);
1345 * snd_soc_init_card - register sound card
1346 * @socdev: the SoC audio device
1348 * Register a SoC sound card. Also registers an AC97 device if the
1349 * codec is AC97 for ad hoc devices.
1351 * Returns 0 for success, else error.
1353 int snd_soc_init_card(struct snd_soc_device
*socdev
)
1355 struct snd_soc_card
*card
= socdev
->card
;
1356 struct snd_soc_codec
*codec
= card
->codec
;
1357 int ret
= 0, i
, ac97
= 0, err
= 0;
1359 for (i
= 0; i
< card
->num_links
; i
++) {
1360 if (card
->dai_link
[i
].init
) {
1361 err
= card
->dai_link
[i
].init(codec
);
1363 printk(KERN_ERR
"asoc: failed to init %s\n",
1364 card
->dai_link
[i
].stream_name
);
1368 if (card
->dai_link
[i
].codec_dai
->ac97_control
)
1371 snprintf(codec
->card
->shortname
, sizeof(codec
->card
->shortname
),
1373 snprintf(codec
->card
->longname
, sizeof(codec
->card
->longname
),
1374 "%s (%s)", card
->name
, codec
->name
);
1376 ret
= snd_card_register(codec
->card
);
1378 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n",
1383 mutex_lock(&codec
->mutex
);
1384 #ifdef CONFIG_SND_SOC_AC97_BUS
1386 ret
= soc_ac97_dev_register(codec
);
1388 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1389 snd_card_free(codec
->card
);
1390 mutex_unlock(&codec
->mutex
);
1396 err
= snd_soc_dapm_sys_add(socdev
->dev
);
1398 printk(KERN_WARNING
"asoc: failed to add dapm sysfs entries\n");
1400 err
= device_create_file(socdev
->dev
, &dev_attr_codec_reg
);
1402 printk(KERN_WARNING
"asoc: failed to add codec sysfs files\n");
1404 soc_init_codec_debugfs(codec
);
1405 mutex_unlock(&codec
->mutex
);
1410 EXPORT_SYMBOL_GPL(snd_soc_init_card
);
1413 * snd_soc_free_pcms - free sound card and pcms
1414 * @socdev: the SoC audio device
1416 * Frees sound card and pcms associated with the socdev.
1417 * Also unregister the codec if it is an AC97 device.
1419 void snd_soc_free_pcms(struct snd_soc_device
*socdev
)
1421 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
1422 #ifdef CONFIG_SND_SOC_AC97_BUS
1423 struct snd_soc_dai
*codec_dai
;
1427 mutex_lock(&codec
->mutex
);
1428 soc_cleanup_codec_debugfs(codec
);
1429 #ifdef CONFIG_SND_SOC_AC97_BUS
1430 for (i
= 0; i
< codec
->num_dai
; i
++) {
1431 codec_dai
= &codec
->dai
[i
];
1432 if (codec_dai
->ac97_control
&& codec
->ac97
) {
1433 soc_ac97_dev_unregister(codec
);
1441 snd_card_free(codec
->card
);
1442 device_remove_file(socdev
->dev
, &dev_attr_codec_reg
);
1443 mutex_unlock(&codec
->mutex
);
1445 EXPORT_SYMBOL_GPL(snd_soc_free_pcms
);
1448 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1449 * @substream: the pcm substream
1450 * @hw: the hardware parameters
1452 * Sets the substream runtime hardware parameters.
1454 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1455 const struct snd_pcm_hardware
*hw
)
1457 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1458 runtime
->hw
.info
= hw
->info
;
1459 runtime
->hw
.formats
= hw
->formats
;
1460 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1461 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1462 runtime
->hw
.periods_min
= hw
->periods_min
;
1463 runtime
->hw
.periods_max
= hw
->periods_max
;
1464 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1465 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1468 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1471 * snd_soc_cnew - create new control
1472 * @_template: control template
1473 * @data: control private data
1474 * @long_name: control long name
1476 * Create a new mixer control from a template control.
1478 * Returns 0 for success, else error.
1480 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1481 void *data
, char *long_name
)
1483 struct snd_kcontrol_new
template;
1485 memcpy(&template, _template
, sizeof(template));
1487 template.name
= long_name
;
1490 return snd_ctl_new1(&template, data
);
1492 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
1495 * snd_soc_add_controls - add an array of controls to a codec.
1496 * Convienience function to add a list of controls. Many codecs were
1497 * duplicating this code.
1499 * @codec: codec to add controls to
1500 * @controls: array of controls to add
1501 * @num_controls: number of elements in the array
1503 * Return 0 for success, else error.
1505 int snd_soc_add_controls(struct snd_soc_codec
*codec
,
1506 const struct snd_kcontrol_new
*controls
, int num_controls
)
1508 struct snd_card
*card
= codec
->card
;
1511 for (i
= 0; i
< num_controls
; i
++) {
1512 const struct snd_kcontrol_new
*control
= &controls
[i
];
1513 err
= snd_ctl_add(card
, snd_soc_cnew(control
, codec
, NULL
));
1515 dev_err(codec
->dev
, "%s: Failed to add %s\n",
1516 codec
->name
, control
->name
);
1523 EXPORT_SYMBOL_GPL(snd_soc_add_controls
);
1526 * snd_soc_info_enum_double - enumerated double mixer info callback
1527 * @kcontrol: mixer control
1528 * @uinfo: control element information
1530 * Callback to provide information about a double enumerated
1533 * Returns 0 for success.
1535 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
1536 struct snd_ctl_elem_info
*uinfo
)
1538 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1540 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1541 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
1542 uinfo
->value
.enumerated
.items
= e
->max
;
1544 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
1545 uinfo
->value
.enumerated
.item
= e
->max
- 1;
1546 strcpy(uinfo
->value
.enumerated
.name
,
1547 e
->texts
[uinfo
->value
.enumerated
.item
]);
1550 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
1553 * snd_soc_get_enum_double - enumerated double mixer get callback
1554 * @kcontrol: mixer control
1555 * @ucontrol: control element information
1557 * Callback to get the value of a double enumerated mixer.
1559 * Returns 0 for success.
1561 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
1562 struct snd_ctl_elem_value
*ucontrol
)
1564 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1565 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1566 unsigned short val
, bitmask
;
1568 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1570 val
= snd_soc_read(codec
, e
->reg
);
1571 ucontrol
->value
.enumerated
.item
[0]
1572 = (val
>> e
->shift_l
) & (bitmask
- 1);
1573 if (e
->shift_l
!= e
->shift_r
)
1574 ucontrol
->value
.enumerated
.item
[1] =
1575 (val
>> e
->shift_r
) & (bitmask
- 1);
1579 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
1582 * snd_soc_put_enum_double - enumerated double mixer put callback
1583 * @kcontrol: mixer control
1584 * @ucontrol: control element information
1586 * Callback to set the value of a double enumerated mixer.
1588 * Returns 0 for success.
1590 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
1591 struct snd_ctl_elem_value
*ucontrol
)
1593 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1594 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1596 unsigned short mask
, bitmask
;
1598 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1600 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1602 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
1603 mask
= (bitmask
- 1) << e
->shift_l
;
1604 if (e
->shift_l
!= e
->shift_r
) {
1605 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1607 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1608 mask
|= (bitmask
- 1) << e
->shift_r
;
1611 return snd_soc_update_bits(codec
, e
->reg
, mask
, val
);
1613 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
1616 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
1617 * @kcontrol: mixer control
1618 * @ucontrol: control element information
1620 * Callback to get the value of a double semi enumerated mixer.
1622 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1623 * used for handling bitfield coded enumeration for example.
1625 * Returns 0 for success.
1627 int snd_soc_get_value_enum_double(struct snd_kcontrol
*kcontrol
,
1628 struct snd_ctl_elem_value
*ucontrol
)
1630 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1631 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1632 unsigned short reg_val
, val
, mux
;
1634 reg_val
= snd_soc_read(codec
, e
->reg
);
1635 val
= (reg_val
>> e
->shift_l
) & e
->mask
;
1636 for (mux
= 0; mux
< e
->max
; mux
++) {
1637 if (val
== e
->values
[mux
])
1640 ucontrol
->value
.enumerated
.item
[0] = mux
;
1641 if (e
->shift_l
!= e
->shift_r
) {
1642 val
= (reg_val
>> e
->shift_r
) & e
->mask
;
1643 for (mux
= 0; mux
< e
->max
; mux
++) {
1644 if (val
== e
->values
[mux
])
1647 ucontrol
->value
.enumerated
.item
[1] = mux
;
1652 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double
);
1655 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
1656 * @kcontrol: mixer control
1657 * @ucontrol: control element information
1659 * Callback to set the value of a double semi enumerated mixer.
1661 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1662 * used for handling bitfield coded enumeration for example.
1664 * Returns 0 for success.
1666 int snd_soc_put_value_enum_double(struct snd_kcontrol
*kcontrol
,
1667 struct snd_ctl_elem_value
*ucontrol
)
1669 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1670 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1672 unsigned short mask
;
1674 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1676 val
= e
->values
[ucontrol
->value
.enumerated
.item
[0]] << e
->shift_l
;
1677 mask
= e
->mask
<< e
->shift_l
;
1678 if (e
->shift_l
!= e
->shift_r
) {
1679 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1681 val
|= e
->values
[ucontrol
->value
.enumerated
.item
[1]] << e
->shift_r
;
1682 mask
|= e
->mask
<< e
->shift_r
;
1685 return snd_soc_update_bits(codec
, e
->reg
, mask
, val
);
1687 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double
);
1690 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1691 * @kcontrol: mixer control
1692 * @uinfo: control element information
1694 * Callback to provide information about an external enumerated
1697 * Returns 0 for success.
1699 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
1700 struct snd_ctl_elem_info
*uinfo
)
1702 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1704 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1706 uinfo
->value
.enumerated
.items
= e
->max
;
1708 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
1709 uinfo
->value
.enumerated
.item
= e
->max
- 1;
1710 strcpy(uinfo
->value
.enumerated
.name
,
1711 e
->texts
[uinfo
->value
.enumerated
.item
]);
1714 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
1717 * snd_soc_info_volsw_ext - external single mixer info callback
1718 * @kcontrol: mixer control
1719 * @uinfo: control element information
1721 * Callback to provide information about a single external mixer control.
1723 * Returns 0 for success.
1725 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
1726 struct snd_ctl_elem_info
*uinfo
)
1728 int max
= kcontrol
->private_value
;
1731 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1733 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1736 uinfo
->value
.integer
.min
= 0;
1737 uinfo
->value
.integer
.max
= max
;
1740 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
1743 * snd_soc_info_volsw - single mixer info callback
1744 * @kcontrol: mixer control
1745 * @uinfo: control element information
1747 * Callback to provide information about a single mixer control.
1749 * Returns 0 for success.
1751 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
1752 struct snd_ctl_elem_info
*uinfo
)
1754 struct soc_mixer_control
*mc
=
1755 (struct soc_mixer_control
*)kcontrol
->private_value
;
1757 unsigned int shift
= mc
->shift
;
1758 unsigned int rshift
= mc
->rshift
;
1761 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1763 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1765 uinfo
->count
= shift
== rshift
? 1 : 2;
1766 uinfo
->value
.integer
.min
= 0;
1767 uinfo
->value
.integer
.max
= max
;
1770 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
1773 * snd_soc_get_volsw - single mixer get callback
1774 * @kcontrol: mixer control
1775 * @ucontrol: control element information
1777 * Callback to get the value of a single mixer control.
1779 * Returns 0 for success.
1781 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
1782 struct snd_ctl_elem_value
*ucontrol
)
1784 struct soc_mixer_control
*mc
=
1785 (struct soc_mixer_control
*)kcontrol
->private_value
;
1786 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1787 unsigned int reg
= mc
->reg
;
1788 unsigned int shift
= mc
->shift
;
1789 unsigned int rshift
= mc
->rshift
;
1791 unsigned int mask
= (1 << fls(max
)) - 1;
1792 unsigned int invert
= mc
->invert
;
1794 ucontrol
->value
.integer
.value
[0] =
1795 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
1796 if (shift
!= rshift
)
1797 ucontrol
->value
.integer
.value
[1] =
1798 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
1800 ucontrol
->value
.integer
.value
[0] =
1801 max
- ucontrol
->value
.integer
.value
[0];
1802 if (shift
!= rshift
)
1803 ucontrol
->value
.integer
.value
[1] =
1804 max
- ucontrol
->value
.integer
.value
[1];
1809 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
1812 * snd_soc_put_volsw - single mixer put callback
1813 * @kcontrol: mixer control
1814 * @ucontrol: control element information
1816 * Callback to set the value of a single mixer control.
1818 * Returns 0 for success.
1820 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
1821 struct snd_ctl_elem_value
*ucontrol
)
1823 struct soc_mixer_control
*mc
=
1824 (struct soc_mixer_control
*)kcontrol
->private_value
;
1825 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1826 unsigned int reg
= mc
->reg
;
1827 unsigned int shift
= mc
->shift
;
1828 unsigned int rshift
= mc
->rshift
;
1830 unsigned int mask
= (1 << fls(max
)) - 1;
1831 unsigned int invert
= mc
->invert
;
1832 unsigned short val
, val2
, val_mask
;
1834 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1837 val_mask
= mask
<< shift
;
1839 if (shift
!= rshift
) {
1840 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1843 val_mask
|= mask
<< rshift
;
1844 val
|= val2
<< rshift
;
1846 return snd_soc_update_bits(codec
, reg
, val_mask
, val
);
1848 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
1851 * snd_soc_info_volsw_2r - double mixer info callback
1852 * @kcontrol: mixer control
1853 * @uinfo: control element information
1855 * Callback to provide information about a double mixer control that
1856 * spans 2 codec registers.
1858 * Returns 0 for success.
1860 int snd_soc_info_volsw_2r(struct snd_kcontrol
*kcontrol
,
1861 struct snd_ctl_elem_info
*uinfo
)
1863 struct soc_mixer_control
*mc
=
1864 (struct soc_mixer_control
*)kcontrol
->private_value
;
1868 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1870 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1873 uinfo
->value
.integer
.min
= 0;
1874 uinfo
->value
.integer
.max
= max
;
1877 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r
);
1880 * snd_soc_get_volsw_2r - double mixer get callback
1881 * @kcontrol: mixer control
1882 * @ucontrol: control element information
1884 * Callback to get the value of a double mixer control that spans 2 registers.
1886 * Returns 0 for success.
1888 int snd_soc_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
1889 struct snd_ctl_elem_value
*ucontrol
)
1891 struct soc_mixer_control
*mc
=
1892 (struct soc_mixer_control
*)kcontrol
->private_value
;
1893 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1894 unsigned int reg
= mc
->reg
;
1895 unsigned int reg2
= mc
->rreg
;
1896 unsigned int shift
= mc
->shift
;
1898 unsigned int mask
= (1<<fls(max
))-1;
1899 unsigned int invert
= mc
->invert
;
1901 ucontrol
->value
.integer
.value
[0] =
1902 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
1903 ucontrol
->value
.integer
.value
[1] =
1904 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
1906 ucontrol
->value
.integer
.value
[0] =
1907 max
- ucontrol
->value
.integer
.value
[0];
1908 ucontrol
->value
.integer
.value
[1] =
1909 max
- ucontrol
->value
.integer
.value
[1];
1914 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r
);
1917 * snd_soc_put_volsw_2r - double mixer set callback
1918 * @kcontrol: mixer control
1919 * @ucontrol: control element information
1921 * Callback to set the value of a double mixer control that spans 2 registers.
1923 * Returns 0 for success.
1925 int snd_soc_put_volsw_2r(struct snd_kcontrol
*kcontrol
,
1926 struct snd_ctl_elem_value
*ucontrol
)
1928 struct soc_mixer_control
*mc
=
1929 (struct soc_mixer_control
*)kcontrol
->private_value
;
1930 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1931 unsigned int reg
= mc
->reg
;
1932 unsigned int reg2
= mc
->rreg
;
1933 unsigned int shift
= mc
->shift
;
1935 unsigned int mask
= (1 << fls(max
)) - 1;
1936 unsigned int invert
= mc
->invert
;
1938 unsigned short val
, val2
, val_mask
;
1940 val_mask
= mask
<< shift
;
1941 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1942 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1950 val2
= val2
<< shift
;
1952 err
= snd_soc_update_bits(codec
, reg
, val_mask
, val
);
1956 err
= snd_soc_update_bits(codec
, reg2
, val_mask
, val2
);
1959 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r
);
1962 * snd_soc_info_volsw_s8 - signed mixer info callback
1963 * @kcontrol: mixer control
1964 * @uinfo: control element information
1966 * Callback to provide information about a signed mixer control.
1968 * Returns 0 for success.
1970 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
1971 struct snd_ctl_elem_info
*uinfo
)
1973 struct soc_mixer_control
*mc
=
1974 (struct soc_mixer_control
*)kcontrol
->private_value
;
1978 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1980 uinfo
->value
.integer
.min
= 0;
1981 uinfo
->value
.integer
.max
= max
-min
;
1984 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
1987 * snd_soc_get_volsw_s8 - signed mixer get callback
1988 * @kcontrol: mixer control
1989 * @ucontrol: control element information
1991 * Callback to get the value of a signed mixer control.
1993 * Returns 0 for success.
1995 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
1996 struct snd_ctl_elem_value
*ucontrol
)
1998 struct soc_mixer_control
*mc
=
1999 (struct soc_mixer_control
*)kcontrol
->private_value
;
2000 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2001 unsigned int reg
= mc
->reg
;
2003 int val
= snd_soc_read(codec
, reg
);
2005 ucontrol
->value
.integer
.value
[0] =
2006 ((signed char)(val
& 0xff))-min
;
2007 ucontrol
->value
.integer
.value
[1] =
2008 ((signed char)((val
>> 8) & 0xff))-min
;
2011 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
2014 * snd_soc_put_volsw_sgn - signed mixer put callback
2015 * @kcontrol: mixer control
2016 * @ucontrol: control element information
2018 * Callback to set the value of a signed mixer control.
2020 * Returns 0 for success.
2022 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
2023 struct snd_ctl_elem_value
*ucontrol
)
2025 struct soc_mixer_control
*mc
=
2026 (struct soc_mixer_control
*)kcontrol
->private_value
;
2027 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2028 unsigned int reg
= mc
->reg
;
2032 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
2033 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
2035 return snd_soc_update_bits(codec
, reg
, 0xffff, val
);
2037 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
2040 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2042 * @clk_id: DAI specific clock ID
2043 * @freq: new clock frequency in Hz
2044 * @dir: new clock direction - input/output.
2046 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2048 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
2049 unsigned int freq
, int dir
)
2051 if (dai
->ops
.set_sysclk
)
2052 return dai
->ops
.set_sysclk(dai
, clk_id
, freq
, dir
);
2056 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
2059 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2061 * @div_id: DAI specific clock divider ID
2062 * @div: new clock divisor.
2064 * Configures the clock dividers. This is used to derive the best DAI bit and
2065 * frame clocks from the system or master clock. It's best to set the DAI bit
2066 * and frame clocks as low as possible to save system power.
2068 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
2069 int div_id
, int div
)
2071 if (dai
->ops
.set_clkdiv
)
2072 return dai
->ops
.set_clkdiv(dai
, div_id
, div
);
2076 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
2079 * snd_soc_dai_set_pll - configure DAI PLL.
2081 * @pll_id: DAI specific PLL ID
2082 * @freq_in: PLL input clock frequency in Hz
2083 * @freq_out: requested PLL output clock frequency in Hz
2085 * Configures and enables PLL to generate output clock based on input clock.
2087 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
,
2088 int pll_id
, unsigned int freq_in
, unsigned int freq_out
)
2090 if (dai
->ops
.set_pll
)
2091 return dai
->ops
.set_pll(dai
, pll_id
, freq_in
, freq_out
);
2095 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
2098 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2100 * @fmt: SND_SOC_DAIFMT_ format value.
2102 * Configures the DAI hardware format and clocking.
2104 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2106 if (dai
->ops
.set_fmt
)
2107 return dai
->ops
.set_fmt(dai
, fmt
);
2111 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
2114 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2116 * @mask: DAI specific mask representing used slots.
2117 * @slots: Number of slots in use.
2119 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2122 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
2123 unsigned int mask
, int slots
)
2125 if (dai
->ops
.set_sysclk
)
2126 return dai
->ops
.set_tdm_slot(dai
, mask
, slots
);
2130 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
2133 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2135 * @tristate: tristate enable
2137 * Tristates the DAI so that others can use it.
2139 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
2141 if (dai
->ops
.set_sysclk
)
2142 return dai
->ops
.set_tristate(dai
, tristate
);
2146 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
2149 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2151 * @mute: mute enable
2153 * Mutes the DAI DAC.
2155 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
2157 if (dai
->ops
.digital_mute
)
2158 return dai
->ops
.digital_mute(dai
, mute
);
2162 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
2165 * snd_soc_register_card - Register a card with the ASoC core
2167 * @card: Card to register
2169 * Note that currently this is an internal only function: it will be
2170 * exposed to machine drivers after further backporting of ASoC v2
2171 * registration APIs.
2173 static int snd_soc_register_card(struct snd_soc_card
*card
)
2175 if (!card
->name
|| !card
->dev
)
2178 INIT_LIST_HEAD(&card
->list
);
2179 card
->instantiated
= 0;
2181 mutex_lock(&client_mutex
);
2182 list_add(&card
->list
, &card_list
);
2183 snd_soc_instantiate_cards();
2184 mutex_unlock(&client_mutex
);
2186 dev_dbg(card
->dev
, "Registered card '%s'\n", card
->name
);
2192 * snd_soc_unregister_card - Unregister a card with the ASoC core
2194 * @card: Card to unregister
2196 * Note that currently this is an internal only function: it will be
2197 * exposed to machine drivers after further backporting of ASoC v2
2198 * registration APIs.
2200 static int snd_soc_unregister_card(struct snd_soc_card
*card
)
2202 mutex_lock(&client_mutex
);
2203 list_del(&card
->list
);
2204 mutex_unlock(&client_mutex
);
2206 dev_dbg(card
->dev
, "Unregistered card '%s'\n", card
->name
);
2212 * snd_soc_register_dai - Register a DAI with the ASoC core
2214 * @dai: DAI to register
2216 int snd_soc_register_dai(struct snd_soc_dai
*dai
)
2221 /* The device should become mandatory over time */
2223 printk(KERN_WARNING
"No device for DAI %s\n", dai
->name
);
2225 INIT_LIST_HEAD(&dai
->list
);
2227 mutex_lock(&client_mutex
);
2228 list_add(&dai
->list
, &dai_list
);
2229 snd_soc_instantiate_cards();
2230 mutex_unlock(&client_mutex
);
2232 pr_debug("Registered DAI '%s'\n", dai
->name
);
2236 EXPORT_SYMBOL_GPL(snd_soc_register_dai
);
2239 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2241 * @dai: DAI to unregister
2243 void snd_soc_unregister_dai(struct snd_soc_dai
*dai
)
2245 mutex_lock(&client_mutex
);
2246 list_del(&dai
->list
);
2247 mutex_unlock(&client_mutex
);
2249 pr_debug("Unregistered DAI '%s'\n", dai
->name
);
2251 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai
);
2254 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
2256 * @dai: Array of DAIs to register
2257 * @count: Number of DAIs
2259 int snd_soc_register_dais(struct snd_soc_dai
*dai
, size_t count
)
2263 for (i
= 0; i
< count
; i
++) {
2264 ret
= snd_soc_register_dai(&dai
[i
]);
2272 for (i
--; i
>= 0; i
--)
2273 snd_soc_unregister_dai(&dai
[i
]);
2277 EXPORT_SYMBOL_GPL(snd_soc_register_dais
);
2280 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
2282 * @dai: Array of DAIs to unregister
2283 * @count: Number of DAIs
2285 void snd_soc_unregister_dais(struct snd_soc_dai
*dai
, size_t count
)
2289 for (i
= 0; i
< count
; i
++)
2290 snd_soc_unregister_dai(&dai
[i
]);
2292 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais
);
2295 * snd_soc_register_platform - Register a platform with the ASoC core
2297 * @platform: platform to register
2299 int snd_soc_register_platform(struct snd_soc_platform
*platform
)
2301 if (!platform
->name
)
2304 INIT_LIST_HEAD(&platform
->list
);
2306 mutex_lock(&client_mutex
);
2307 list_add(&platform
->list
, &platform_list
);
2308 snd_soc_instantiate_cards();
2309 mutex_unlock(&client_mutex
);
2311 pr_debug("Registered platform '%s'\n", platform
->name
);
2315 EXPORT_SYMBOL_GPL(snd_soc_register_platform
);
2318 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
2320 * @platform: platform to unregister
2322 void snd_soc_unregister_platform(struct snd_soc_platform
*platform
)
2324 mutex_lock(&client_mutex
);
2325 list_del(&platform
->list
);
2326 mutex_unlock(&client_mutex
);
2328 pr_debug("Unregistered platform '%s'\n", platform
->name
);
2330 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform
);
2333 * snd_soc_register_codec - Register a codec with the ASoC core
2335 * @codec: codec to register
2337 int snd_soc_register_codec(struct snd_soc_codec
*codec
)
2342 /* The device should become mandatory over time */
2344 printk(KERN_WARNING
"No device for codec %s\n", codec
->name
);
2346 INIT_LIST_HEAD(&codec
->list
);
2348 mutex_lock(&client_mutex
);
2349 list_add(&codec
->list
, &codec_list
);
2350 snd_soc_instantiate_cards();
2351 mutex_unlock(&client_mutex
);
2353 pr_debug("Registered codec '%s'\n", codec
->name
);
2357 EXPORT_SYMBOL_GPL(snd_soc_register_codec
);
2360 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
2362 * @codec: codec to unregister
2364 void snd_soc_unregister_codec(struct snd_soc_codec
*codec
)
2366 mutex_lock(&client_mutex
);
2367 list_del(&codec
->list
);
2368 mutex_unlock(&client_mutex
);
2370 pr_debug("Unregistered codec '%s'\n", codec
->name
);
2372 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec
);
2374 static int __init
snd_soc_init(void)
2376 #ifdef CONFIG_DEBUG_FS
2377 debugfs_root
= debugfs_create_dir("asoc", NULL
);
2378 if (IS_ERR(debugfs_root
) || !debugfs_root
) {
2380 "ASoC: Failed to create debugfs directory\n");
2381 debugfs_root
= NULL
;
2385 return platform_driver_register(&soc_driver
);
2388 static void __exit
snd_soc_exit(void)
2390 #ifdef CONFIG_DEBUG_FS
2391 debugfs_remove_recursive(debugfs_root
);
2393 platform_driver_unregister(&soc_driver
);
2396 module_init(snd_soc_init
);
2397 module_exit(snd_soc_exit
);
2399 /* Module information */
2400 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2401 MODULE_DESCRIPTION("ALSA SoC Core");
2402 MODULE_LICENSE("GPL");
2403 MODULE_ALIAS("platform:soc-audio");