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 * 12th Aug 2005 Initial version.
19 * 25th Oct 2005 Working Codec, Interface and Platform registration.
22 * o Add hw rules to enforce rates, etc.
23 * o More testing with other codecs/machines.
24 * o Add more codecs and platforms to ensure good API coverage.
25 * o Support TDM on PCM and I2S
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include <linux/init.h>
31 #include <linux/delay.h>
33 #include <linux/bitops.h>
34 #include <linux/platform_device.h>
35 #include <sound/driver.h>
36 #include <sound/core.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/soc.h>
40 #include <sound/soc-dapm.h>
41 #include <sound/initval.h>
46 #define dbg(format, arg...) printk(format, ## arg)
48 #define dbg(format, arg...)
51 static DEFINE_MUTEX(pcm_mutex);
52 static DEFINE_MUTEX(io_mutex);
53 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
56 * This is a timeout to do a DAPM powerdown after a stream is closed().
57 * It can be used to eliminate pops between different playback streams, e.g.
58 * between two audio tracks.
60 static int pmdown_time = 5000;
61 module_param(pmdown_time, int, 0);
62 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
65 * This function forces any delayed work to be queued and run.
67 static int run_delayed_work(struct delayed_work *dwork)
71 /* cancel any work waiting to be queued. */
72 ret = cancel_delayed_work(dwork);
74 /* if there was any work waiting then we run it now and
75 * wait for it's completion */
77 schedule_delayed_work(dwork, 0);
78 flush_scheduled_work();
83 #ifdef CONFIG_SND_SOC_AC97_BUS
84 /* unregister ac97 codec */
85 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
87 if (codec->ac97->dev.bus)
88 device_unregister(&codec->ac97->dev);
92 /* stop no dev release warning */
93 static void soc_ac97_device_release(struct device *dev){}
95 /* register ac97 codec to bus */
96 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
100 codec->ac97->dev.bus = &ac97_bus_type;
101 codec->ac97->dev.parent = NULL;
102 codec->ac97->dev.release = soc_ac97_device_release;
104 snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
105 codec->card->number, 0, codec->name);
106 err = device_register(&codec->ac97->dev);
108 snd_printk(KERN_ERR "Can't register ac97 bus\n");
109 codec->ac97->dev.bus = NULL;
116 static inline const char* get_dai_name(int type)
119 case SND_SOC_DAI_AC97:
121 case SND_SOC_DAI_I2S:
123 case SND_SOC_DAI_PCM:
130 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
131 * then initialized and any private data can be allocated. This also calls
132 * startup for the cpu DAI, platform, machine and codec DAI.
134 static int soc_pcm_open(struct snd_pcm_substream *substream)
136 struct snd_soc_pcm_runtime *rtd = substream->private_data;
137 struct snd_soc_device *socdev = rtd->socdev;
138 struct snd_pcm_runtime *runtime = substream->runtime;
139 struct snd_soc_dai_link *machine = rtd->dai;
140 struct snd_soc_platform *platform = socdev->platform;
141 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
142 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
145 mutex_lock(&pcm_mutex);
147 /* startup the audio subsystem */
148 if (cpu_dai->ops.startup) {
149 ret = cpu_dai->ops.startup(substream);
151 printk(KERN_ERR "asoc: can't open interface %s\n",
157 if (platform->pcm_ops->open) {
158 ret = platform->pcm_ops->open(substream);
160 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
165 if (codec_dai->ops.startup) {
166 ret = codec_dai->ops.startup(substream);
168 printk(KERN_ERR "asoc: can't open codec %s\n",
174 if (machine->ops && machine->ops->startup) {
175 ret = machine->ops->startup(substream);
177 printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
182 /* Check that the codec and cpu DAI's are compatible */
183 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
184 runtime->hw.rate_min =
185 max(codec_dai->playback.rate_min, cpu_dai->playback.rate_min);
186 runtime->hw.rate_max =
187 min(codec_dai->playback.rate_max, cpu_dai->playback.rate_max);
188 runtime->hw.channels_min =
189 max(codec_dai->playback.channels_min,
190 cpu_dai->playback.channels_min);
191 runtime->hw.channels_max =
192 min(codec_dai->playback.channels_max,
193 cpu_dai->playback.channels_max);
194 runtime->hw.formats =
195 codec_dai->playback.formats & cpu_dai->playback.formats;
197 codec_dai->playback.rates & cpu_dai->playback.rates;
199 runtime->hw.rate_min =
200 max(codec_dai->capture.rate_min, cpu_dai->capture.rate_min);
201 runtime->hw.rate_max =
202 min(codec_dai->capture.rate_max, 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 subsytem 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 codec_dai->pop_wait = 0;
291 snd_soc_dapm_stream_event(codec, codec_dai->playback.stream_name,
292 SND_SOC_DAPM_STREAM_STOP);
294 /* power down the codec power domain if no longer active */
295 if (codec->active == 0) {
296 dbg("pop wq D3 %s %s\n", codec->name,
297 codec_dai->playback.stream_name);
298 if (codec->dapm_event)
299 codec->dapm_event(codec, SNDRV_CTL_POWER_D3hot);
303 mutex_unlock(&pcm_mutex);
307 * Called by ALSA when a PCM substream is closed. Private data can be
308 * freed here. The cpu DAI, codec DAI, machine and platform are also
311 static int soc_codec_close(struct snd_pcm_substream *substream)
313 struct snd_soc_pcm_runtime *rtd = substream->private_data;
314 struct snd_soc_device *socdev = rtd->socdev;
315 struct snd_soc_dai_link *machine = rtd->dai;
316 struct snd_soc_platform *platform = socdev->platform;
317 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
318 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
319 struct snd_soc_codec *codec = socdev->codec;
321 mutex_lock(&pcm_mutex);
323 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
324 cpu_dai->playback.active = codec_dai->playback.active = 0;
326 cpu_dai->capture.active = codec_dai->capture.active = 0;
328 if (codec_dai->playback.active == 0 &&
329 codec_dai->capture.active == 0) {
330 cpu_dai->active = codec_dai->active = 0;
334 if (cpu_dai->ops.shutdown)
335 cpu_dai->ops.shutdown(substream);
337 if (codec_dai->ops.shutdown)
338 codec_dai->ops.shutdown(substream);
340 if (machine->ops && machine->ops->shutdown)
341 machine->ops->shutdown(substream);
343 if (platform->pcm_ops->close)
344 platform->pcm_ops->close(substream);
345 cpu_dai->runtime = NULL;
347 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
348 /* start delayed pop wq here for playback streams */
349 codec_dai->pop_wait = 1;
350 schedule_delayed_work(&socdev->delayed_work,
351 msecs_to_jiffies(pmdown_time));
353 /* capture streams can be powered down now */
354 snd_soc_dapm_stream_event(codec,
355 codec_dai->capture.stream_name, SND_SOC_DAPM_STREAM_STOP);
357 if (codec->active == 0 && codec_dai->pop_wait == 0){
358 if (codec->dapm_event)
359 codec->dapm_event(codec, SNDRV_CTL_POWER_D3hot);
363 mutex_unlock(&pcm_mutex);
368 * Called by ALSA when the PCM substream is prepared, can set format, sample
369 * rate, etc. This function is non atomic and can be called multiple times,
370 * it can refer to the runtime info.
372 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
374 struct snd_soc_pcm_runtime *rtd = substream->private_data;
375 struct snd_soc_device *socdev = rtd->socdev;
376 struct snd_soc_dai_link *machine = rtd->dai;
377 struct snd_soc_platform *platform = socdev->platform;
378 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
379 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
380 struct snd_soc_codec *codec = socdev->codec;
383 mutex_lock(&pcm_mutex);
385 if (machine->ops && machine->ops->prepare) {
386 ret = machine->ops->prepare(substream);
388 printk(KERN_ERR "asoc: machine prepare error\n");
393 if (platform->pcm_ops->prepare) {
394 ret = platform->pcm_ops->prepare(substream);
396 printk(KERN_ERR "asoc: platform prepare error\n");
401 if (codec_dai->ops.prepare) {
402 ret = codec_dai->ops.prepare(substream);
404 printk(KERN_ERR "asoc: codec DAI prepare error\n");
409 if (cpu_dai->ops.prepare) {
410 ret = cpu_dai->ops.prepare(substream);
412 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
417 /* we only want to start a DAPM playback stream if we are not waiting
418 * on an existing one stopping */
419 if (codec_dai->pop_wait) {
420 /* we are waiting for the delayed work to start */
421 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
422 snd_soc_dapm_stream_event(socdev->codec,
423 codec_dai->capture.stream_name,
424 SND_SOC_DAPM_STREAM_START);
426 codec_dai->pop_wait = 0;
427 cancel_delayed_work(&socdev->delayed_work);
428 if (codec_dai->dai_ops.digital_mute)
429 codec_dai->dai_ops.digital_mute(codec_dai, 0);
432 /* no delayed work - do we need to power up codec */
433 if (codec->dapm_state != SNDRV_CTL_POWER_D0) {
435 if (codec->dapm_event)
436 codec->dapm_event(codec, SNDRV_CTL_POWER_D1);
438 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
439 snd_soc_dapm_stream_event(codec,
440 codec_dai->playback.stream_name,
441 SND_SOC_DAPM_STREAM_START);
443 snd_soc_dapm_stream_event(codec,
444 codec_dai->capture.stream_name,
445 SND_SOC_DAPM_STREAM_START);
447 if (codec->dapm_event)
448 codec->dapm_event(codec, SNDRV_CTL_POWER_D0);
449 if (codec_dai->dai_ops.digital_mute)
450 codec_dai->dai_ops.digital_mute(codec_dai, 0);
453 /* codec already powered - power on widgets */
454 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
455 snd_soc_dapm_stream_event(codec,
456 codec_dai->playback.stream_name,
457 SND_SOC_DAPM_STREAM_START);
459 snd_soc_dapm_stream_event(codec,
460 codec_dai->capture.stream_name,
461 SND_SOC_DAPM_STREAM_START);
462 if (codec_dai->dai_ops.digital_mute)
463 codec_dai->dai_ops.digital_mute(codec_dai, 0);
468 mutex_unlock(&pcm_mutex);
473 * Called by ALSA when the hardware params are set by application. This
474 * function can also be called multiple times and can allocate buffers
475 * (using snd_pcm_lib_* ). It's non-atomic.
477 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
478 struct snd_pcm_hw_params *params)
480 struct snd_soc_pcm_runtime *rtd = substream->private_data;
481 struct snd_soc_device *socdev = rtd->socdev;
482 struct snd_soc_dai_link *machine = rtd->dai;
483 struct snd_soc_platform *platform = socdev->platform;
484 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
485 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
488 mutex_lock(&pcm_mutex);
490 if (machine->ops && machine->ops->hw_params) {
491 ret = machine->ops->hw_params(substream, params);
493 printk(KERN_ERR "asoc: machine hw_params failed\n");
498 if (codec_dai->ops.hw_params) {
499 ret = codec_dai->ops.hw_params(substream, params);
501 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
507 if (cpu_dai->ops.hw_params) {
508 ret = cpu_dai->ops.hw_params(substream, params);
510 printk(KERN_ERR "asoc: can't set interface %s hw params\n",
516 if (platform->pcm_ops->hw_params) {
517 ret = platform->pcm_ops->hw_params(substream, params);
519 printk(KERN_ERR "asoc: can't set platform %s hw params\n",
526 mutex_unlock(&pcm_mutex);
530 if (cpu_dai->ops.hw_free)
531 cpu_dai->ops.hw_free(substream);
534 if (codec_dai->ops.hw_free)
535 codec_dai->ops.hw_free(substream);
538 if(machine->ops && machine->ops->hw_free)
539 machine->ops->hw_free(substream);
541 mutex_unlock(&pcm_mutex);
546 * Free's resources allocated by hw_params, can be called multiple times
548 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
550 struct snd_soc_pcm_runtime *rtd = substream->private_data;
551 struct snd_soc_device *socdev = rtd->socdev;
552 struct snd_soc_dai_link *machine = rtd->dai;
553 struct snd_soc_platform *platform = socdev->platform;
554 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
555 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
556 struct snd_soc_codec *codec = socdev->codec;
558 mutex_lock(&pcm_mutex);
560 /* apply codec digital mute */
561 if (!codec->active && codec_dai->dai_ops.digital_mute)
562 codec_dai->dai_ops.digital_mute(codec_dai, 1);
564 /* free any machine hw params */
565 if (machine->ops && machine->ops->hw_free)
566 machine->ops->hw_free(substream);
568 /* free any DMA resources */
569 if (platform->pcm_ops->hw_free)
570 platform->pcm_ops->hw_free(substream);
572 /* now free hw params for the DAI's */
573 if (codec_dai->ops.hw_free)
574 codec_dai->ops.hw_free(substream);
576 if (cpu_dai->ops.hw_free)
577 cpu_dai->ops.hw_free(substream);
579 mutex_unlock(&pcm_mutex);
583 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
585 struct snd_soc_pcm_runtime *rtd = substream->private_data;
586 struct snd_soc_device *socdev = rtd->socdev;
587 struct snd_soc_dai_link *machine = rtd->dai;
588 struct snd_soc_platform *platform = socdev->platform;
589 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
590 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
593 if (codec_dai->ops.trigger) {
594 ret = codec_dai->ops.trigger(substream, cmd);
599 if (platform->pcm_ops->trigger) {
600 ret = platform->pcm_ops->trigger(substream, cmd);
605 if (cpu_dai->ops.trigger) {
606 ret = cpu_dai->ops.trigger(substream, cmd);
613 /* ASoC PCM operations */
614 static struct snd_pcm_ops soc_pcm_ops = {
615 .open = soc_pcm_open,
616 .close = soc_codec_close,
617 .hw_params = soc_pcm_hw_params,
618 .hw_free = soc_pcm_hw_free,
619 .prepare = soc_pcm_prepare,
620 .trigger = soc_pcm_trigger,
624 /* powers down audio subsystem for suspend */
625 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
627 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
628 struct snd_soc_machine *machine = socdev->machine;
629 struct snd_soc_platform *platform = socdev->platform;
630 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
631 struct snd_soc_codec *codec = socdev->codec;
634 /* mute any active DAC's */
635 for(i = 0; i < machine->num_links; i++) {
636 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
637 if (dai->dai_ops.digital_mute && dai->playback.active)
638 dai->dai_ops.digital_mute(dai, 1);
641 if (machine->suspend_pre)
642 machine->suspend_pre(pdev, state);
644 for(i = 0; i < machine->num_links; i++) {
645 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
646 if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
647 cpu_dai->suspend(pdev, cpu_dai);
648 if (platform->suspend)
649 platform->suspend(pdev, cpu_dai);
652 /* close any waiting streams and save state */
653 run_delayed_work(&socdev->delayed_work);
654 codec->suspend_dapm_state = codec->dapm_state;
656 for(i = 0; i < codec->num_dai; i++) {
657 char *stream = codec->dai[i].playback.stream_name;
659 snd_soc_dapm_stream_event(codec, stream,
660 SND_SOC_DAPM_STREAM_SUSPEND);
661 stream = codec->dai[i].capture.stream_name;
663 snd_soc_dapm_stream_event(codec, stream,
664 SND_SOC_DAPM_STREAM_SUSPEND);
667 if (codec_dev->suspend)
668 codec_dev->suspend(pdev, state);
670 for(i = 0; i < machine->num_links; i++) {
671 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
672 if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
673 cpu_dai->suspend(pdev, cpu_dai);
676 if (machine->suspend_post)
677 machine->suspend_post(pdev, state);
682 /* powers up audio subsystem after a suspend */
683 static int soc_resume(struct platform_device *pdev)
685 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
686 struct snd_soc_machine *machine = socdev->machine;
687 struct snd_soc_platform *platform = socdev->platform;
688 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
689 struct snd_soc_codec *codec = socdev->codec;
692 if (machine->resume_pre)
693 machine->resume_pre(pdev);
695 for(i = 0; i < machine->num_links; i++) {
696 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
697 if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
698 cpu_dai->resume(pdev, cpu_dai);
701 if (codec_dev->resume)
702 codec_dev->resume(pdev);
704 for(i = 0; i < codec->num_dai; i++) {
705 char* stream = codec->dai[i].playback.stream_name;
707 snd_soc_dapm_stream_event(codec, stream,
708 SND_SOC_DAPM_STREAM_RESUME);
709 stream = codec->dai[i].capture.stream_name;
711 snd_soc_dapm_stream_event(codec, stream,
712 SND_SOC_DAPM_STREAM_RESUME);
715 /* unmute any active DAC's */
716 for(i = 0; i < machine->num_links; i++) {
717 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
718 if (dai->dai_ops.digital_mute && dai->playback.active)
719 dai->dai_ops.digital_mute(dai, 0);
722 for(i = 0; i < machine->num_links; i++) {
723 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
724 if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
725 cpu_dai->resume(pdev, cpu_dai);
726 if (platform->resume)
727 platform->resume(pdev, cpu_dai);
730 if (machine->resume_post)
731 machine->resume_post(pdev);
737 #define soc_suspend NULL
738 #define soc_resume NULL
741 /* probes a new socdev */
742 static int soc_probe(struct platform_device *pdev)
745 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
746 struct snd_soc_machine *machine = socdev->machine;
747 struct snd_soc_platform *platform = socdev->platform;
748 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
750 if (machine->probe) {
751 ret = machine->probe(pdev);
756 for (i = 0; i < machine->num_links; i++) {
757 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
758 if (cpu_dai->probe) {
759 ret = cpu_dai->probe(pdev);
765 if (codec_dev->probe) {
766 ret = codec_dev->probe(pdev);
771 if (platform->probe) {
772 ret = platform->probe(pdev);
777 /* DAPM stream work */
778 INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
782 if (codec_dev->remove)
783 codec_dev->remove(pdev);
786 for (i--; i >= 0; i--) {
787 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
789 cpu_dai->remove(pdev);
793 machine->remove(pdev);
798 /* removes a socdev */
799 static int soc_remove(struct platform_device *pdev)
802 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
803 struct snd_soc_machine *machine = socdev->machine;
804 struct snd_soc_platform *platform = socdev->platform;
805 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
807 run_delayed_work(&socdev->delayed_work);
809 if (platform->remove)
810 platform->remove(pdev);
812 if (codec_dev->remove)
813 codec_dev->remove(pdev);
815 for (i = 0; i < machine->num_links; i++) {
816 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
818 cpu_dai->remove(pdev);
822 machine->remove(pdev);
827 /* ASoC platform driver */
828 static struct platform_driver soc_driver = {
833 .remove = soc_remove,
834 .suspend = soc_suspend,
835 .resume = soc_resume,
838 /* create a new pcm */
839 static int soc_new_pcm(struct snd_soc_device *socdev,
840 struct snd_soc_dai_link *dai_link, int num)
842 struct snd_soc_codec *codec = socdev->codec;
843 struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
844 struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
845 struct snd_soc_pcm_runtime *rtd;
848 int ret = 0, playback = 0, capture = 0;
850 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
855 rtd->socdev = socdev;
856 codec_dai->codec = socdev->codec;
858 /* check client and interface hw capabilities */
859 sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
860 get_dai_name(cpu_dai->type), num);
862 if (codec_dai->playback.channels_min)
864 if (codec_dai->capture.channels_min)
867 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
870 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
875 pcm->private_data = rtd;
876 soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
877 soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
878 soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
879 soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
880 soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
881 soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
882 soc_pcm_ops.page = socdev->platform->pcm_ops->page;
885 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
888 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
890 ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
892 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
897 pcm->private_free = socdev->platform->pcm_free;
898 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
903 /* codec register dump */
904 static ssize_t codec_reg_show(struct device *dev,
905 struct device_attribute *attr, char *buf)
907 struct snd_soc_device *devdata = dev_get_drvdata(dev);
908 struct snd_soc_codec *codec = devdata->codec;
909 int i, step = 1, count = 0;
911 if (!codec->reg_cache_size)
914 if (codec->reg_cache_step)
915 step = codec->reg_cache_step;
917 count += sprintf(buf, "%s registers\n", codec->name);
918 for(i = 0; i < codec->reg_cache_size; i += step)
919 count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
923 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
926 * snd_soc_new_ac97_codec - initailise AC97 device
927 * @codec: audio codec
928 * @ops: AC97 bus operations
929 * @num: AC97 codec number
931 * Initialises AC97 codec resources for use by ad-hoc devices only.
933 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
934 struct snd_ac97_bus_ops *ops, int num)
936 mutex_lock(&codec->mutex);
938 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
939 if (codec->ac97 == NULL) {
940 mutex_unlock(&codec->mutex);
944 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
945 if (codec->ac97->bus == NULL) {
948 mutex_unlock(&codec->mutex);
952 codec->ac97->bus->ops = ops;
953 codec->ac97->num = num;
954 mutex_unlock(&codec->mutex);
957 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
960 * snd_soc_free_ac97_codec - free AC97 codec device
961 * @codec: audio codec
963 * Frees AC97 codec device resources.
965 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
967 mutex_lock(&codec->mutex);
968 kfree(codec->ac97->bus);
971 mutex_unlock(&codec->mutex);
973 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
976 * snd_soc_update_bits - update codec register bits
977 * @codec: audio codec
978 * @reg: codec register
979 * @mask: register mask
982 * Writes new register value.
984 * Returns 1 for change else 0.
986 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
987 unsigned short mask, unsigned short value)
990 unsigned short old, new;
992 mutex_lock(&io_mutex);
993 old = snd_soc_read(codec, reg);
994 new = (old & ~mask) | value;
997 snd_soc_write(codec, reg, new);
999 mutex_unlock(&io_mutex);
1002 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1005 * snd_soc_test_bits - test register for change
1006 * @codec: audio codec
1007 * @reg: codec register
1008 * @mask: register mask
1011 * Tests a register with a new value and checks if the new value is
1012 * different from the old value.
1014 * Returns 1 for change else 0.
1016 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1017 unsigned short mask, unsigned short value)
1020 unsigned short old, new;
1022 mutex_lock(&io_mutex);
1023 old = snd_soc_read(codec, reg);
1024 new = (old & ~mask) | value;
1025 change = old != new;
1026 mutex_unlock(&io_mutex);
1030 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1033 * snd_soc_new_pcms - create new sound card and pcms
1034 * @socdev: the SoC audio device
1036 * Create a new sound card based upon the codec and interface pcms.
1038 * Returns 0 for success, else error.
1040 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1042 struct snd_soc_codec *codec = socdev->codec;
1043 struct snd_soc_machine *machine = socdev->machine;
1046 mutex_lock(&codec->mutex);
1048 /* register a sound card */
1049 codec->card = snd_card_new(idx, xid, codec->owner, 0);
1051 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1053 mutex_unlock(&codec->mutex);
1057 codec->card->dev = socdev->dev;
1058 codec->card->private_data = codec;
1059 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1061 /* create the pcms */
1062 for(i = 0; i < machine->num_links; i++) {
1063 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1065 printk(KERN_ERR "asoc: can't create pcm %s\n",
1066 machine->dai_link[i].stream_name);
1067 mutex_unlock(&codec->mutex);
1072 mutex_unlock(&codec->mutex);
1075 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1078 * snd_soc_register_card - register sound card
1079 * @socdev: the SoC audio device
1081 * Register a SoC sound card. Also registers an AC97 device if the
1082 * codec is AC97 for ad hoc devices.
1084 * Returns 0 for success, else error.
1086 int snd_soc_register_card(struct snd_soc_device *socdev)
1088 struct snd_soc_codec *codec = socdev->codec;
1089 struct snd_soc_machine *machine = socdev->machine;
1090 int ret = 0, i, ac97 = 0, err = 0;
1092 mutex_lock(&codec->mutex);
1093 for(i = 0; i < machine->num_links; i++) {
1094 if (socdev->machine->dai_link[i].init) {
1095 err = socdev->machine->dai_link[i].init(codec);
1097 printk(KERN_ERR "asoc: failed to init %s\n",
1098 socdev->machine->dai_link[i].stream_name);
1102 if (socdev->machine->dai_link[i].cpu_dai->type == SND_SOC_DAI_AC97)
1105 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1106 "%s", machine->name);
1107 snprintf(codec->card->longname, sizeof(codec->card->longname),
1108 "%s (%s)", machine->name, codec->name);
1110 ret = snd_card_register(codec->card);
1112 printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
1117 #ifdef CONFIG_SND_SOC_AC97_BUS
1119 ret = soc_ac97_dev_register(codec);
1121 printk(KERN_ERR "asoc: AC97 device register failed\n");
1122 snd_card_free(codec->card);
1128 err = snd_soc_dapm_sys_add(socdev->dev);
1130 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1132 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1134 printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
1136 mutex_unlock(&codec->mutex);
1139 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1142 * snd_soc_free_pcms - free sound card and pcms
1143 * @socdev: the SoC audio device
1145 * Frees sound card and pcms associated with the socdev.
1146 * Also unregister the codec if it is an AC97 device.
1148 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1150 struct snd_soc_codec *codec = socdev->codec;
1152 mutex_lock(&codec->mutex);
1153 #ifdef CONFIG_SND_SOC_AC97_BUS
1155 soc_ac97_dev_unregister(codec);
1159 snd_card_free(codec->card);
1160 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1161 mutex_unlock(&codec->mutex);
1163 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1166 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1167 * @substream: the pcm substream
1168 * @hw: the hardware parameters
1170 * Sets the substream runtime hardware parameters.
1172 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1173 const struct snd_pcm_hardware *hw)
1175 struct snd_pcm_runtime *runtime = substream->runtime;
1176 runtime->hw.info = hw->info;
1177 runtime->hw.formats = hw->formats;
1178 runtime->hw.period_bytes_min = hw->period_bytes_min;
1179 runtime->hw.period_bytes_max = hw->period_bytes_max;
1180 runtime->hw.periods_min = hw->periods_min;
1181 runtime->hw.periods_max = hw->periods_max;
1182 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1183 runtime->hw.fifo_size = hw->fifo_size;
1186 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1189 * snd_soc_cnew - create new control
1190 * @_template: control template
1191 * @data: control private data
1192 * @lnng_name: control long name
1194 * Create a new mixer control from a template control.
1196 * Returns 0 for success, else error.
1198 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1199 void *data, char *long_name)
1201 struct snd_kcontrol_new template;
1203 memcpy(&template, _template, sizeof(template));
1205 template.name = long_name;
1206 template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1209 return snd_ctl_new1(&template, data);
1211 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1214 * snd_soc_info_enum_double - enumerated double mixer info callback
1215 * @kcontrol: mixer control
1216 * @uinfo: control element information
1218 * Callback to provide information about a double enumerated
1221 * Returns 0 for success.
1223 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1224 struct snd_ctl_elem_info *uinfo)
1226 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1228 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1229 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1230 uinfo->value.enumerated.items = e->mask;
1232 if (uinfo->value.enumerated.item > e->mask - 1)
1233 uinfo->value.enumerated.item = e->mask - 1;
1234 strcpy(uinfo->value.enumerated.name,
1235 e->texts[uinfo->value.enumerated.item]);
1238 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1241 * snd_soc_get_enum_double - enumerated double mixer get callback
1242 * @kcontrol: mixer control
1243 * @uinfo: control element information
1245 * Callback to get the value of a double enumerated mixer.
1247 * Returns 0 for success.
1249 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1250 struct snd_ctl_elem_value *ucontrol)
1252 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1253 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1254 unsigned short val, bitmask;
1256 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1258 val = snd_soc_read(codec, e->reg);
1259 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1260 if (e->shift_l != e->shift_r)
1261 ucontrol->value.enumerated.item[1] =
1262 (val >> e->shift_r) & (bitmask - 1);
1266 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1269 * snd_soc_put_enum_double - enumerated double mixer put callback
1270 * @kcontrol: mixer control
1271 * @uinfo: control element information
1273 * Callback to set the value of a double enumerated mixer.
1275 * Returns 0 for success.
1277 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1278 struct snd_ctl_elem_value *ucontrol)
1280 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1281 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1283 unsigned short mask, bitmask;
1285 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1287 if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1289 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1290 mask = (bitmask - 1) << e->shift_l;
1291 if (e->shift_l != e->shift_r) {
1292 if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1294 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1295 mask |= (bitmask - 1) << e->shift_r;
1298 return snd_soc_update_bits(codec, e->reg, mask, val);
1300 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1303 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1304 * @kcontrol: mixer control
1305 * @uinfo: control element information
1307 * Callback to provide information about an external enumerated
1310 * Returns 0 for success.
1312 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1313 struct snd_ctl_elem_info *uinfo)
1315 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1317 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1319 uinfo->value.enumerated.items = e->mask;
1321 if (uinfo->value.enumerated.item > e->mask - 1)
1322 uinfo->value.enumerated.item = e->mask - 1;
1323 strcpy(uinfo->value.enumerated.name,
1324 e->texts[uinfo->value.enumerated.item]);
1327 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1330 * snd_soc_info_volsw_ext - external single mixer info callback
1331 * @kcontrol: mixer control
1332 * @uinfo: control element information
1334 * Callback to provide information about a single external mixer control.
1336 * Returns 0 for success.
1338 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1339 struct snd_ctl_elem_info *uinfo)
1341 int mask = kcontrol->private_value;
1344 mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1346 uinfo->value.integer.min = 0;
1347 uinfo->value.integer.max = mask;
1350 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1353 * snd_soc_info_bool_ext - external single boolean mixer info callback
1354 * @kcontrol: mixer control
1355 * @uinfo: control element information
1357 * Callback to provide information about a single boolean external mixer control.
1359 * Returns 0 for success.
1361 int snd_soc_info_bool_ext(struct snd_kcontrol *kcontrol,
1362 struct snd_ctl_elem_info *uinfo)
1364 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1366 uinfo->value.integer.min = 0;
1367 uinfo->value.integer.max = 1;
1370 EXPORT_SYMBOL_GPL(snd_soc_info_bool_ext);
1373 * snd_soc_info_volsw - single mixer info callback
1374 * @kcontrol: mixer control
1375 * @uinfo: control element information
1377 * Callback to provide information about a single mixer control.
1379 * Returns 0 for success.
1381 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1382 struct snd_ctl_elem_info *uinfo)
1384 int mask = (kcontrol->private_value >> 16) & 0xff;
1385 int shift = (kcontrol->private_value >> 8) & 0x0f;
1386 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1389 mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1390 uinfo->count = shift == rshift ? 1 : 2;
1391 uinfo->value.integer.min = 0;
1392 uinfo->value.integer.max = mask;
1395 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1398 * snd_soc_get_volsw - single mixer get callback
1399 * @kcontrol: mixer control
1400 * @uinfo: control element information
1402 * Callback to get the value of a single mixer control.
1404 * Returns 0 for success.
1406 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1407 struct snd_ctl_elem_value *ucontrol)
1409 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1410 int reg = kcontrol->private_value & 0xff;
1411 int shift = (kcontrol->private_value >> 8) & 0x0f;
1412 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1413 int mask = (kcontrol->private_value >> 16) & 0xff;
1414 int invert = (kcontrol->private_value >> 24) & 0x01;
1416 ucontrol->value.integer.value[0] =
1417 (snd_soc_read(codec, reg) >> shift) & mask;
1418 if (shift != rshift)
1419 ucontrol->value.integer.value[1] =
1420 (snd_soc_read(codec, reg) >> rshift) & mask;
1422 ucontrol->value.integer.value[0] =
1423 mask - ucontrol->value.integer.value[0];
1424 if (shift != rshift)
1425 ucontrol->value.integer.value[1] =
1426 mask - ucontrol->value.integer.value[1];
1431 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1434 * snd_soc_put_volsw - single mixer put callback
1435 * @kcontrol: mixer control
1436 * @uinfo: control element information
1438 * Callback to set the value of a single mixer control.
1440 * Returns 0 for success.
1442 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1443 struct snd_ctl_elem_value *ucontrol)
1445 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1446 int reg = kcontrol->private_value & 0xff;
1447 int shift = (kcontrol->private_value >> 8) & 0x0f;
1448 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1449 int mask = (kcontrol->private_value >> 16) & 0xff;
1450 int invert = (kcontrol->private_value >> 24) & 0x01;
1452 unsigned short val, val2, val_mask;
1454 val = (ucontrol->value.integer.value[0] & mask);
1457 val_mask = mask << shift;
1459 if (shift != rshift) {
1460 val2 = (ucontrol->value.integer.value[1] & mask);
1463 val_mask |= mask << rshift;
1464 val |= val2 << rshift;
1466 err = snd_soc_update_bits(codec, reg, val_mask, val);
1469 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1472 * snd_soc_info_volsw_2r - double mixer info callback
1473 * @kcontrol: mixer control
1474 * @uinfo: control element information
1476 * Callback to provide information about a double mixer control that
1477 * spans 2 codec registers.
1479 * Returns 0 for success.
1481 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1482 struct snd_ctl_elem_info *uinfo)
1484 int mask = (kcontrol->private_value >> 12) & 0xff;
1487 mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1489 uinfo->value.integer.min = 0;
1490 uinfo->value.integer.max = mask;
1493 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1496 * snd_soc_get_volsw_2r - double mixer get callback
1497 * @kcontrol: mixer control
1498 * @uinfo: control element information
1500 * Callback to get the value of a double mixer control that spans 2 registers.
1502 * Returns 0 for success.
1504 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1505 struct snd_ctl_elem_value *ucontrol)
1507 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1508 int reg = kcontrol->private_value & 0xff;
1509 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1510 int shift = (kcontrol->private_value >> 8) & 0x0f;
1511 int mask = (kcontrol->private_value >> 12) & 0xff;
1512 int invert = (kcontrol->private_value >> 20) & 0x01;
1514 ucontrol->value.integer.value[0] =
1515 (snd_soc_read(codec, reg) >> shift) & mask;
1516 ucontrol->value.integer.value[1] =
1517 (snd_soc_read(codec, reg2) >> shift) & mask;
1519 ucontrol->value.integer.value[0] =
1520 mask - ucontrol->value.integer.value[0];
1521 ucontrol->value.integer.value[1] =
1522 mask - ucontrol->value.integer.value[1];
1527 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1530 * snd_soc_put_volsw_2r - double mixer set callback
1531 * @kcontrol: mixer control
1532 * @uinfo: control element information
1534 * Callback to set the value of a double mixer control that spans 2 registers.
1536 * Returns 0 for success.
1538 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1539 struct snd_ctl_elem_value *ucontrol)
1541 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1542 int reg = kcontrol->private_value & 0xff;
1543 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1544 int shift = (kcontrol->private_value >> 8) & 0x0f;
1545 int mask = (kcontrol->private_value >> 12) & 0xff;
1546 int invert = (kcontrol->private_value >> 20) & 0x01;
1548 unsigned short val, val2, val_mask;
1550 val_mask = mask << shift;
1551 val = (ucontrol->value.integer.value[0] & mask);
1552 val2 = (ucontrol->value.integer.value[1] & mask);
1560 val2 = val2 << shift;
1562 if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
1565 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1568 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1570 static int __devinit snd_soc_init(void)
1572 printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1573 return platform_driver_register(&soc_driver);
1576 static void snd_soc_exit(void)
1578 platform_driver_unregister(&soc_driver);
1581 module_init(snd_soc_init);
1582 module_exit(snd_soc_exit);
1584 /* Module information */
1585 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1586 MODULE_DESCRIPTION("ALSA SoC Core");
1587 MODULE_LICENSE("GPL");