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/platform_device.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include <sound/soc.h>
34 #include <sound/soc-dapm.h>
35 #include <sound/initval.h>
40 #define dbg(format, arg...) printk(format, ## arg)
42 #define dbg(format, arg...)
45 static DEFINE_MUTEX(pcm_mutex
);
46 static DEFINE_MUTEX(io_mutex
);
47 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq
);
50 * This is a timeout to do a DAPM powerdown after a stream is closed().
51 * It can be used to eliminate pops between different playback streams, e.g.
52 * between two audio tracks.
54 static int pmdown_time
= 5000;
55 module_param(pmdown_time
, int, 0);
56 MODULE_PARM_DESC(pmdown_time
, "DAPM stream powerdown time (msecs)");
59 * This function forces any delayed work to be queued and run.
61 static int run_delayed_work(struct delayed_work
*dwork
)
65 /* cancel any work waiting to be queued. */
66 ret
= cancel_delayed_work(dwork
);
68 /* if there was any work waiting then we run it now and
69 * wait for it's completion */
71 schedule_delayed_work(dwork
, 0);
72 flush_scheduled_work();
77 #ifdef CONFIG_SND_SOC_AC97_BUS
78 /* unregister ac97 codec */
79 static int soc_ac97_dev_unregister(struct snd_soc_codec
*codec
)
81 if (codec
->ac97
->dev
.bus
)
82 device_unregister(&codec
->ac97
->dev
);
86 /* stop no dev release warning */
87 static void soc_ac97_device_release(struct device
*dev
){}
89 /* register ac97 codec to bus */
90 static int soc_ac97_dev_register(struct snd_soc_codec
*codec
)
94 codec
->ac97
->dev
.bus
= &ac97_bus_type
;
95 codec
->ac97
->dev
.parent
= NULL
;
96 codec
->ac97
->dev
.release
= soc_ac97_device_release
;
98 dev_set_name(&codec
->ac97
->dev
, "%d-%d:%s",
99 codec
->card
->number
, 0, codec
->name
);
100 err
= device_register(&codec
->ac97
->dev
);
102 snd_printk(KERN_ERR
"Can't register ac97 bus\n");
103 codec
->ac97
->dev
.bus
= NULL
;
110 static inline const char *get_dai_name(int type
)
113 case SND_SOC_DAI_AC97_BUS
:
114 case SND_SOC_DAI_AC97
:
116 case SND_SOC_DAI_I2S
:
118 case SND_SOC_DAI_PCM
:
125 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
126 * then initialized and any private data can be allocated. This also calls
127 * startup for the cpu DAI, platform, machine and codec DAI.
129 static int soc_pcm_open(struct snd_pcm_substream
*substream
)
131 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
132 struct snd_soc_device
*socdev
= rtd
->socdev
;
133 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
134 struct snd_soc_dai_link
*machine
= rtd
->dai
;
135 struct snd_soc_platform
*platform
= socdev
->platform
;
136 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
137 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
140 mutex_lock(&pcm_mutex
);
142 /* startup the audio subsystem */
143 if (cpu_dai
->ops
.startup
) {
144 ret
= cpu_dai
->ops
.startup(substream
);
146 printk(KERN_ERR
"asoc: can't open interface %s\n",
152 if (platform
->pcm_ops
->open
) {
153 ret
= platform
->pcm_ops
->open(substream
);
155 printk(KERN_ERR
"asoc: can't open platform %s\n", platform
->name
);
160 if (codec_dai
->ops
.startup
) {
161 ret
= codec_dai
->ops
.startup(substream
);
163 printk(KERN_ERR
"asoc: can't open codec %s\n",
169 if (machine
->ops
&& machine
->ops
->startup
) {
170 ret
= machine
->ops
->startup(substream
);
172 printk(KERN_ERR
"asoc: %s startup failed\n", machine
->name
);
177 /* Check that the codec and cpu DAI's are compatible */
178 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
179 runtime
->hw
.rate_min
=
180 max(codec_dai
->playback
.rate_min
,
181 cpu_dai
->playback
.rate_min
);
182 runtime
->hw
.rate_max
=
183 min(codec_dai
->playback
.rate_max
,
184 cpu_dai
->playback
.rate_max
);
185 runtime
->hw
.channels_min
=
186 max(codec_dai
->playback
.channels_min
,
187 cpu_dai
->playback
.channels_min
);
188 runtime
->hw
.channels_max
=
189 min(codec_dai
->playback
.channels_max
,
190 cpu_dai
->playback
.channels_max
);
191 runtime
->hw
.formats
=
192 codec_dai
->playback
.formats
& cpu_dai
->playback
.formats
;
194 codec_dai
->playback
.rates
& cpu_dai
->playback
.rates
;
196 runtime
->hw
.rate_min
=
197 max(codec_dai
->capture
.rate_min
,
198 cpu_dai
->capture
.rate_min
);
199 runtime
->hw
.rate_max
=
200 min(codec_dai
->capture
.rate_max
,
201 cpu_dai
->capture
.rate_max
);
202 runtime
->hw
.channels_min
=
203 max(codec_dai
->capture
.channels_min
,
204 cpu_dai
->capture
.channels_min
);
205 runtime
->hw
.channels_max
=
206 min(codec_dai
->capture
.channels_max
,
207 cpu_dai
->capture
.channels_max
);
208 runtime
->hw
.formats
=
209 codec_dai
->capture
.formats
& cpu_dai
->capture
.formats
;
211 codec_dai
->capture
.rates
& cpu_dai
->capture
.rates
;
214 snd_pcm_limit_hw_rates(runtime
);
215 if (!runtime
->hw
.rates
) {
216 printk(KERN_ERR
"asoc: %s <-> %s No matching rates\n",
217 codec_dai
->name
, cpu_dai
->name
);
220 if (!runtime
->hw
.formats
) {
221 printk(KERN_ERR
"asoc: %s <-> %s No matching formats\n",
222 codec_dai
->name
, cpu_dai
->name
);
225 if (!runtime
->hw
.channels_min
|| !runtime
->hw
.channels_max
) {
226 printk(KERN_ERR
"asoc: %s <-> %s No matching channels\n",
227 codec_dai
->name
, cpu_dai
->name
);
231 dbg("asoc: %s <-> %s info:\n", codec_dai
->name
, cpu_dai
->name
);
232 dbg("asoc: rate mask 0x%x\n", runtime
->hw
.rates
);
233 dbg("asoc: min ch %d max ch %d\n", runtime
->hw
.channels_min
,
234 runtime
->hw
.channels_max
);
235 dbg("asoc: min rate %d max rate %d\n", runtime
->hw
.rate_min
,
236 runtime
->hw
.rate_max
);
238 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
239 cpu_dai
->playback
.active
= codec_dai
->playback
.active
= 1;
241 cpu_dai
->capture
.active
= codec_dai
->capture
.active
= 1;
242 cpu_dai
->active
= codec_dai
->active
= 1;
243 cpu_dai
->runtime
= runtime
;
244 socdev
->codec
->active
++;
245 mutex_unlock(&pcm_mutex
);
249 if (machine
->ops
&& machine
->ops
->shutdown
)
250 machine
->ops
->shutdown(substream
);
253 if (platform
->pcm_ops
->close
)
254 platform
->pcm_ops
->close(substream
);
257 if (cpu_dai
->ops
.shutdown
)
258 cpu_dai
->ops
.shutdown(substream
);
260 mutex_unlock(&pcm_mutex
);
265 * Power down the audio subsystem pmdown_time msecs after close is called.
266 * This is to ensure there are no pops or clicks in between any music tracks
267 * due to DAPM power cycling.
269 static void close_delayed_work(struct work_struct
*work
)
271 struct snd_soc_device
*socdev
=
272 container_of(work
, struct snd_soc_device
, delayed_work
.work
);
273 struct snd_soc_codec
*codec
= socdev
->codec
;
274 struct snd_soc_dai
*codec_dai
;
277 mutex_lock(&pcm_mutex
);
278 for (i
= 0; i
< codec
->num_dai
; i
++) {
279 codec_dai
= &codec
->dai
[i
];
281 dbg("pop wq checking: %s status: %s waiting: %s\n",
282 codec_dai
->playback
.stream_name
,
283 codec_dai
->playback
.active
? "active" : "inactive",
284 codec_dai
->pop_wait
? "yes" : "no");
286 /* are we waiting on this codec DAI stream */
287 if (codec_dai
->pop_wait
== 1) {
289 /* Reduce power if no longer active */
290 if (codec
->active
== 0) {
291 dbg("pop wq D1 %s %s\n", codec
->name
,
292 codec_dai
->playback
.stream_name
);
293 snd_soc_dapm_set_bias_level(socdev
,
294 SND_SOC_BIAS_PREPARE
);
297 codec_dai
->pop_wait
= 0;
298 snd_soc_dapm_stream_event(codec
,
299 codec_dai
->playback
.stream_name
,
300 SND_SOC_DAPM_STREAM_STOP
);
302 /* Fall into standby if no longer active */
303 if (codec
->active
== 0) {
304 dbg("pop wq D3 %s %s\n", codec
->name
,
305 codec_dai
->playback
.stream_name
);
306 snd_soc_dapm_set_bias_level(socdev
,
307 SND_SOC_BIAS_STANDBY
);
311 mutex_unlock(&pcm_mutex
);
315 * Called by ALSA when a PCM substream is closed. Private data can be
316 * freed here. The cpu DAI, codec DAI, machine and platform are also
319 static int soc_codec_close(struct snd_pcm_substream
*substream
)
321 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
322 struct snd_soc_device
*socdev
= rtd
->socdev
;
323 struct snd_soc_dai_link
*machine
= rtd
->dai
;
324 struct snd_soc_platform
*platform
= socdev
->platform
;
325 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
326 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
327 struct snd_soc_codec
*codec
= socdev
->codec
;
329 mutex_lock(&pcm_mutex
);
331 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
332 cpu_dai
->playback
.active
= codec_dai
->playback
.active
= 0;
334 cpu_dai
->capture
.active
= codec_dai
->capture
.active
= 0;
336 if (codec_dai
->playback
.active
== 0 &&
337 codec_dai
->capture
.active
== 0) {
338 cpu_dai
->active
= codec_dai
->active
= 0;
342 /* Muting the DAC suppresses artifacts caused during digital
343 * shutdown, for example from stopping clocks.
345 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
346 snd_soc_dai_digital_mute(codec_dai
, 1);
348 if (cpu_dai
->ops
.shutdown
)
349 cpu_dai
->ops
.shutdown(substream
);
351 if (codec_dai
->ops
.shutdown
)
352 codec_dai
->ops
.shutdown(substream
);
354 if (machine
->ops
&& machine
->ops
->shutdown
)
355 machine
->ops
->shutdown(substream
);
357 if (platform
->pcm_ops
->close
)
358 platform
->pcm_ops
->close(substream
);
359 cpu_dai
->runtime
= NULL
;
361 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
362 /* start delayed pop wq here for playback streams */
363 codec_dai
->pop_wait
= 1;
364 schedule_delayed_work(&socdev
->delayed_work
,
365 msecs_to_jiffies(pmdown_time
));
367 /* capture streams can be powered down now */
368 snd_soc_dapm_stream_event(codec
,
369 codec_dai
->capture
.stream_name
,
370 SND_SOC_DAPM_STREAM_STOP
);
372 if (codec
->active
== 0 && codec_dai
->pop_wait
== 0)
373 snd_soc_dapm_set_bias_level(socdev
,
374 SND_SOC_BIAS_STANDBY
);
377 mutex_unlock(&pcm_mutex
);
382 * Called by ALSA when the PCM substream is prepared, can set format, sample
383 * rate, etc. This function is non atomic and can be called multiple times,
384 * it can refer to the runtime info.
386 static int soc_pcm_prepare(struct snd_pcm_substream
*substream
)
388 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
389 struct snd_soc_device
*socdev
= rtd
->socdev
;
390 struct snd_soc_dai_link
*machine
= rtd
->dai
;
391 struct snd_soc_platform
*platform
= socdev
->platform
;
392 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
393 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
394 struct snd_soc_codec
*codec
= socdev
->codec
;
397 mutex_lock(&pcm_mutex
);
399 if (machine
->ops
&& machine
->ops
->prepare
) {
400 ret
= machine
->ops
->prepare(substream
);
402 printk(KERN_ERR
"asoc: machine prepare error\n");
407 if (platform
->pcm_ops
->prepare
) {
408 ret
= platform
->pcm_ops
->prepare(substream
);
410 printk(KERN_ERR
"asoc: platform prepare error\n");
415 if (codec_dai
->ops
.prepare
) {
416 ret
= codec_dai
->ops
.prepare(substream
);
418 printk(KERN_ERR
"asoc: codec DAI prepare error\n");
423 if (cpu_dai
->ops
.prepare
) {
424 ret
= cpu_dai
->ops
.prepare(substream
);
426 printk(KERN_ERR
"asoc: cpu DAI prepare error\n");
431 /* we only want to start a DAPM playback stream if we are not waiting
432 * on an existing one stopping */
433 if (codec_dai
->pop_wait
) {
434 /* we are waiting for the delayed work to start */
435 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
436 snd_soc_dapm_stream_event(socdev
->codec
,
437 codec_dai
->capture
.stream_name
,
438 SND_SOC_DAPM_STREAM_START
);
440 codec_dai
->pop_wait
= 0;
441 cancel_delayed_work(&socdev
->delayed_work
);
442 snd_soc_dai_digital_mute(codec_dai
, 0);
445 /* no delayed work - do we need to power up codec */
446 if (codec
->bias_level
!= SND_SOC_BIAS_ON
) {
448 snd_soc_dapm_set_bias_level(socdev
,
449 SND_SOC_BIAS_PREPARE
);
451 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
452 snd_soc_dapm_stream_event(codec
,
453 codec_dai
->playback
.stream_name
,
454 SND_SOC_DAPM_STREAM_START
);
456 snd_soc_dapm_stream_event(codec
,
457 codec_dai
->capture
.stream_name
,
458 SND_SOC_DAPM_STREAM_START
);
460 snd_soc_dapm_set_bias_level(socdev
, SND_SOC_BIAS_ON
);
461 snd_soc_dai_digital_mute(codec_dai
, 0);
464 /* codec already powered - power on widgets */
465 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
466 snd_soc_dapm_stream_event(codec
,
467 codec_dai
->playback
.stream_name
,
468 SND_SOC_DAPM_STREAM_START
);
470 snd_soc_dapm_stream_event(codec
,
471 codec_dai
->capture
.stream_name
,
472 SND_SOC_DAPM_STREAM_START
);
474 snd_soc_dai_digital_mute(codec_dai
, 0);
479 mutex_unlock(&pcm_mutex
);
484 * Called by ALSA when the hardware params are set by application. This
485 * function can also be called multiple times and can allocate buffers
486 * (using snd_pcm_lib_* ). It's non-atomic.
488 static int soc_pcm_hw_params(struct snd_pcm_substream
*substream
,
489 struct snd_pcm_hw_params
*params
)
491 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
492 struct snd_soc_device
*socdev
= rtd
->socdev
;
493 struct snd_soc_dai_link
*machine
= rtd
->dai
;
494 struct snd_soc_platform
*platform
= socdev
->platform
;
495 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
496 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
499 mutex_lock(&pcm_mutex
);
501 if (machine
->ops
&& machine
->ops
->hw_params
) {
502 ret
= machine
->ops
->hw_params(substream
, params
);
504 printk(KERN_ERR
"asoc: machine hw_params failed\n");
509 if (codec_dai
->ops
.hw_params
) {
510 ret
= codec_dai
->ops
.hw_params(substream
, params
);
512 printk(KERN_ERR
"asoc: can't set codec %s hw params\n",
518 if (cpu_dai
->ops
.hw_params
) {
519 ret
= cpu_dai
->ops
.hw_params(substream
, params
);
521 printk(KERN_ERR
"asoc: interface %s hw params failed\n",
527 if (platform
->pcm_ops
->hw_params
) {
528 ret
= platform
->pcm_ops
->hw_params(substream
, params
);
530 printk(KERN_ERR
"asoc: platform %s hw params failed\n",
537 mutex_unlock(&pcm_mutex
);
541 if (cpu_dai
->ops
.hw_free
)
542 cpu_dai
->ops
.hw_free(substream
);
545 if (codec_dai
->ops
.hw_free
)
546 codec_dai
->ops
.hw_free(substream
);
549 if (machine
->ops
&& machine
->ops
->hw_free
)
550 machine
->ops
->hw_free(substream
);
552 mutex_unlock(&pcm_mutex
);
557 * Free's resources allocated by hw_params, can be called multiple times
559 static int soc_pcm_hw_free(struct snd_pcm_substream
*substream
)
561 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
562 struct snd_soc_device
*socdev
= rtd
->socdev
;
563 struct snd_soc_dai_link
*machine
= rtd
->dai
;
564 struct snd_soc_platform
*platform
= socdev
->platform
;
565 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
566 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
567 struct snd_soc_codec
*codec
= socdev
->codec
;
569 mutex_lock(&pcm_mutex
);
571 /* apply codec digital mute */
573 snd_soc_dai_digital_mute(codec_dai
, 1);
575 /* free any machine hw params */
576 if (machine
->ops
&& machine
->ops
->hw_free
)
577 machine
->ops
->hw_free(substream
);
579 /* free any DMA resources */
580 if (platform
->pcm_ops
->hw_free
)
581 platform
->pcm_ops
->hw_free(substream
);
583 /* now free hw params for the DAI's */
584 if (codec_dai
->ops
.hw_free
)
585 codec_dai
->ops
.hw_free(substream
);
587 if (cpu_dai
->ops
.hw_free
)
588 cpu_dai
->ops
.hw_free(substream
);
590 mutex_unlock(&pcm_mutex
);
594 static int soc_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
596 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
597 struct snd_soc_device
*socdev
= rtd
->socdev
;
598 struct snd_soc_dai_link
*machine
= rtd
->dai
;
599 struct snd_soc_platform
*platform
= socdev
->platform
;
600 struct snd_soc_dai
*cpu_dai
= machine
->cpu_dai
;
601 struct snd_soc_dai
*codec_dai
= machine
->codec_dai
;
604 if (codec_dai
->ops
.trigger
) {
605 ret
= codec_dai
->ops
.trigger(substream
, cmd
);
610 if (platform
->pcm_ops
->trigger
) {
611 ret
= platform
->pcm_ops
->trigger(substream
, cmd
);
616 if (cpu_dai
->ops
.trigger
) {
617 ret
= cpu_dai
->ops
.trigger(substream
, cmd
);
624 /* ASoC PCM operations */
625 static struct snd_pcm_ops soc_pcm_ops
= {
626 .open
= soc_pcm_open
,
627 .close
= soc_codec_close
,
628 .hw_params
= soc_pcm_hw_params
,
629 .hw_free
= soc_pcm_hw_free
,
630 .prepare
= soc_pcm_prepare
,
631 .trigger
= soc_pcm_trigger
,
635 /* powers down audio subsystem for suspend */
636 static int soc_suspend(struct platform_device
*pdev
, pm_message_t state
)
638 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
639 struct snd_soc_machine
*machine
= socdev
->machine
;
640 struct snd_soc_platform
*platform
= socdev
->platform
;
641 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
642 struct snd_soc_codec
*codec
= socdev
->codec
;
645 /* Due to the resume being scheduled into a workqueue we could
646 * suspend before that's finished - wait for it to complete.
648 snd_power_lock(codec
->card
);
649 snd_power_wait(codec
->card
, SNDRV_CTL_POWER_D0
);
650 snd_power_unlock(codec
->card
);
652 /* we're going to block userspace touching us until resume completes */
653 snd_power_change_state(codec
->card
, SNDRV_CTL_POWER_D3hot
);
655 /* mute any active DAC's */
656 for (i
= 0; i
< machine
->num_links
; i
++) {
657 struct snd_soc_dai
*dai
= machine
->dai_link
[i
].codec_dai
;
658 if (dai
->dai_ops
.digital_mute
&& dai
->playback
.active
)
659 dai
->dai_ops
.digital_mute(dai
, 1);
662 /* suspend all pcms */
663 for (i
= 0; i
< machine
->num_links
; i
++)
664 snd_pcm_suspend_all(machine
->dai_link
[i
].pcm
);
666 if (machine
->suspend_pre
)
667 machine
->suspend_pre(pdev
, state
);
669 for (i
= 0; i
< machine
->num_links
; i
++) {
670 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
671 if (cpu_dai
->suspend
&& cpu_dai
->type
!= SND_SOC_DAI_AC97
)
672 cpu_dai
->suspend(pdev
, cpu_dai
);
673 if (platform
->suspend
)
674 platform
->suspend(pdev
, cpu_dai
);
677 /* close any waiting streams and save state */
678 run_delayed_work(&socdev
->delayed_work
);
679 codec
->suspend_bias_level
= codec
->bias_level
;
681 for (i
= 0; i
< codec
->num_dai
; i
++) {
682 char *stream
= codec
->dai
[i
].playback
.stream_name
;
684 snd_soc_dapm_stream_event(codec
, stream
,
685 SND_SOC_DAPM_STREAM_SUSPEND
);
686 stream
= codec
->dai
[i
].capture
.stream_name
;
688 snd_soc_dapm_stream_event(codec
, stream
,
689 SND_SOC_DAPM_STREAM_SUSPEND
);
692 if (codec_dev
->suspend
)
693 codec_dev
->suspend(pdev
, state
);
695 for (i
= 0; i
< machine
->num_links
; i
++) {
696 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
697 if (cpu_dai
->suspend
&& cpu_dai
->type
== SND_SOC_DAI_AC97
)
698 cpu_dai
->suspend(pdev
, cpu_dai
);
701 if (machine
->suspend_post
)
702 machine
->suspend_post(pdev
, state
);
707 /* deferred resume work, so resume can complete before we finished
708 * setting our codec back up, which can be very slow on I2C
710 static void soc_resume_deferred(struct work_struct
*work
)
712 struct snd_soc_device
*socdev
= container_of(work
,
713 struct snd_soc_device
,
714 deferred_resume_work
);
715 struct snd_soc_machine
*machine
= socdev
->machine
;
716 struct snd_soc_platform
*platform
= socdev
->platform
;
717 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
718 struct snd_soc_codec
*codec
= socdev
->codec
;
719 struct platform_device
*pdev
= to_platform_device(socdev
->dev
);
722 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
723 * so userspace apps are blocked from touching us
726 dev_info(socdev
->dev
, "starting resume work\n");
728 if (machine
->resume_pre
)
729 machine
->resume_pre(pdev
);
731 for (i
= 0; i
< machine
->num_links
; i
++) {
732 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
733 if (cpu_dai
->resume
&& cpu_dai
->type
== SND_SOC_DAI_AC97
)
734 cpu_dai
->resume(pdev
, cpu_dai
);
737 if (codec_dev
->resume
)
738 codec_dev
->resume(pdev
);
740 for (i
= 0; i
< codec
->num_dai
; i
++) {
741 char *stream
= codec
->dai
[i
].playback
.stream_name
;
743 snd_soc_dapm_stream_event(codec
, stream
,
744 SND_SOC_DAPM_STREAM_RESUME
);
745 stream
= codec
->dai
[i
].capture
.stream_name
;
747 snd_soc_dapm_stream_event(codec
, stream
,
748 SND_SOC_DAPM_STREAM_RESUME
);
751 /* unmute any active DACs */
752 for (i
= 0; i
< machine
->num_links
; i
++) {
753 struct snd_soc_dai
*dai
= machine
->dai_link
[i
].codec_dai
;
754 if (dai
->dai_ops
.digital_mute
&& dai
->playback
.active
)
755 dai
->dai_ops
.digital_mute(dai
, 0);
758 for (i
= 0; i
< machine
->num_links
; i
++) {
759 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
760 if (cpu_dai
->resume
&& cpu_dai
->type
!= SND_SOC_DAI_AC97
)
761 cpu_dai
->resume(pdev
, cpu_dai
);
762 if (platform
->resume
)
763 platform
->resume(pdev
, cpu_dai
);
766 if (machine
->resume_post
)
767 machine
->resume_post(pdev
);
769 dev_info(socdev
->dev
, "resume work completed\n");
771 /* userspace can access us now we are back as we were before */
772 snd_power_change_state(codec
->card
, SNDRV_CTL_POWER_D0
);
775 /* powers up audio subsystem after a suspend */
776 static int soc_resume(struct platform_device
*pdev
)
778 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
780 dev_info(socdev
->dev
, "scheduling resume work\n");
782 if (!schedule_work(&socdev
->deferred_resume_work
))
783 dev_err(socdev
->dev
, "work item may be lost\n");
789 #define soc_suspend NULL
790 #define soc_resume NULL
793 /* probes a new socdev */
794 static int soc_probe(struct platform_device
*pdev
)
797 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
798 struct snd_soc_machine
*machine
= socdev
->machine
;
799 struct snd_soc_platform
*platform
= socdev
->platform
;
800 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
802 if (machine
->probe
) {
803 ret
= machine
->probe(pdev
);
808 for (i
= 0; i
< machine
->num_links
; i
++) {
809 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
810 if (cpu_dai
->probe
) {
811 ret
= cpu_dai
->probe(pdev
, cpu_dai
);
817 if (codec_dev
->probe
) {
818 ret
= codec_dev
->probe(pdev
);
823 if (platform
->probe
) {
824 ret
= platform
->probe(pdev
);
829 /* DAPM stream work */
830 INIT_DELAYED_WORK(&socdev
->delayed_work
, close_delayed_work
);
832 /* deferred resume work */
833 INIT_WORK(&socdev
->deferred_resume_work
, soc_resume_deferred
);
839 if (codec_dev
->remove
)
840 codec_dev
->remove(pdev
);
843 for (i
--; i
>= 0; i
--) {
844 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
846 cpu_dai
->remove(pdev
, cpu_dai
);
850 machine
->remove(pdev
);
855 /* removes a socdev */
856 static int soc_remove(struct platform_device
*pdev
)
859 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
860 struct snd_soc_machine
*machine
= socdev
->machine
;
861 struct snd_soc_platform
*platform
= socdev
->platform
;
862 struct snd_soc_codec_device
*codec_dev
= socdev
->codec_dev
;
864 run_delayed_work(&socdev
->delayed_work
);
866 if (platform
->remove
)
867 platform
->remove(pdev
);
869 if (codec_dev
->remove
)
870 codec_dev
->remove(pdev
);
872 for (i
= 0; i
< machine
->num_links
; i
++) {
873 struct snd_soc_dai
*cpu_dai
= machine
->dai_link
[i
].cpu_dai
;
875 cpu_dai
->remove(pdev
, cpu_dai
);
879 machine
->remove(pdev
);
884 /* ASoC platform driver */
885 static struct platform_driver soc_driver
= {
888 .owner
= THIS_MODULE
,
891 .remove
= soc_remove
,
892 .suspend
= soc_suspend
,
893 .resume
= soc_resume
,
896 /* create a new pcm */
897 static int soc_new_pcm(struct snd_soc_device
*socdev
,
898 struct snd_soc_dai_link
*dai_link
, int num
)
900 struct snd_soc_codec
*codec
= socdev
->codec
;
901 struct snd_soc_dai
*codec_dai
= dai_link
->codec_dai
;
902 struct snd_soc_dai
*cpu_dai
= dai_link
->cpu_dai
;
903 struct snd_soc_pcm_runtime
*rtd
;
906 int ret
= 0, playback
= 0, capture
= 0;
908 rtd
= kzalloc(sizeof(struct snd_soc_pcm_runtime
), GFP_KERNEL
);
913 rtd
->socdev
= socdev
;
914 codec_dai
->codec
= socdev
->codec
;
916 /* check client and interface hw capabilities */
917 sprintf(new_name
, "%s %s-%s-%d", dai_link
->stream_name
, codec_dai
->name
,
918 get_dai_name(cpu_dai
->type
), num
);
920 if (codec_dai
->playback
.channels_min
)
922 if (codec_dai
->capture
.channels_min
)
925 ret
= snd_pcm_new(codec
->card
, new_name
, codec
->pcm_devs
++, playback
,
928 printk(KERN_ERR
"asoc: can't create pcm for codec %s\n",
935 pcm
->private_data
= rtd
;
936 soc_pcm_ops
.mmap
= socdev
->platform
->pcm_ops
->mmap
;
937 soc_pcm_ops
.pointer
= socdev
->platform
->pcm_ops
->pointer
;
938 soc_pcm_ops
.ioctl
= socdev
->platform
->pcm_ops
->ioctl
;
939 soc_pcm_ops
.copy
= socdev
->platform
->pcm_ops
->copy
;
940 soc_pcm_ops
.silence
= socdev
->platform
->pcm_ops
->silence
;
941 soc_pcm_ops
.ack
= socdev
->platform
->pcm_ops
->ack
;
942 soc_pcm_ops
.page
= socdev
->platform
->pcm_ops
->page
;
945 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &soc_pcm_ops
);
948 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &soc_pcm_ops
);
950 ret
= socdev
->platform
->pcm_new(codec
->card
, codec_dai
, pcm
);
952 printk(KERN_ERR
"asoc: platform pcm constructor failed\n");
957 pcm
->private_free
= socdev
->platform
->pcm_free
;
958 printk(KERN_INFO
"asoc: %s <-> %s mapping ok\n", codec_dai
->name
,
963 /* codec register dump */
964 static ssize_t
codec_reg_show(struct device
*dev
,
965 struct device_attribute
*attr
, char *buf
)
967 struct snd_soc_device
*devdata
= dev_get_drvdata(dev
);
968 struct snd_soc_codec
*codec
= devdata
->codec
;
969 int i
, step
= 1, count
= 0;
971 if (!codec
->reg_cache_size
)
974 if (codec
->reg_cache_step
)
975 step
= codec
->reg_cache_step
;
977 count
+= sprintf(buf
, "%s registers\n", codec
->name
);
978 for (i
= 0; i
< codec
->reg_cache_size
; i
+= step
) {
979 count
+= sprintf(buf
+ count
, "%2x: ", i
);
980 if (count
>= PAGE_SIZE
- 1)
983 if (codec
->display_register
)
984 count
+= codec
->display_register(codec
, buf
+ count
,
985 PAGE_SIZE
- count
, i
);
987 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
,
988 "%4x", codec
->read(codec
, i
));
990 if (count
>= PAGE_SIZE
- 1)
993 count
+= snprintf(buf
+ count
, PAGE_SIZE
- count
, "\n");
994 if (count
>= PAGE_SIZE
- 1)
998 /* Truncate count; min() would cause a warning */
999 if (count
>= PAGE_SIZE
)
1000 count
= PAGE_SIZE
- 1;
1004 static DEVICE_ATTR(codec_reg
, 0444, codec_reg_show
, NULL
);
1007 * snd_soc_new_ac97_codec - initailise AC97 device
1008 * @codec: audio codec
1009 * @ops: AC97 bus operations
1010 * @num: AC97 codec number
1012 * Initialises AC97 codec resources for use by ad-hoc devices only.
1014 int snd_soc_new_ac97_codec(struct snd_soc_codec
*codec
,
1015 struct snd_ac97_bus_ops
*ops
, int num
)
1017 mutex_lock(&codec
->mutex
);
1019 codec
->ac97
= kzalloc(sizeof(struct snd_ac97
), GFP_KERNEL
);
1020 if (codec
->ac97
== NULL
) {
1021 mutex_unlock(&codec
->mutex
);
1025 codec
->ac97
->bus
= kzalloc(sizeof(struct snd_ac97_bus
), GFP_KERNEL
);
1026 if (codec
->ac97
->bus
== NULL
) {
1029 mutex_unlock(&codec
->mutex
);
1033 codec
->ac97
->bus
->ops
= ops
;
1034 codec
->ac97
->num
= num
;
1035 mutex_unlock(&codec
->mutex
);
1038 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec
);
1041 * snd_soc_free_ac97_codec - free AC97 codec device
1042 * @codec: audio codec
1044 * Frees AC97 codec device resources.
1046 void snd_soc_free_ac97_codec(struct snd_soc_codec
*codec
)
1048 mutex_lock(&codec
->mutex
);
1049 kfree(codec
->ac97
->bus
);
1052 mutex_unlock(&codec
->mutex
);
1054 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec
);
1057 * snd_soc_update_bits - update codec register bits
1058 * @codec: audio codec
1059 * @reg: codec register
1060 * @mask: register mask
1063 * Writes new register value.
1065 * Returns 1 for change else 0.
1067 int snd_soc_update_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1068 unsigned short mask
, unsigned short value
)
1071 unsigned short old
, new;
1073 mutex_lock(&io_mutex
);
1074 old
= snd_soc_read(codec
, reg
);
1075 new = (old
& ~mask
) | value
;
1076 change
= old
!= new;
1078 snd_soc_write(codec
, reg
, new);
1080 mutex_unlock(&io_mutex
);
1083 EXPORT_SYMBOL_GPL(snd_soc_update_bits
);
1086 * snd_soc_test_bits - test register for change
1087 * @codec: audio codec
1088 * @reg: codec register
1089 * @mask: register mask
1092 * Tests a register with a new value and checks if the new value is
1093 * different from the old value.
1095 * Returns 1 for change else 0.
1097 int snd_soc_test_bits(struct snd_soc_codec
*codec
, unsigned short reg
,
1098 unsigned short mask
, unsigned short value
)
1101 unsigned short old
, new;
1103 mutex_lock(&io_mutex
);
1104 old
= snd_soc_read(codec
, reg
);
1105 new = (old
& ~mask
) | value
;
1106 change
= old
!= new;
1107 mutex_unlock(&io_mutex
);
1111 EXPORT_SYMBOL_GPL(snd_soc_test_bits
);
1114 * snd_soc_new_pcms - create new sound card and pcms
1115 * @socdev: the SoC audio device
1117 * Create a new sound card based upon the codec and interface pcms.
1119 * Returns 0 for success, else error.
1121 int snd_soc_new_pcms(struct snd_soc_device
*socdev
, int idx
, const char *xid
)
1123 struct snd_soc_codec
*codec
= socdev
->codec
;
1124 struct snd_soc_machine
*machine
= socdev
->machine
;
1127 mutex_lock(&codec
->mutex
);
1129 /* register a sound card */
1130 codec
->card
= snd_card_new(idx
, xid
, codec
->owner
, 0);
1132 printk(KERN_ERR
"asoc: can't create sound card for codec %s\n",
1134 mutex_unlock(&codec
->mutex
);
1138 codec
->card
->dev
= socdev
->dev
;
1139 codec
->card
->private_data
= codec
;
1140 strncpy(codec
->card
->driver
, codec
->name
, sizeof(codec
->card
->driver
));
1142 /* create the pcms */
1143 for (i
= 0; i
< machine
->num_links
; i
++) {
1144 ret
= soc_new_pcm(socdev
, &machine
->dai_link
[i
], i
);
1146 printk(KERN_ERR
"asoc: can't create pcm %s\n",
1147 machine
->dai_link
[i
].stream_name
);
1148 mutex_unlock(&codec
->mutex
);
1153 mutex_unlock(&codec
->mutex
);
1156 EXPORT_SYMBOL_GPL(snd_soc_new_pcms
);
1159 * snd_soc_register_card - register sound card
1160 * @socdev: the SoC audio device
1162 * Register a SoC sound card. Also registers an AC97 device if the
1163 * codec is AC97 for ad hoc devices.
1165 * Returns 0 for success, else error.
1167 int snd_soc_register_card(struct snd_soc_device
*socdev
)
1169 struct snd_soc_codec
*codec
= socdev
->codec
;
1170 struct snd_soc_machine
*machine
= socdev
->machine
;
1171 int ret
= 0, i
, ac97
= 0, err
= 0;
1173 for (i
= 0; i
< machine
->num_links
; i
++) {
1174 if (socdev
->machine
->dai_link
[i
].init
) {
1175 err
= socdev
->machine
->dai_link
[i
].init(codec
);
1177 printk(KERN_ERR
"asoc: failed to init %s\n",
1178 socdev
->machine
->dai_link
[i
].stream_name
);
1182 if (socdev
->machine
->dai_link
[i
].codec_dai
->type
==
1183 SND_SOC_DAI_AC97_BUS
)
1186 snprintf(codec
->card
->shortname
, sizeof(codec
->card
->shortname
),
1187 "%s", machine
->name
);
1188 snprintf(codec
->card
->longname
, sizeof(codec
->card
->longname
),
1189 "%s (%s)", machine
->name
, codec
->name
);
1191 ret
= snd_card_register(codec
->card
);
1193 printk(KERN_ERR
"asoc: failed to register soundcard for %s\n",
1198 mutex_lock(&codec
->mutex
);
1199 #ifdef CONFIG_SND_SOC_AC97_BUS
1201 ret
= soc_ac97_dev_register(codec
);
1203 printk(KERN_ERR
"asoc: AC97 device register failed\n");
1204 snd_card_free(codec
->card
);
1205 mutex_unlock(&codec
->mutex
);
1211 err
= snd_soc_dapm_sys_add(socdev
->dev
);
1213 printk(KERN_WARNING
"asoc: failed to add dapm sysfs entries\n");
1215 err
= device_create_file(socdev
->dev
, &dev_attr_codec_reg
);
1217 printk(KERN_WARNING
"asoc: failed to add codec sysfs files\n");
1219 mutex_unlock(&codec
->mutex
);
1224 EXPORT_SYMBOL_GPL(snd_soc_register_card
);
1227 * snd_soc_free_pcms - free sound card and pcms
1228 * @socdev: the SoC audio device
1230 * Frees sound card and pcms associated with the socdev.
1231 * Also unregister the codec if it is an AC97 device.
1233 void snd_soc_free_pcms(struct snd_soc_device
*socdev
)
1235 struct snd_soc_codec
*codec
= socdev
->codec
;
1236 #ifdef CONFIG_SND_SOC_AC97_BUS
1237 struct snd_soc_dai
*codec_dai
;
1241 mutex_lock(&codec
->mutex
);
1242 #ifdef CONFIG_SND_SOC_AC97_BUS
1243 for (i
= 0; i
< codec
->num_dai
; i
++) {
1244 codec_dai
= &codec
->dai
[i
];
1245 if (codec_dai
->type
== SND_SOC_DAI_AC97_BUS
&& codec
->ac97
) {
1246 soc_ac97_dev_unregister(codec
);
1254 snd_card_free(codec
->card
);
1255 device_remove_file(socdev
->dev
, &dev_attr_codec_reg
);
1256 mutex_unlock(&codec
->mutex
);
1258 EXPORT_SYMBOL_GPL(snd_soc_free_pcms
);
1261 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1262 * @substream: the pcm substream
1263 * @hw: the hardware parameters
1265 * Sets the substream runtime hardware parameters.
1267 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream
*substream
,
1268 const struct snd_pcm_hardware
*hw
)
1270 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1271 runtime
->hw
.info
= hw
->info
;
1272 runtime
->hw
.formats
= hw
->formats
;
1273 runtime
->hw
.period_bytes_min
= hw
->period_bytes_min
;
1274 runtime
->hw
.period_bytes_max
= hw
->period_bytes_max
;
1275 runtime
->hw
.periods_min
= hw
->periods_min
;
1276 runtime
->hw
.periods_max
= hw
->periods_max
;
1277 runtime
->hw
.buffer_bytes_max
= hw
->buffer_bytes_max
;
1278 runtime
->hw
.fifo_size
= hw
->fifo_size
;
1281 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams
);
1284 * snd_soc_cnew - create new control
1285 * @_template: control template
1286 * @data: control private data
1287 * @lnng_name: control long name
1289 * Create a new mixer control from a template control.
1291 * Returns 0 for success, else error.
1293 struct snd_kcontrol
*snd_soc_cnew(const struct snd_kcontrol_new
*_template
,
1294 void *data
, char *long_name
)
1296 struct snd_kcontrol_new
template;
1298 memcpy(&template, _template
, sizeof(template));
1300 template.name
= long_name
;
1303 return snd_ctl_new1(&template, data
);
1305 EXPORT_SYMBOL_GPL(snd_soc_cnew
);
1308 * snd_soc_info_enum_double - enumerated double mixer info callback
1309 * @kcontrol: mixer control
1310 * @uinfo: control element information
1312 * Callback to provide information about a double enumerated
1315 * Returns 0 for success.
1317 int snd_soc_info_enum_double(struct snd_kcontrol
*kcontrol
,
1318 struct snd_ctl_elem_info
*uinfo
)
1320 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1322 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1323 uinfo
->count
= e
->shift_l
== e
->shift_r
? 1 : 2;
1324 uinfo
->value
.enumerated
.items
= e
->max
;
1326 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
1327 uinfo
->value
.enumerated
.item
= e
->max
- 1;
1328 strcpy(uinfo
->value
.enumerated
.name
,
1329 e
->texts
[uinfo
->value
.enumerated
.item
]);
1332 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double
);
1335 * snd_soc_get_enum_double - enumerated double mixer get callback
1336 * @kcontrol: mixer control
1337 * @uinfo: control element information
1339 * Callback to get the value of a double enumerated mixer.
1341 * Returns 0 for success.
1343 int snd_soc_get_enum_double(struct snd_kcontrol
*kcontrol
,
1344 struct snd_ctl_elem_value
*ucontrol
)
1346 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1347 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1348 unsigned short val
, bitmask
;
1350 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1352 val
= snd_soc_read(codec
, e
->reg
);
1353 ucontrol
->value
.enumerated
.item
[0]
1354 = (val
>> e
->shift_l
) & (bitmask
- 1);
1355 if (e
->shift_l
!= e
->shift_r
)
1356 ucontrol
->value
.enumerated
.item
[1] =
1357 (val
>> e
->shift_r
) & (bitmask
- 1);
1361 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double
);
1364 * snd_soc_put_enum_double - enumerated double mixer put callback
1365 * @kcontrol: mixer control
1366 * @uinfo: control element information
1368 * Callback to set the value of a double enumerated mixer.
1370 * Returns 0 for success.
1372 int snd_soc_put_enum_double(struct snd_kcontrol
*kcontrol
,
1373 struct snd_ctl_elem_value
*ucontrol
)
1375 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1376 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1378 unsigned short mask
, bitmask
;
1380 for (bitmask
= 1; bitmask
< e
->max
; bitmask
<<= 1)
1382 if (ucontrol
->value
.enumerated
.item
[0] > e
->max
- 1)
1384 val
= ucontrol
->value
.enumerated
.item
[0] << e
->shift_l
;
1385 mask
= (bitmask
- 1) << e
->shift_l
;
1386 if (e
->shift_l
!= e
->shift_r
) {
1387 if (ucontrol
->value
.enumerated
.item
[1] > e
->max
- 1)
1389 val
|= ucontrol
->value
.enumerated
.item
[1] << e
->shift_r
;
1390 mask
|= (bitmask
- 1) << e
->shift_r
;
1393 return snd_soc_update_bits(codec
, e
->reg
, mask
, val
);
1395 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double
);
1398 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1399 * @kcontrol: mixer control
1400 * @uinfo: control element information
1402 * Callback to provide information about an external enumerated
1405 * Returns 0 for success.
1407 int snd_soc_info_enum_ext(struct snd_kcontrol
*kcontrol
,
1408 struct snd_ctl_elem_info
*uinfo
)
1410 struct soc_enum
*e
= (struct soc_enum
*)kcontrol
->private_value
;
1412 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1414 uinfo
->value
.enumerated
.items
= e
->max
;
1416 if (uinfo
->value
.enumerated
.item
> e
->max
- 1)
1417 uinfo
->value
.enumerated
.item
= e
->max
- 1;
1418 strcpy(uinfo
->value
.enumerated
.name
,
1419 e
->texts
[uinfo
->value
.enumerated
.item
]);
1422 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext
);
1425 * snd_soc_info_volsw_ext - external single mixer info callback
1426 * @kcontrol: mixer control
1427 * @uinfo: control element information
1429 * Callback to provide information about a single external mixer control.
1431 * Returns 0 for success.
1433 int snd_soc_info_volsw_ext(struct snd_kcontrol
*kcontrol
,
1434 struct snd_ctl_elem_info
*uinfo
)
1436 int max
= kcontrol
->private_value
;
1439 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1441 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1444 uinfo
->value
.integer
.min
= 0;
1445 uinfo
->value
.integer
.max
= max
;
1448 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext
);
1451 * snd_soc_info_volsw - single mixer info callback
1452 * @kcontrol: mixer control
1453 * @uinfo: control element information
1455 * Callback to provide information about a single mixer control.
1457 * Returns 0 for success.
1459 int snd_soc_info_volsw(struct snd_kcontrol
*kcontrol
,
1460 struct snd_ctl_elem_info
*uinfo
)
1462 struct soc_mixer_control
*mc
=
1463 (struct soc_mixer_control
*)kcontrol
->private_value
;
1465 unsigned int shift
= mc
->shift
;
1466 unsigned int rshift
= mc
->rshift
;
1469 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1471 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1473 uinfo
->count
= shift
== rshift
? 1 : 2;
1474 uinfo
->value
.integer
.min
= 0;
1475 uinfo
->value
.integer
.max
= max
;
1478 EXPORT_SYMBOL_GPL(snd_soc_info_volsw
);
1481 * snd_soc_get_volsw - single mixer get callback
1482 * @kcontrol: mixer control
1483 * @uinfo: control element information
1485 * Callback to get the value of a single mixer control.
1487 * Returns 0 for success.
1489 int snd_soc_get_volsw(struct snd_kcontrol
*kcontrol
,
1490 struct snd_ctl_elem_value
*ucontrol
)
1492 struct soc_mixer_control
*mc
=
1493 (struct soc_mixer_control
*)kcontrol
->private_value
;
1494 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1495 unsigned int reg
= mc
->reg
;
1496 unsigned int shift
= mc
->shift
;
1497 unsigned int rshift
= mc
->rshift
;
1499 unsigned int mask
= (1 << fls(max
)) - 1;
1500 unsigned int invert
= mc
->invert
;
1502 ucontrol
->value
.integer
.value
[0] =
1503 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
1504 if (shift
!= rshift
)
1505 ucontrol
->value
.integer
.value
[1] =
1506 (snd_soc_read(codec
, reg
) >> rshift
) & mask
;
1508 ucontrol
->value
.integer
.value
[0] =
1509 max
- ucontrol
->value
.integer
.value
[0];
1510 if (shift
!= rshift
)
1511 ucontrol
->value
.integer
.value
[1] =
1512 max
- ucontrol
->value
.integer
.value
[1];
1517 EXPORT_SYMBOL_GPL(snd_soc_get_volsw
);
1520 * snd_soc_put_volsw - single mixer put callback
1521 * @kcontrol: mixer control
1522 * @uinfo: control element information
1524 * Callback to set the value of a single mixer control.
1526 * Returns 0 for success.
1528 int snd_soc_put_volsw(struct snd_kcontrol
*kcontrol
,
1529 struct snd_ctl_elem_value
*ucontrol
)
1531 struct soc_mixer_control
*mc
=
1532 (struct soc_mixer_control
*)kcontrol
->private_value
;
1533 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1534 unsigned int reg
= mc
->reg
;
1535 unsigned int shift
= mc
->shift
;
1536 unsigned int rshift
= mc
->rshift
;
1538 unsigned int mask
= (1 << fls(max
)) - 1;
1539 unsigned int invert
= mc
->invert
;
1540 unsigned short val
, val2
, val_mask
;
1542 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1545 val_mask
= mask
<< shift
;
1547 if (shift
!= rshift
) {
1548 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1551 val_mask
|= mask
<< rshift
;
1552 val
|= val2
<< rshift
;
1554 return snd_soc_update_bits(codec
, reg
, val_mask
, val
);
1556 EXPORT_SYMBOL_GPL(snd_soc_put_volsw
);
1559 * snd_soc_info_volsw_2r - double mixer info callback
1560 * @kcontrol: mixer control
1561 * @uinfo: control element information
1563 * Callback to provide information about a double mixer control that
1564 * spans 2 codec registers.
1566 * Returns 0 for success.
1568 int snd_soc_info_volsw_2r(struct snd_kcontrol
*kcontrol
,
1569 struct snd_ctl_elem_info
*uinfo
)
1571 struct soc_mixer_control
*mc
=
1572 (struct soc_mixer_control
*)kcontrol
->private_value
;
1576 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
1578 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1581 uinfo
->value
.integer
.min
= 0;
1582 uinfo
->value
.integer
.max
= max
;
1585 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r
);
1588 * snd_soc_get_volsw_2r - double mixer get callback
1589 * @kcontrol: mixer control
1590 * @uinfo: control element information
1592 * Callback to get the value of a double mixer control that spans 2 registers.
1594 * Returns 0 for success.
1596 int snd_soc_get_volsw_2r(struct snd_kcontrol
*kcontrol
,
1597 struct snd_ctl_elem_value
*ucontrol
)
1599 struct soc_mixer_control
*mc
=
1600 (struct soc_mixer_control
*)kcontrol
->private_value
;
1601 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1602 unsigned int reg
= mc
->reg
;
1603 unsigned int reg2
= mc
->rreg
;
1604 unsigned int shift
= mc
->shift
;
1606 unsigned int mask
= (1<<fls(max
))-1;
1607 unsigned int invert
= mc
->invert
;
1609 ucontrol
->value
.integer
.value
[0] =
1610 (snd_soc_read(codec
, reg
) >> shift
) & mask
;
1611 ucontrol
->value
.integer
.value
[1] =
1612 (snd_soc_read(codec
, reg2
) >> shift
) & mask
;
1614 ucontrol
->value
.integer
.value
[0] =
1615 max
- ucontrol
->value
.integer
.value
[0];
1616 ucontrol
->value
.integer
.value
[1] =
1617 max
- ucontrol
->value
.integer
.value
[1];
1622 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r
);
1625 * snd_soc_put_volsw_2r - double mixer set callback
1626 * @kcontrol: mixer control
1627 * @uinfo: control element information
1629 * Callback to set the value of a double mixer control that spans 2 registers.
1631 * Returns 0 for success.
1633 int snd_soc_put_volsw_2r(struct snd_kcontrol
*kcontrol
,
1634 struct snd_ctl_elem_value
*ucontrol
)
1636 struct soc_mixer_control
*mc
=
1637 (struct soc_mixer_control
*)kcontrol
->private_value
;
1638 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1639 unsigned int reg
= mc
->reg
;
1640 unsigned int reg2
= mc
->rreg
;
1641 unsigned int shift
= mc
->shift
;
1643 unsigned int mask
= (1 << fls(max
)) - 1;
1644 unsigned int invert
= mc
->invert
;
1646 unsigned short val
, val2
, val_mask
;
1648 val_mask
= mask
<< shift
;
1649 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1650 val2
= (ucontrol
->value
.integer
.value
[1] & mask
);
1658 val2
= val2
<< shift
;
1660 err
= snd_soc_update_bits(codec
, reg
, val_mask
, val
);
1664 err
= snd_soc_update_bits(codec
, reg2
, val_mask
, val2
);
1667 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r
);
1670 * snd_soc_info_volsw_s8 - signed mixer info callback
1671 * @kcontrol: mixer control
1672 * @uinfo: control element information
1674 * Callback to provide information about a signed mixer control.
1676 * Returns 0 for success.
1678 int snd_soc_info_volsw_s8(struct snd_kcontrol
*kcontrol
,
1679 struct snd_ctl_elem_info
*uinfo
)
1681 struct soc_mixer_control
*mc
=
1682 (struct soc_mixer_control
*)kcontrol
->private_value
;
1686 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1688 uinfo
->value
.integer
.min
= 0;
1689 uinfo
->value
.integer
.max
= max
-min
;
1692 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8
);
1695 * snd_soc_get_volsw_s8 - signed mixer get callback
1696 * @kcontrol: mixer control
1697 * @uinfo: control element information
1699 * Callback to get the value of a signed mixer control.
1701 * Returns 0 for success.
1703 int snd_soc_get_volsw_s8(struct snd_kcontrol
*kcontrol
,
1704 struct snd_ctl_elem_value
*ucontrol
)
1706 struct soc_mixer_control
*mc
=
1707 (struct soc_mixer_control
*)kcontrol
->private_value
;
1708 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1709 unsigned int reg
= mc
->reg
;
1711 int val
= snd_soc_read(codec
, reg
);
1713 ucontrol
->value
.integer
.value
[0] =
1714 ((signed char)(val
& 0xff))-min
;
1715 ucontrol
->value
.integer
.value
[1] =
1716 ((signed char)((val
>> 8) & 0xff))-min
;
1719 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8
);
1722 * snd_soc_put_volsw_sgn - signed mixer put callback
1723 * @kcontrol: mixer control
1724 * @uinfo: control element information
1726 * Callback to set the value of a signed mixer control.
1728 * Returns 0 for success.
1730 int snd_soc_put_volsw_s8(struct snd_kcontrol
*kcontrol
,
1731 struct snd_ctl_elem_value
*ucontrol
)
1733 struct soc_mixer_control
*mc
=
1734 (struct soc_mixer_control
*)kcontrol
->private_value
;
1735 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1736 unsigned int reg
= mc
->reg
;
1740 val
= (ucontrol
->value
.integer
.value
[0]+min
) & 0xff;
1741 val
|= ((ucontrol
->value
.integer
.value
[1]+min
) & 0xff) << 8;
1743 return snd_soc_update_bits(codec
, reg
, 0xffff, val
);
1745 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8
);
1748 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
1750 * @clk_id: DAI specific clock ID
1751 * @freq: new clock frequency in Hz
1752 * @dir: new clock direction - input/output.
1754 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
1756 int snd_soc_dai_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
,
1757 unsigned int freq
, int dir
)
1759 if (dai
->dai_ops
.set_sysclk
)
1760 return dai
->dai_ops
.set_sysclk(dai
, clk_id
, freq
, dir
);
1764 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk
);
1767 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
1769 * @clk_id: DAI specific clock divider ID
1770 * @div: new clock divisor.
1772 * Configures the clock dividers. This is used to derive the best DAI bit and
1773 * frame clocks from the system or master clock. It's best to set the DAI bit
1774 * and frame clocks as low as possible to save system power.
1776 int snd_soc_dai_set_clkdiv(struct snd_soc_dai
*dai
,
1777 int div_id
, int div
)
1779 if (dai
->dai_ops
.set_clkdiv
)
1780 return dai
->dai_ops
.set_clkdiv(dai
, div_id
, div
);
1784 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv
);
1787 * snd_soc_dai_set_pll - configure DAI PLL.
1789 * @pll_id: DAI specific PLL ID
1790 * @freq_in: PLL input clock frequency in Hz
1791 * @freq_out: requested PLL output clock frequency in Hz
1793 * Configures and enables PLL to generate output clock based on input clock.
1795 int snd_soc_dai_set_pll(struct snd_soc_dai
*dai
,
1796 int pll_id
, unsigned int freq_in
, unsigned int freq_out
)
1798 if (dai
->dai_ops
.set_pll
)
1799 return dai
->dai_ops
.set_pll(dai
, pll_id
, freq_in
, freq_out
);
1803 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll
);
1806 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
1808 * @clk_id: DAI specific clock ID
1809 * @fmt: SND_SOC_DAIFMT_ format value.
1811 * Configures the DAI hardware format and clocking.
1813 int snd_soc_dai_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
1815 if (dai
->dai_ops
.set_fmt
)
1816 return dai
->dai_ops
.set_fmt(dai
, fmt
);
1820 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt
);
1823 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
1825 * @mask: DAI specific mask representing used slots.
1826 * @slots: Number of slots in use.
1828 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
1831 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai
*dai
,
1832 unsigned int mask
, int slots
)
1834 if (dai
->dai_ops
.set_sysclk
)
1835 return dai
->dai_ops
.set_tdm_slot(dai
, mask
, slots
);
1839 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot
);
1842 * snd_soc_dai_set_tristate - configure DAI system or master clock.
1844 * @tristate: tristate enable
1846 * Tristates the DAI so that others can use it.
1848 int snd_soc_dai_set_tristate(struct snd_soc_dai
*dai
, int tristate
)
1850 if (dai
->dai_ops
.set_sysclk
)
1851 return dai
->dai_ops
.set_tristate(dai
, tristate
);
1855 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate
);
1858 * snd_soc_dai_digital_mute - configure DAI system or master clock.
1860 * @mute: mute enable
1862 * Mutes the DAI DAC.
1864 int snd_soc_dai_digital_mute(struct snd_soc_dai
*dai
, int mute
)
1866 if (dai
->dai_ops
.digital_mute
)
1867 return dai
->dai_ops
.digital_mute(dai
, mute
);
1871 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute
);
1873 static int __devinit
snd_soc_init(void)
1875 printk(KERN_INFO
"ASoC version %s\n", SND_SOC_VERSION
);
1876 return platform_driver_register(&soc_driver
);
1879 static void snd_soc_exit(void)
1881 platform_driver_unregister(&soc_driver
);
1884 module_init(snd_soc_init
);
1885 module_exit(snd_soc_exit
);
1887 /* Module information */
1888 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1889 MODULE_DESCRIPTION("ALSA SoC Core");
1890 MODULE_LICENSE("GPL");
1891 MODULE_ALIAS("platform:soc-audio");