2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
7 * Author: Liam Girdwood
8 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
9 * with code, comments and ideas from :-
10 * Richard Purdie <richard@openedhand.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 * o Add hw rules to enforce rates, etc.
19 * o More testing with other codecs/machines.
20 * o Add more codecs and platforms to ensure good API coverage.
21 * o Support TDM on PCM and I2S
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
29 #include <linux/bitops.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>
41 #define dbg(format, arg...) printk(format, ## arg)
43 #define dbg(format, arg...)
46 static DEFINE_MUTEX(pcm_mutex);
47 static DEFINE_MUTEX(io_mutex);
48 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
51 * This is a timeout to do a DAPM powerdown after a stream is closed().
52 * It can be used to eliminate pops between different playback streams, e.g.
53 * between two audio tracks.
55 static int pmdown_time = 5000;
56 module_param(pmdown_time, int, 0);
57 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
60 * This function forces any delayed work to be queued and run.
62 static int run_delayed_work(struct delayed_work *dwork)
66 /* cancel any work waiting to be queued. */
67 ret = cancel_delayed_work(dwork);
69 /* if there was any work waiting then we run it now and
70 * wait for it's completion */
72 schedule_delayed_work(dwork, 0);
73 flush_scheduled_work();
78 #ifdef CONFIG_SND_SOC_AC97_BUS
79 /* unregister ac97 codec */
80 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
82 if (codec->ac97->dev.bus)
83 device_unregister(&codec->ac97->dev);
87 /* stop no dev release warning */
88 static void soc_ac97_device_release(struct device *dev){}
90 /* register ac97 codec to bus */
91 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
95 codec->ac97->dev.bus = &ac97_bus_type;
96 codec->ac97->dev.parent = NULL;
97 codec->ac97->dev.release = soc_ac97_device_release;
99 snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
100 codec->card->number, 0, codec->name);
101 err = device_register(&codec->ac97->dev);
103 snd_printk(KERN_ERR "Can't register ac97 bus\n");
104 codec->ac97->dev.bus = NULL;
111 static inline const char *get_dai_name(int type)
114 case SND_SOC_DAI_AC97_BUS:
115 case SND_SOC_DAI_AC97:
117 case SND_SOC_DAI_I2S:
119 case SND_SOC_DAI_PCM:
126 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
127 * then initialized and any private data can be allocated. This also calls
128 * startup for the cpu DAI, platform, machine and codec DAI.
130 static int soc_pcm_open(struct snd_pcm_substream *substream)
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct snd_soc_device *socdev = rtd->socdev;
134 struct snd_pcm_runtime *runtime = substream->runtime;
135 struct snd_soc_dai_link *machine = rtd->dai;
136 struct snd_soc_platform *platform = socdev->platform;
137 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
138 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
141 mutex_lock(&pcm_mutex);
143 /* startup the audio subsystem */
144 if (cpu_dai->ops.startup) {
145 ret = cpu_dai->ops.startup(substream);
147 printk(KERN_ERR "asoc: can't open interface %s\n",
153 if (platform->pcm_ops->open) {
154 ret = platform->pcm_ops->open(substream);
156 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
161 if (codec_dai->ops.startup) {
162 ret = codec_dai->ops.startup(substream);
164 printk(KERN_ERR "asoc: can't open codec %s\n",
170 if (machine->ops && machine->ops->startup) {
171 ret = machine->ops->startup(substream);
173 printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
178 /* Check that the codec and cpu DAI's are compatible */
179 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
180 runtime->hw.rate_min =
181 max(codec_dai->playback.rate_min,
182 cpu_dai->playback.rate_min);
183 runtime->hw.rate_max =
184 min(codec_dai->playback.rate_max,
185 cpu_dai->playback.rate_max);
186 runtime->hw.channels_min =
187 max(codec_dai->playback.channels_min,
188 cpu_dai->playback.channels_min);
189 runtime->hw.channels_max =
190 min(codec_dai->playback.channels_max,
191 cpu_dai->playback.channels_max);
192 runtime->hw.formats =
193 codec_dai->playback.formats & cpu_dai->playback.formats;
195 codec_dai->playback.rates & cpu_dai->playback.rates;
197 runtime->hw.rate_min =
198 max(codec_dai->capture.rate_min,
199 cpu_dai->capture.rate_min);
200 runtime->hw.rate_max =
201 min(codec_dai->capture.rate_max,
202 cpu_dai->capture.rate_max);
203 runtime->hw.channels_min =
204 max(codec_dai->capture.channels_min,
205 cpu_dai->capture.channels_min);
206 runtime->hw.channels_max =
207 min(codec_dai->capture.channels_max,
208 cpu_dai->capture.channels_max);
209 runtime->hw.formats =
210 codec_dai->capture.formats & cpu_dai->capture.formats;
212 codec_dai->capture.rates & cpu_dai->capture.rates;
215 snd_pcm_limit_hw_rates(runtime);
216 if (!runtime->hw.rates) {
217 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
218 codec_dai->name, cpu_dai->name);
221 if (!runtime->hw.formats) {
222 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
223 codec_dai->name, cpu_dai->name);
226 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
227 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
228 codec_dai->name, cpu_dai->name);
232 dbg("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
233 dbg("asoc: rate mask 0x%x\n", runtime->hw.rates);
234 dbg("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
235 runtime->hw.channels_max);
236 dbg("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
237 runtime->hw.rate_max);
239 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
240 cpu_dai->playback.active = codec_dai->playback.active = 1;
242 cpu_dai->capture.active = codec_dai->capture.active = 1;
243 cpu_dai->active = codec_dai->active = 1;
244 cpu_dai->runtime = runtime;
245 socdev->codec->active++;
246 mutex_unlock(&pcm_mutex);
250 if (machine->ops && machine->ops->shutdown)
251 machine->ops->shutdown(substream);
254 if (platform->pcm_ops->close)
255 platform->pcm_ops->close(substream);
258 if (cpu_dai->ops.shutdown)
259 cpu_dai->ops.shutdown(substream);
261 mutex_unlock(&pcm_mutex);
266 * Power down the audio subsystem pmdown_time msecs after close is called.
267 * This is to ensure there are no pops or clicks in between any music tracks
268 * due to DAPM power cycling.
270 static void close_delayed_work(struct work_struct *work)
272 struct snd_soc_device *socdev =
273 container_of(work, struct snd_soc_device, delayed_work.work);
274 struct snd_soc_codec *codec = socdev->codec;
275 struct snd_soc_codec_dai *codec_dai;
278 mutex_lock(&pcm_mutex);
279 for (i = 0; i < codec->num_dai; i++) {
280 codec_dai = &codec->dai[i];
282 dbg("pop wq checking: %s status: %s waiting: %s\n",
283 codec_dai->playback.stream_name,
284 codec_dai->playback.active ? "active" : "inactive",
285 codec_dai->pop_wait ? "yes" : "no");
287 /* are we waiting on this codec DAI stream */
288 if (codec_dai->pop_wait == 1) {
290 /* Reduce power if no longer active */
291 if (codec->active == 0) {
292 dbg("pop wq D1 %s %s\n", codec->name,
293 codec_dai->playback.stream_name);
294 snd_soc_dapm_set_bias_level(socdev,
295 SND_SOC_BIAS_PREPARE);
298 codec_dai->pop_wait = 0;
299 snd_soc_dapm_stream_event(codec,
300 codec_dai->playback.stream_name,
301 SND_SOC_DAPM_STREAM_STOP);
303 /* Fall into standby if no longer active */
304 if (codec->active == 0) {
305 dbg("pop wq D3 %s %s\n", codec->name,
306 codec_dai->playback.stream_name);
307 snd_soc_dapm_set_bias_level(socdev,
308 SND_SOC_BIAS_STANDBY);
312 mutex_unlock(&pcm_mutex);
316 * Called by ALSA when a PCM substream is closed. Private data can be
317 * freed here. The cpu DAI, codec DAI, machine and platform are also
320 static int soc_codec_close(struct snd_pcm_substream *substream)
322 struct snd_soc_pcm_runtime *rtd = substream->private_data;
323 struct snd_soc_device *socdev = rtd->socdev;
324 struct snd_soc_dai_link *machine = rtd->dai;
325 struct snd_soc_platform *platform = socdev->platform;
326 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
327 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
328 struct snd_soc_codec *codec = socdev->codec;
330 mutex_lock(&pcm_mutex);
332 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
333 cpu_dai->playback.active = codec_dai->playback.active = 0;
335 cpu_dai->capture.active = codec_dai->capture.active = 0;
337 if (codec_dai->playback.active == 0 &&
338 codec_dai->capture.active == 0) {
339 cpu_dai->active = codec_dai->active = 0;
343 if (cpu_dai->ops.shutdown)
344 cpu_dai->ops.shutdown(substream);
346 if (codec_dai->ops.shutdown)
347 codec_dai->ops.shutdown(substream);
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(&socdev->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_dai_link *machine = rtd->dai;
386 struct snd_soc_platform *platform = socdev->platform;
387 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
388 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
389 struct snd_soc_codec *codec = socdev->codec;
392 mutex_lock(&pcm_mutex);
394 if (machine->ops && machine->ops->prepare) {
395 ret = machine->ops->prepare(substream);
397 printk(KERN_ERR "asoc: machine prepare error\n");
402 if (platform->pcm_ops->prepare) {
403 ret = platform->pcm_ops->prepare(substream);
405 printk(KERN_ERR "asoc: platform prepare error\n");
410 if (codec_dai->ops.prepare) {
411 ret = codec_dai->ops.prepare(substream);
413 printk(KERN_ERR "asoc: codec DAI prepare error\n");
418 if (cpu_dai->ops.prepare) {
419 ret = cpu_dai->ops.prepare(substream);
421 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
426 /* we only want to start a DAPM playback stream if we are not waiting
427 * on an existing one stopping */
428 if (codec_dai->pop_wait) {
429 /* we are waiting for the delayed work to start */
430 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
431 snd_soc_dapm_stream_event(socdev->codec,
432 codec_dai->capture.stream_name,
433 SND_SOC_DAPM_STREAM_START);
435 codec_dai->pop_wait = 0;
436 cancel_delayed_work(&socdev->delayed_work);
437 if (codec_dai->dai_ops.digital_mute)
438 codec_dai->dai_ops.digital_mute(codec_dai, 0);
441 /* no delayed work - do we need to power up codec */
442 if (codec->bias_level != SND_SOC_BIAS_ON) {
444 snd_soc_dapm_set_bias_level(socdev,
445 SND_SOC_BIAS_PREPARE);
447 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
448 snd_soc_dapm_stream_event(codec,
449 codec_dai->playback.stream_name,
450 SND_SOC_DAPM_STREAM_START);
452 snd_soc_dapm_stream_event(codec,
453 codec_dai->capture.stream_name,
454 SND_SOC_DAPM_STREAM_START);
456 snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
457 if (codec_dai->dai_ops.digital_mute)
458 codec_dai->dai_ops.digital_mute(codec_dai, 0);
461 /* codec already powered - power on widgets */
462 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
463 snd_soc_dapm_stream_event(codec,
464 codec_dai->playback.stream_name,
465 SND_SOC_DAPM_STREAM_START);
467 snd_soc_dapm_stream_event(codec,
468 codec_dai->capture.stream_name,
469 SND_SOC_DAPM_STREAM_START);
470 if (codec_dai->dai_ops.digital_mute)
471 codec_dai->dai_ops.digital_mute(codec_dai, 0);
476 mutex_unlock(&pcm_mutex);
481 * Called by ALSA when the hardware params are set by application. This
482 * function can also be called multiple times and can allocate buffers
483 * (using snd_pcm_lib_* ). It's non-atomic.
485 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
486 struct snd_pcm_hw_params *params)
488 struct snd_soc_pcm_runtime *rtd = substream->private_data;
489 struct snd_soc_device *socdev = rtd->socdev;
490 struct snd_soc_dai_link *machine = rtd->dai;
491 struct snd_soc_platform *platform = socdev->platform;
492 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
493 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
496 mutex_lock(&pcm_mutex);
498 if (machine->ops && machine->ops->hw_params) {
499 ret = machine->ops->hw_params(substream, params);
501 printk(KERN_ERR "asoc: machine hw_params failed\n");
506 if (codec_dai->ops.hw_params) {
507 ret = codec_dai->ops.hw_params(substream, params);
509 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
515 if (cpu_dai->ops.hw_params) {
516 ret = cpu_dai->ops.hw_params(substream, params);
518 printk(KERN_ERR "asoc: interface %s hw params failed\n",
524 if (platform->pcm_ops->hw_params) {
525 ret = platform->pcm_ops->hw_params(substream, params);
527 printk(KERN_ERR "asoc: platform %s hw params failed\n",
534 mutex_unlock(&pcm_mutex);
538 if (cpu_dai->ops.hw_free)
539 cpu_dai->ops.hw_free(substream);
542 if (codec_dai->ops.hw_free)
543 codec_dai->ops.hw_free(substream);
546 if (machine->ops && machine->ops->hw_free)
547 machine->ops->hw_free(substream);
549 mutex_unlock(&pcm_mutex);
554 * Free's resources allocated by hw_params, can be called multiple times
556 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
558 struct snd_soc_pcm_runtime *rtd = substream->private_data;
559 struct snd_soc_device *socdev = rtd->socdev;
560 struct snd_soc_dai_link *machine = rtd->dai;
561 struct snd_soc_platform *platform = socdev->platform;
562 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
563 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
564 struct snd_soc_codec *codec = socdev->codec;
566 mutex_lock(&pcm_mutex);
568 /* apply codec digital mute */
569 if (!codec->active && codec_dai->dai_ops.digital_mute)
570 codec_dai->dai_ops.digital_mute(codec_dai, 1);
572 /* free any machine hw params */
573 if (machine->ops && machine->ops->hw_free)
574 machine->ops->hw_free(substream);
576 /* free any DMA resources */
577 if (platform->pcm_ops->hw_free)
578 platform->pcm_ops->hw_free(substream);
580 /* now free hw params for the DAI's */
581 if (codec_dai->ops.hw_free)
582 codec_dai->ops.hw_free(substream);
584 if (cpu_dai->ops.hw_free)
585 cpu_dai->ops.hw_free(substream);
587 mutex_unlock(&pcm_mutex);
591 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
593 struct snd_soc_pcm_runtime *rtd = substream->private_data;
594 struct snd_soc_device *socdev = rtd->socdev;
595 struct snd_soc_dai_link *machine = rtd->dai;
596 struct snd_soc_platform *platform = socdev->platform;
597 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
598 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
601 if (codec_dai->ops.trigger) {
602 ret = codec_dai->ops.trigger(substream, cmd);
607 if (platform->pcm_ops->trigger) {
608 ret = platform->pcm_ops->trigger(substream, cmd);
613 if (cpu_dai->ops.trigger) {
614 ret = cpu_dai->ops.trigger(substream, cmd);
621 /* ASoC PCM operations */
622 static struct snd_pcm_ops soc_pcm_ops = {
623 .open = soc_pcm_open,
624 .close = soc_codec_close,
625 .hw_params = soc_pcm_hw_params,
626 .hw_free = soc_pcm_hw_free,
627 .prepare = soc_pcm_prepare,
628 .trigger = soc_pcm_trigger,
632 /* powers down audio subsystem for suspend */
633 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
635 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
636 struct snd_soc_machine *machine = socdev->machine;
637 struct snd_soc_platform *platform = socdev->platform;
638 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
639 struct snd_soc_codec *codec = socdev->codec;
642 /* mute any active DAC's */
643 for (i = 0; i < machine->num_links; i++) {
644 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
645 if (dai->dai_ops.digital_mute && dai->playback.active)
646 dai->dai_ops.digital_mute(dai, 1);
649 /* suspend all pcms */
650 for (i = 0; i < machine->num_links; i++)
651 snd_pcm_suspend_all(machine->dai_link[i].pcm);
653 if (machine->suspend_pre)
654 machine->suspend_pre(pdev, state);
656 for (i = 0; i < machine->num_links; i++) {
657 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
658 if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
659 cpu_dai->suspend(pdev, cpu_dai);
660 if (platform->suspend)
661 platform->suspend(pdev, cpu_dai);
664 /* close any waiting streams and save state */
665 run_delayed_work(&socdev->delayed_work);
666 codec->suspend_bias_level = codec->bias_level;
668 for (i = 0; i < codec->num_dai; i++) {
669 char *stream = codec->dai[i].playback.stream_name;
671 snd_soc_dapm_stream_event(codec, stream,
672 SND_SOC_DAPM_STREAM_SUSPEND);
673 stream = codec->dai[i].capture.stream_name;
675 snd_soc_dapm_stream_event(codec, stream,
676 SND_SOC_DAPM_STREAM_SUSPEND);
679 if (codec_dev->suspend)
680 codec_dev->suspend(pdev, state);
682 for (i = 0; i < machine->num_links; i++) {
683 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
684 if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
685 cpu_dai->suspend(pdev, cpu_dai);
688 if (machine->suspend_post)
689 machine->suspend_post(pdev, state);
694 /* powers up audio subsystem after a suspend */
695 static int soc_resume(struct platform_device *pdev)
697 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
698 struct snd_soc_machine *machine = socdev->machine;
699 struct snd_soc_platform *platform = socdev->platform;
700 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
701 struct snd_soc_codec *codec = socdev->codec;
704 if (machine->resume_pre)
705 machine->resume_pre(pdev);
707 for (i = 0; i < machine->num_links; i++) {
708 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
709 if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
710 cpu_dai->resume(pdev, cpu_dai);
713 if (codec_dev->resume)
714 codec_dev->resume(pdev);
716 for (i = 0; i < codec->num_dai; i++) {
717 char *stream = codec->dai[i].playback.stream_name;
719 snd_soc_dapm_stream_event(codec, stream,
720 SND_SOC_DAPM_STREAM_RESUME);
721 stream = codec->dai[i].capture.stream_name;
723 snd_soc_dapm_stream_event(codec, stream,
724 SND_SOC_DAPM_STREAM_RESUME);
727 /* unmute any active DACs */
728 for (i = 0; i < machine->num_links; i++) {
729 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
730 if (dai->dai_ops.digital_mute && dai->playback.active)
731 dai->dai_ops.digital_mute(dai, 0);
734 for (i = 0; i < machine->num_links; i++) {
735 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
736 if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
737 cpu_dai->resume(pdev, cpu_dai);
738 if (platform->resume)
739 platform->resume(pdev, cpu_dai);
742 if (machine->resume_post)
743 machine->resume_post(pdev);
749 #define soc_suspend NULL
750 #define soc_resume NULL
753 /* probes a new socdev */
754 static int soc_probe(struct platform_device *pdev)
757 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
758 struct snd_soc_machine *machine = socdev->machine;
759 struct snd_soc_platform *platform = socdev->platform;
760 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
762 if (machine->probe) {
763 ret = machine->probe(pdev);
768 for (i = 0; i < machine->num_links; i++) {
769 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
770 if (cpu_dai->probe) {
771 ret = cpu_dai->probe(pdev);
777 if (codec_dev->probe) {
778 ret = codec_dev->probe(pdev);
783 if (platform->probe) {
784 ret = platform->probe(pdev);
789 /* DAPM stream work */
790 INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
794 if (codec_dev->remove)
795 codec_dev->remove(pdev);
798 for (i--; i >= 0; i--) {
799 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
801 cpu_dai->remove(pdev);
805 machine->remove(pdev);
810 /* removes a socdev */
811 static int soc_remove(struct platform_device *pdev)
814 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
815 struct snd_soc_machine *machine = socdev->machine;
816 struct snd_soc_platform *platform = socdev->platform;
817 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
819 run_delayed_work(&socdev->delayed_work);
821 if (platform->remove)
822 platform->remove(pdev);
824 if (codec_dev->remove)
825 codec_dev->remove(pdev);
827 for (i = 0; i < machine->num_links; i++) {
828 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
830 cpu_dai->remove(pdev);
834 machine->remove(pdev);
839 /* ASoC platform driver */
840 static struct platform_driver soc_driver = {
843 .owner = THIS_MODULE,
846 .remove = soc_remove,
847 .suspend = soc_suspend,
848 .resume = soc_resume,
851 /* create a new pcm */
852 static int soc_new_pcm(struct snd_soc_device *socdev,
853 struct snd_soc_dai_link *dai_link, int num)
855 struct snd_soc_codec *codec = socdev->codec;
856 struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
857 struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
858 struct snd_soc_pcm_runtime *rtd;
861 int ret = 0, playback = 0, capture = 0;
863 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
868 rtd->socdev = socdev;
869 codec_dai->codec = socdev->codec;
871 /* check client and interface hw capabilities */
872 sprintf(new_name, "%s %s-%s-%d", dai_link->stream_name, codec_dai->name,
873 get_dai_name(cpu_dai->type), num);
875 if (codec_dai->playback.channels_min)
877 if (codec_dai->capture.channels_min)
880 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
883 printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
890 pcm->private_data = rtd;
891 soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
892 soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
893 soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
894 soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
895 soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
896 soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
897 soc_pcm_ops.page = socdev->platform->pcm_ops->page;
900 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
903 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
905 ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
907 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
912 pcm->private_free = socdev->platform->pcm_free;
913 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
918 /* codec register dump */
919 static ssize_t codec_reg_show(struct device *dev,
920 struct device_attribute *attr, char *buf)
922 struct snd_soc_device *devdata = dev_get_drvdata(dev);
923 struct snd_soc_codec *codec = devdata->codec;
924 int i, step = 1, count = 0;
926 if (!codec->reg_cache_size)
929 if (codec->reg_cache_step)
930 step = codec->reg_cache_step;
932 count += sprintf(buf, "%s registers\n", codec->name);
933 for (i = 0; i < codec->reg_cache_size; i += step)
934 count += sprintf(buf + count, "%2x: %4x\n", i,
935 codec->read(codec, i));
939 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
942 * snd_soc_new_ac97_codec - initailise AC97 device
943 * @codec: audio codec
944 * @ops: AC97 bus operations
945 * @num: AC97 codec number
947 * Initialises AC97 codec resources for use by ad-hoc devices only.
949 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
950 struct snd_ac97_bus_ops *ops, int num)
952 mutex_lock(&codec->mutex);
954 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
955 if (codec->ac97 == NULL) {
956 mutex_unlock(&codec->mutex);
960 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
961 if (codec->ac97->bus == NULL) {
964 mutex_unlock(&codec->mutex);
968 codec->ac97->bus->ops = ops;
969 codec->ac97->num = num;
970 mutex_unlock(&codec->mutex);
973 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
976 * snd_soc_free_ac97_codec - free AC97 codec device
977 * @codec: audio codec
979 * Frees AC97 codec device resources.
981 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
983 mutex_lock(&codec->mutex);
984 kfree(codec->ac97->bus);
987 mutex_unlock(&codec->mutex);
989 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
992 * snd_soc_update_bits - update codec register bits
993 * @codec: audio codec
994 * @reg: codec register
995 * @mask: register mask
998 * Writes new register value.
1000 * Returns 1 for change else 0.
1002 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1003 unsigned short mask, unsigned short value)
1006 unsigned short old, new;
1008 mutex_lock(&io_mutex);
1009 old = snd_soc_read(codec, reg);
1010 new = (old & ~mask) | value;
1011 change = old != new;
1013 snd_soc_write(codec, reg, new);
1015 mutex_unlock(&io_mutex);
1018 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1021 * snd_soc_test_bits - test register for change
1022 * @codec: audio codec
1023 * @reg: codec register
1024 * @mask: register mask
1027 * Tests a register with a new value and checks if the new value is
1028 * different from the old value.
1030 * Returns 1 for change else 0.
1032 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1033 unsigned short mask, unsigned short value)
1036 unsigned short old, new;
1038 mutex_lock(&io_mutex);
1039 old = snd_soc_read(codec, reg);
1040 new = (old & ~mask) | value;
1041 change = old != new;
1042 mutex_unlock(&io_mutex);
1046 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1049 * snd_soc_new_pcms - create new sound card and pcms
1050 * @socdev: the SoC audio device
1052 * Create a new sound card based upon the codec and interface pcms.
1054 * Returns 0 for success, else error.
1056 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1058 struct snd_soc_codec *codec = socdev->codec;
1059 struct snd_soc_machine *machine = socdev->machine;
1062 mutex_lock(&codec->mutex);
1064 /* register a sound card */
1065 codec->card = snd_card_new(idx, xid, codec->owner, 0);
1067 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1069 mutex_unlock(&codec->mutex);
1073 codec->card->dev = socdev->dev;
1074 codec->card->private_data = codec;
1075 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1077 /* create the pcms */
1078 for (i = 0; i < machine->num_links; i++) {
1079 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1081 printk(KERN_ERR "asoc: can't create pcm %s\n",
1082 machine->dai_link[i].stream_name);
1083 mutex_unlock(&codec->mutex);
1088 mutex_unlock(&codec->mutex);
1091 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1094 * snd_soc_register_card - register sound card
1095 * @socdev: the SoC audio device
1097 * Register a SoC sound card. Also registers an AC97 device if the
1098 * codec is AC97 for ad hoc devices.
1100 * Returns 0 for success, else error.
1102 int snd_soc_register_card(struct snd_soc_device *socdev)
1104 struct snd_soc_codec *codec = socdev->codec;
1105 struct snd_soc_machine *machine = socdev->machine;
1106 int ret = 0, i, ac97 = 0, err = 0;
1108 for (i = 0; i < machine->num_links; i++) {
1109 if (socdev->machine->dai_link[i].init) {
1110 err = socdev->machine->dai_link[i].init(codec);
1112 printk(KERN_ERR "asoc: failed to init %s\n",
1113 socdev->machine->dai_link[i].stream_name);
1117 if (socdev->machine->dai_link[i].codec_dai->type ==
1118 SND_SOC_DAI_AC97_BUS)
1121 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1122 "%s", machine->name);
1123 snprintf(codec->card->longname, sizeof(codec->card->longname),
1124 "%s (%s)", machine->name, codec->name);
1126 ret = snd_card_register(codec->card);
1128 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1133 mutex_lock(&codec->mutex);
1134 #ifdef CONFIG_SND_SOC_AC97_BUS
1136 ret = soc_ac97_dev_register(codec);
1138 printk(KERN_ERR "asoc: AC97 device register failed\n");
1139 snd_card_free(codec->card);
1140 mutex_unlock(&codec->mutex);
1146 err = snd_soc_dapm_sys_add(socdev->dev);
1148 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1150 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1152 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1154 mutex_unlock(&codec->mutex);
1159 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1162 * snd_soc_free_pcms - free sound card and pcms
1163 * @socdev: the SoC audio device
1165 * Frees sound card and pcms associated with the socdev.
1166 * Also unregister the codec if it is an AC97 device.
1168 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1170 struct snd_soc_codec *codec = socdev->codec;
1171 #ifdef CONFIG_SND_SOC_AC97_BUS
1172 struct snd_soc_codec_dai *codec_dai;
1176 mutex_lock(&codec->mutex);
1177 #ifdef CONFIG_SND_SOC_AC97_BUS
1178 for (i = 0; i < codec->num_dai; i++) {
1179 codec_dai = &codec->dai[i];
1180 if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
1181 soc_ac97_dev_unregister(codec);
1189 snd_card_free(codec->card);
1190 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1191 mutex_unlock(&codec->mutex);
1193 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1196 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1197 * @substream: the pcm substream
1198 * @hw: the hardware parameters
1200 * Sets the substream runtime hardware parameters.
1202 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1203 const struct snd_pcm_hardware *hw)
1205 struct snd_pcm_runtime *runtime = substream->runtime;
1206 runtime->hw.info = hw->info;
1207 runtime->hw.formats = hw->formats;
1208 runtime->hw.period_bytes_min = hw->period_bytes_min;
1209 runtime->hw.period_bytes_max = hw->period_bytes_max;
1210 runtime->hw.periods_min = hw->periods_min;
1211 runtime->hw.periods_max = hw->periods_max;
1212 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1213 runtime->hw.fifo_size = hw->fifo_size;
1216 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1219 * snd_soc_cnew - create new control
1220 * @_template: control template
1221 * @data: control private data
1222 * @lnng_name: control long name
1224 * Create a new mixer control from a template control.
1226 * Returns 0 for success, else error.
1228 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1229 void *data, char *long_name)
1231 struct snd_kcontrol_new template;
1233 memcpy(&template, _template, sizeof(template));
1235 template.name = long_name;
1238 return snd_ctl_new1(&template, data);
1240 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1243 * snd_soc_info_enum_double - enumerated double mixer info callback
1244 * @kcontrol: mixer control
1245 * @uinfo: control element information
1247 * Callback to provide information about a double enumerated
1250 * Returns 0 for success.
1252 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1253 struct snd_ctl_elem_info *uinfo)
1255 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1257 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1258 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1259 uinfo->value.enumerated.items = e->mask;
1261 if (uinfo->value.enumerated.item > e->mask - 1)
1262 uinfo->value.enumerated.item = e->mask - 1;
1263 strcpy(uinfo->value.enumerated.name,
1264 e->texts[uinfo->value.enumerated.item]);
1267 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1270 * snd_soc_get_enum_double - enumerated double mixer get callback
1271 * @kcontrol: mixer control
1272 * @uinfo: control element information
1274 * Callback to get the value of a double enumerated mixer.
1276 * Returns 0 for success.
1278 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1279 struct snd_ctl_elem_value *ucontrol)
1281 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1282 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1283 unsigned short val, bitmask;
1285 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1287 val = snd_soc_read(codec, e->reg);
1288 ucontrol->value.enumerated.item[0]
1289 = (val >> e->shift_l) & (bitmask - 1);
1290 if (e->shift_l != e->shift_r)
1291 ucontrol->value.enumerated.item[1] =
1292 (val >> e->shift_r) & (bitmask - 1);
1296 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1299 * snd_soc_put_enum_double - enumerated double mixer put callback
1300 * @kcontrol: mixer control
1301 * @uinfo: control element information
1303 * Callback to set the value of a double enumerated mixer.
1305 * Returns 0 for success.
1307 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1308 struct snd_ctl_elem_value *ucontrol)
1310 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1311 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1313 unsigned short mask, bitmask;
1315 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1317 if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1319 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1320 mask = (bitmask - 1) << e->shift_l;
1321 if (e->shift_l != e->shift_r) {
1322 if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1324 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1325 mask |= (bitmask - 1) << e->shift_r;
1328 return snd_soc_update_bits(codec, e->reg, mask, val);
1330 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1333 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1334 * @kcontrol: mixer control
1335 * @uinfo: control element information
1337 * Callback to provide information about an external enumerated
1340 * Returns 0 for success.
1342 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1343 struct snd_ctl_elem_info *uinfo)
1345 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1347 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1349 uinfo->value.enumerated.items = e->mask;
1351 if (uinfo->value.enumerated.item > e->mask - 1)
1352 uinfo->value.enumerated.item = e->mask - 1;
1353 strcpy(uinfo->value.enumerated.name,
1354 e->texts[uinfo->value.enumerated.item]);
1357 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1360 * snd_soc_info_volsw_ext - external single mixer info callback
1361 * @kcontrol: mixer control
1362 * @uinfo: control element information
1364 * Callback to provide information about a single external mixer control.
1366 * Returns 0 for success.
1368 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1369 struct snd_ctl_elem_info *uinfo)
1371 int max = kcontrol->private_value;
1374 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1376 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1379 uinfo->value.integer.min = 0;
1380 uinfo->value.integer.max = max;
1383 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1386 * snd_soc_info_volsw - single mixer info callback
1387 * @kcontrol: mixer control
1388 * @uinfo: control element information
1390 * Callback to provide information about a single mixer control.
1392 * Returns 0 for success.
1394 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1395 struct snd_ctl_elem_info *uinfo)
1397 int max = (kcontrol->private_value >> 16) & 0xff;
1398 int shift = (kcontrol->private_value >> 8) & 0x0f;
1399 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1402 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1404 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1406 uinfo->count = shift == rshift ? 1 : 2;
1407 uinfo->value.integer.min = 0;
1408 uinfo->value.integer.max = max;
1411 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1414 * snd_soc_get_volsw - single mixer get callback
1415 * @kcontrol: mixer control
1416 * @uinfo: control element information
1418 * Callback to get the value of a single mixer control.
1420 * Returns 0 for success.
1422 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol)
1425 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1426 int reg = kcontrol->private_value & 0xff;
1427 int shift = (kcontrol->private_value >> 8) & 0x0f;
1428 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1429 int max = (kcontrol->private_value >> 16) & 0xff;
1430 int mask = (1 << fls(max)) - 1;
1431 int invert = (kcontrol->private_value >> 24) & 0x01;
1433 ucontrol->value.integer.value[0] =
1434 (snd_soc_read(codec, reg) >> shift) & mask;
1435 if (shift != rshift)
1436 ucontrol->value.integer.value[1] =
1437 (snd_soc_read(codec, reg) >> rshift) & mask;
1439 ucontrol->value.integer.value[0] =
1440 max - ucontrol->value.integer.value[0];
1441 if (shift != rshift)
1442 ucontrol->value.integer.value[1] =
1443 max - ucontrol->value.integer.value[1];
1448 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1451 * snd_soc_put_volsw - single mixer put callback
1452 * @kcontrol: mixer control
1453 * @uinfo: control element information
1455 * Callback to set the value of a single mixer control.
1457 * Returns 0 for success.
1459 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1460 struct snd_ctl_elem_value *ucontrol)
1462 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1463 int reg = kcontrol->private_value & 0xff;
1464 int shift = (kcontrol->private_value >> 8) & 0x0f;
1465 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1466 int max = (kcontrol->private_value >> 16) & 0xff;
1467 int mask = (1 << fls(max)) - 1;
1468 int invert = (kcontrol->private_value >> 24) & 0x01;
1469 unsigned short val, val2, val_mask;
1471 val = (ucontrol->value.integer.value[0] & mask);
1474 val_mask = mask << shift;
1476 if (shift != rshift) {
1477 val2 = (ucontrol->value.integer.value[1] & mask);
1480 val_mask |= mask << rshift;
1481 val |= val2 << rshift;
1483 return snd_soc_update_bits(codec, reg, val_mask, val);
1485 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1488 * snd_soc_info_volsw_2r - double mixer info callback
1489 * @kcontrol: mixer control
1490 * @uinfo: control element information
1492 * Callback to provide information about a double mixer control that
1493 * spans 2 codec registers.
1495 * Returns 0 for success.
1497 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1498 struct snd_ctl_elem_info *uinfo)
1500 int max = (kcontrol->private_value >> 12) & 0xff;
1503 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1505 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1508 uinfo->value.integer.min = 0;
1509 uinfo->value.integer.max = max;
1512 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1515 * snd_soc_get_volsw_2r - double mixer get callback
1516 * @kcontrol: mixer control
1517 * @uinfo: control element information
1519 * Callback to get the value of a double mixer control that spans 2 registers.
1521 * Returns 0 for success.
1523 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1524 struct snd_ctl_elem_value *ucontrol)
1526 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1527 int reg = kcontrol->private_value & 0xff;
1528 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1529 int shift = (kcontrol->private_value >> 8) & 0x0f;
1530 int max = (kcontrol->private_value >> 12) & 0xff;
1531 int mask = (1<<fls(max))-1;
1532 int invert = (kcontrol->private_value >> 20) & 0x01;
1534 ucontrol->value.integer.value[0] =
1535 (snd_soc_read(codec, reg) >> shift) & mask;
1536 ucontrol->value.integer.value[1] =
1537 (snd_soc_read(codec, reg2) >> shift) & mask;
1539 ucontrol->value.integer.value[0] =
1540 max - ucontrol->value.integer.value[0];
1541 ucontrol->value.integer.value[1] =
1542 max - ucontrol->value.integer.value[1];
1547 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1550 * snd_soc_put_volsw_2r - double mixer set callback
1551 * @kcontrol: mixer control
1552 * @uinfo: control element information
1554 * Callback to set the value of a double mixer control that spans 2 registers.
1556 * Returns 0 for success.
1558 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1559 struct snd_ctl_elem_value *ucontrol)
1561 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1562 int reg = kcontrol->private_value & 0xff;
1563 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1564 int shift = (kcontrol->private_value >> 8) & 0x0f;
1565 int max = (kcontrol->private_value >> 12) & 0xff;
1566 int mask = (1 << fls(max)) - 1;
1567 int invert = (kcontrol->private_value >> 20) & 0x01;
1569 unsigned short val, val2, val_mask;
1571 val_mask = mask << shift;
1572 val = (ucontrol->value.integer.value[0] & mask);
1573 val2 = (ucontrol->value.integer.value[1] & mask);
1581 val2 = val2 << shift;
1583 err = snd_soc_update_bits(codec, reg, val_mask, val);
1587 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1590 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1592 static int __devinit snd_soc_init(void)
1594 printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1595 return platform_driver_register(&soc_driver);
1598 static void snd_soc_exit(void)
1600 platform_driver_unregister(&soc_driver);
1603 module_init(snd_soc_init);
1604 module_exit(snd_soc_exit);
1606 /* Module information */
1607 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1608 MODULE_DESCRIPTION("ALSA SoC Core");
1609 MODULE_LICENSE("GPL");
1610 MODULE_ALIAS("platform:soc-audio");