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/core.h>
36 #include <sound/pcm.h>
37 #include <sound/pcm_params.h>
38 #include <sound/soc.h>
39 #include <sound/soc-dapm.h>
40 #include <sound/initval.h>
45 #define dbg(format, arg...) printk(format, ## arg)
47 #define dbg(format, arg...)
50 static DEFINE_MUTEX(pcm_mutex);
51 static DEFINE_MUTEX(io_mutex);
52 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
55 * This is a timeout to do a DAPM powerdown after a stream is closed().
56 * It can be used to eliminate pops between different playback streams, e.g.
57 * between two audio tracks.
59 static int pmdown_time = 5000;
60 module_param(pmdown_time, int, 0);
61 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
64 * This function forces any delayed work to be queued and run.
66 static int run_delayed_work(struct delayed_work *dwork)
70 /* cancel any work waiting to be queued. */
71 ret = cancel_delayed_work(dwork);
73 /* if there was any work waiting then we run it now and
74 * wait for it's completion */
76 schedule_delayed_work(dwork, 0);
77 flush_scheduled_work();
82 #ifdef CONFIG_SND_SOC_AC97_BUS
83 /* unregister ac97 codec */
84 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
86 if (codec->ac97->dev.bus)
87 device_unregister(&codec->ac97->dev);
91 /* stop no dev release warning */
92 static void soc_ac97_device_release(struct device *dev){}
94 /* register ac97 codec to bus */
95 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
99 codec->ac97->dev.bus = &ac97_bus_type;
100 codec->ac97->dev.parent = NULL;
101 codec->ac97->dev.release = soc_ac97_device_release;
103 snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
104 codec->card->number, 0, codec->name);
105 err = device_register(&codec->ac97->dev);
107 snd_printk(KERN_ERR "Can't register ac97 bus\n");
108 codec->ac97->dev.bus = NULL;
115 static inline const char* get_dai_name(int type)
118 case SND_SOC_DAI_AC97_BUS:
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 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 /* power down the codec to D1 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_device_event(socdev,
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 /* power down the codec power domain 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_device_event(socdev,
308 SNDRV_CTL_POWER_D3hot);
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_device_event(socdev,
369 SNDRV_CTL_POWER_D3hot);
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->dapm_state != SNDRV_CTL_POWER_D0) {
444 snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D1);
446 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
447 snd_soc_dapm_stream_event(codec,
448 codec_dai->playback.stream_name,
449 SND_SOC_DAPM_STREAM_START);
451 snd_soc_dapm_stream_event(codec,
452 codec_dai->capture.stream_name,
453 SND_SOC_DAPM_STREAM_START);
455 snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D0);
456 if (codec_dai->dai_ops.digital_mute)
457 codec_dai->dai_ops.digital_mute(codec_dai, 0);
460 /* codec already powered - power on widgets */
461 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
462 snd_soc_dapm_stream_event(codec,
463 codec_dai->playback.stream_name,
464 SND_SOC_DAPM_STREAM_START);
466 snd_soc_dapm_stream_event(codec,
467 codec_dai->capture.stream_name,
468 SND_SOC_DAPM_STREAM_START);
469 if (codec_dai->dai_ops.digital_mute)
470 codec_dai->dai_ops.digital_mute(codec_dai, 0);
475 mutex_unlock(&pcm_mutex);
480 * Called by ALSA when the hardware params are set by application. This
481 * function can also be called multiple times and can allocate buffers
482 * (using snd_pcm_lib_* ). It's non-atomic.
484 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
485 struct snd_pcm_hw_params *params)
487 struct snd_soc_pcm_runtime *rtd = substream->private_data;
488 struct snd_soc_device *socdev = rtd->socdev;
489 struct snd_soc_dai_link *machine = rtd->dai;
490 struct snd_soc_platform *platform = socdev->platform;
491 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
492 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
495 mutex_lock(&pcm_mutex);
497 if (machine->ops && machine->ops->hw_params) {
498 ret = machine->ops->hw_params(substream, params);
500 printk(KERN_ERR "asoc: machine hw_params failed\n");
505 if (codec_dai->ops.hw_params) {
506 ret = codec_dai->ops.hw_params(substream, params);
508 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
514 if (cpu_dai->ops.hw_params) {
515 ret = cpu_dai->ops.hw_params(substream, params);
517 printk(KERN_ERR "asoc: can't set interface %s hw params\n",
523 if (platform->pcm_ops->hw_params) {
524 ret = platform->pcm_ops->hw_params(substream, params);
526 printk(KERN_ERR "asoc: can't set platform %s hw params\n",
533 mutex_unlock(&pcm_mutex);
537 if (cpu_dai->ops.hw_free)
538 cpu_dai->ops.hw_free(substream);
541 if (codec_dai->ops.hw_free)
542 codec_dai->ops.hw_free(substream);
545 if(machine->ops && machine->ops->hw_free)
546 machine->ops->hw_free(substream);
548 mutex_unlock(&pcm_mutex);
553 * Free's resources allocated by hw_params, can be called multiple times
555 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
557 struct snd_soc_pcm_runtime *rtd = substream->private_data;
558 struct snd_soc_device *socdev = rtd->socdev;
559 struct snd_soc_dai_link *machine = rtd->dai;
560 struct snd_soc_platform *platform = socdev->platform;
561 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
562 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
563 struct snd_soc_codec *codec = socdev->codec;
565 mutex_lock(&pcm_mutex);
567 /* apply codec digital mute */
568 if (!codec->active && codec_dai->dai_ops.digital_mute)
569 codec_dai->dai_ops.digital_mute(codec_dai, 1);
571 /* free any machine hw params */
572 if (machine->ops && machine->ops->hw_free)
573 machine->ops->hw_free(substream);
575 /* free any DMA resources */
576 if (platform->pcm_ops->hw_free)
577 platform->pcm_ops->hw_free(substream);
579 /* now free hw params for the DAI's */
580 if (codec_dai->ops.hw_free)
581 codec_dai->ops.hw_free(substream);
583 if (cpu_dai->ops.hw_free)
584 cpu_dai->ops.hw_free(substream);
586 mutex_unlock(&pcm_mutex);
590 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
592 struct snd_soc_pcm_runtime *rtd = substream->private_data;
593 struct snd_soc_device *socdev = rtd->socdev;
594 struct snd_soc_dai_link *machine = rtd->dai;
595 struct snd_soc_platform *platform = socdev->platform;
596 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
597 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
600 if (codec_dai->ops.trigger) {
601 ret = codec_dai->ops.trigger(substream, cmd);
606 if (platform->pcm_ops->trigger) {
607 ret = platform->pcm_ops->trigger(substream, cmd);
612 if (cpu_dai->ops.trigger) {
613 ret = cpu_dai->ops.trigger(substream, cmd);
620 /* ASoC PCM operations */
621 static struct snd_pcm_ops soc_pcm_ops = {
622 .open = soc_pcm_open,
623 .close = soc_codec_close,
624 .hw_params = soc_pcm_hw_params,
625 .hw_free = soc_pcm_hw_free,
626 .prepare = soc_pcm_prepare,
627 .trigger = soc_pcm_trigger,
631 /* powers down audio subsystem for suspend */
632 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
634 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
635 struct snd_soc_machine *machine = socdev->machine;
636 struct snd_soc_platform *platform = socdev->platform;
637 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
638 struct snd_soc_codec *codec = socdev->codec;
641 /* mute any active DAC's */
642 for(i = 0; i < machine->num_links; i++) {
643 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
644 if (dai->dai_ops.digital_mute && dai->playback.active)
645 dai->dai_ops.digital_mute(dai, 1);
648 if (machine->suspend_pre)
649 machine->suspend_pre(pdev, state);
651 for(i = 0; i < machine->num_links; i++) {
652 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
653 if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
654 cpu_dai->suspend(pdev, cpu_dai);
655 if (platform->suspend)
656 platform->suspend(pdev, cpu_dai);
659 /* close any waiting streams and save state */
660 run_delayed_work(&socdev->delayed_work);
661 codec->suspend_dapm_state = codec->dapm_state;
663 for(i = 0; i < codec->num_dai; i++) {
664 char *stream = codec->dai[i].playback.stream_name;
666 snd_soc_dapm_stream_event(codec, stream,
667 SND_SOC_DAPM_STREAM_SUSPEND);
668 stream = codec->dai[i].capture.stream_name;
670 snd_soc_dapm_stream_event(codec, stream,
671 SND_SOC_DAPM_STREAM_SUSPEND);
674 if (codec_dev->suspend)
675 codec_dev->suspend(pdev, state);
677 for(i = 0; i < machine->num_links; i++) {
678 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
679 if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
680 cpu_dai->suspend(pdev, cpu_dai);
683 if (machine->suspend_post)
684 machine->suspend_post(pdev, state);
689 /* powers up audio subsystem after a suspend */
690 static int soc_resume(struct platform_device *pdev)
692 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
693 struct snd_soc_machine *machine = socdev->machine;
694 struct snd_soc_platform *platform = socdev->platform;
695 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
696 struct snd_soc_codec *codec = socdev->codec;
699 if (machine->resume_pre)
700 machine->resume_pre(pdev);
702 for(i = 0; i < machine->num_links; i++) {
703 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
704 if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
705 cpu_dai->resume(pdev, cpu_dai);
708 if (codec_dev->resume)
709 codec_dev->resume(pdev);
711 for(i = 0; i < codec->num_dai; i++) {
712 char* stream = codec->dai[i].playback.stream_name;
714 snd_soc_dapm_stream_event(codec, stream,
715 SND_SOC_DAPM_STREAM_RESUME);
716 stream = codec->dai[i].capture.stream_name;
718 snd_soc_dapm_stream_event(codec, stream,
719 SND_SOC_DAPM_STREAM_RESUME);
722 /* unmute any active DAC's */
723 for(i = 0; i < machine->num_links; i++) {
724 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
725 if (dai->dai_ops.digital_mute && dai->playback.active)
726 dai->dai_ops.digital_mute(dai, 0);
729 for(i = 0; i < machine->num_links; i++) {
730 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
731 if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
732 cpu_dai->resume(pdev, cpu_dai);
733 if (platform->resume)
734 platform->resume(pdev, cpu_dai);
737 if (machine->resume_post)
738 machine->resume_post(pdev);
744 #define soc_suspend NULL
745 #define soc_resume NULL
748 /* probes a new socdev */
749 static int soc_probe(struct platform_device *pdev)
752 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
753 struct snd_soc_machine *machine = socdev->machine;
754 struct snd_soc_platform *platform = socdev->platform;
755 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
757 if (machine->probe) {
758 ret = machine->probe(pdev);
763 for (i = 0; i < machine->num_links; i++) {
764 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
765 if (cpu_dai->probe) {
766 ret = cpu_dai->probe(pdev);
772 if (codec_dev->probe) {
773 ret = codec_dev->probe(pdev);
778 if (platform->probe) {
779 ret = platform->probe(pdev);
784 /* DAPM stream work */
785 INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
789 if (codec_dev->remove)
790 codec_dev->remove(pdev);
793 for (i--; i >= 0; i--) {
794 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
796 cpu_dai->remove(pdev);
800 machine->remove(pdev);
805 /* removes a socdev */
806 static int soc_remove(struct platform_device *pdev)
809 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
810 struct snd_soc_machine *machine = socdev->machine;
811 struct snd_soc_platform *platform = socdev->platform;
812 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
814 run_delayed_work(&socdev->delayed_work);
816 if (platform->remove)
817 platform->remove(pdev);
819 if (codec_dev->remove)
820 codec_dev->remove(pdev);
822 for (i = 0; i < machine->num_links; i++) {
823 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
825 cpu_dai->remove(pdev);
829 machine->remove(pdev);
834 /* ASoC platform driver */
835 static struct platform_driver soc_driver = {
840 .remove = soc_remove,
841 .suspend = soc_suspend,
842 .resume = soc_resume,
845 /* create a new pcm */
846 static int soc_new_pcm(struct snd_soc_device *socdev,
847 struct snd_soc_dai_link *dai_link, int num)
849 struct snd_soc_codec *codec = socdev->codec;
850 struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
851 struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
852 struct snd_soc_pcm_runtime *rtd;
855 int ret = 0, playback = 0, capture = 0;
857 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
862 rtd->socdev = socdev;
863 codec_dai->codec = socdev->codec;
865 /* check client and interface hw capabilities */
866 sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
867 get_dai_name(cpu_dai->type), num);
869 if (codec_dai->playback.channels_min)
871 if (codec_dai->capture.channels_min)
874 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
877 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
882 pcm->private_data = rtd;
883 soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
884 soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
885 soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
886 soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
887 soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
888 soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
889 soc_pcm_ops.page = socdev->platform->pcm_ops->page;
892 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
895 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
897 ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
899 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
904 pcm->private_free = socdev->platform->pcm_free;
905 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
910 /* codec register dump */
911 static ssize_t codec_reg_show(struct device *dev,
912 struct device_attribute *attr, char *buf)
914 struct snd_soc_device *devdata = dev_get_drvdata(dev);
915 struct snd_soc_codec *codec = devdata->codec;
916 int i, step = 1, count = 0;
918 if (!codec->reg_cache_size)
921 if (codec->reg_cache_step)
922 step = codec->reg_cache_step;
924 count += sprintf(buf, "%s registers\n", codec->name);
925 for(i = 0; i < codec->reg_cache_size; i += step)
926 count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
930 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
933 * snd_soc_new_ac97_codec - initailise AC97 device
934 * @codec: audio codec
935 * @ops: AC97 bus operations
936 * @num: AC97 codec number
938 * Initialises AC97 codec resources for use by ad-hoc devices only.
940 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
941 struct snd_ac97_bus_ops *ops, int num)
943 mutex_lock(&codec->mutex);
945 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
946 if (codec->ac97 == NULL) {
947 mutex_unlock(&codec->mutex);
951 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
952 if (codec->ac97->bus == NULL) {
955 mutex_unlock(&codec->mutex);
959 codec->ac97->bus->ops = ops;
960 codec->ac97->num = num;
961 mutex_unlock(&codec->mutex);
964 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
967 * snd_soc_free_ac97_codec - free AC97 codec device
968 * @codec: audio codec
970 * Frees AC97 codec device resources.
972 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
974 mutex_lock(&codec->mutex);
975 kfree(codec->ac97->bus);
978 mutex_unlock(&codec->mutex);
980 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
983 * snd_soc_update_bits - update codec register bits
984 * @codec: audio codec
985 * @reg: codec register
986 * @mask: register mask
989 * Writes new register value.
991 * Returns 1 for change else 0.
993 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
994 unsigned short mask, unsigned short value)
997 unsigned short old, new;
999 mutex_lock(&io_mutex);
1000 old = snd_soc_read(codec, reg);
1001 new = (old & ~mask) | value;
1002 change = old != new;
1004 snd_soc_write(codec, reg, new);
1006 mutex_unlock(&io_mutex);
1009 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1012 * snd_soc_test_bits - test register for change
1013 * @codec: audio codec
1014 * @reg: codec register
1015 * @mask: register mask
1018 * Tests a register with a new value and checks if the new value is
1019 * different from the old value.
1021 * Returns 1 for change else 0.
1023 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1024 unsigned short mask, unsigned short value)
1027 unsigned short old, new;
1029 mutex_lock(&io_mutex);
1030 old = snd_soc_read(codec, reg);
1031 new = (old & ~mask) | value;
1032 change = old != new;
1033 mutex_unlock(&io_mutex);
1037 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1040 * snd_soc_new_pcms - create new sound card and pcms
1041 * @socdev: the SoC audio device
1043 * Create a new sound card based upon the codec and interface pcms.
1045 * Returns 0 for success, else error.
1047 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1049 struct snd_soc_codec *codec = socdev->codec;
1050 struct snd_soc_machine *machine = socdev->machine;
1053 mutex_lock(&codec->mutex);
1055 /* register a sound card */
1056 codec->card = snd_card_new(idx, xid, codec->owner, 0);
1058 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1060 mutex_unlock(&codec->mutex);
1064 codec->card->dev = socdev->dev;
1065 codec->card->private_data = codec;
1066 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1068 /* create the pcms */
1069 for(i = 0; i < machine->num_links; i++) {
1070 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1072 printk(KERN_ERR "asoc: can't create pcm %s\n",
1073 machine->dai_link[i].stream_name);
1074 mutex_unlock(&codec->mutex);
1079 mutex_unlock(&codec->mutex);
1082 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1085 * snd_soc_register_card - register sound card
1086 * @socdev: the SoC audio device
1088 * Register a SoC sound card. Also registers an AC97 device if the
1089 * codec is AC97 for ad hoc devices.
1091 * Returns 0 for success, else error.
1093 int snd_soc_register_card(struct snd_soc_device *socdev)
1095 struct snd_soc_codec *codec = socdev->codec;
1096 struct snd_soc_machine *machine = socdev->machine;
1097 int ret = 0, i, ac97 = 0, err = 0;
1099 mutex_lock(&codec->mutex);
1100 for(i = 0; i < machine->num_links; i++) {
1101 if (socdev->machine->dai_link[i].init) {
1102 err = socdev->machine->dai_link[i].init(codec);
1104 printk(KERN_ERR "asoc: failed to init %s\n",
1105 socdev->machine->dai_link[i].stream_name);
1109 if (socdev->machine->dai_link[i].codec_dai->type ==
1110 SND_SOC_DAI_AC97_BUS)
1113 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1114 "%s", machine->name);
1115 snprintf(codec->card->longname, sizeof(codec->card->longname),
1116 "%s (%s)", machine->name, codec->name);
1118 ret = snd_card_register(codec->card);
1120 printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
1125 #ifdef CONFIG_SND_SOC_AC97_BUS
1127 ret = soc_ac97_dev_register(codec);
1129 printk(KERN_ERR "asoc: AC97 device register failed\n");
1130 snd_card_free(codec->card);
1136 err = snd_soc_dapm_sys_add(socdev->dev);
1138 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1140 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1142 printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
1144 mutex_unlock(&codec->mutex);
1147 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1150 * snd_soc_free_pcms - free sound card and pcms
1151 * @socdev: the SoC audio device
1153 * Frees sound card and pcms associated with the socdev.
1154 * Also unregister the codec if it is an AC97 device.
1156 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1158 struct snd_soc_codec *codec = socdev->codec;
1159 #ifdef CONFIG_SND_SOC_AC97_BUS
1160 struct snd_soc_codec_dai *codec_dai;
1164 mutex_lock(&codec->mutex);
1165 #ifdef CONFIG_SND_SOC_AC97_BUS
1166 for(i = 0; i < codec->num_dai; i++) {
1167 codec_dai = &codec->dai[i];
1168 if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
1169 soc_ac97_dev_unregister(codec);
1177 snd_card_free(codec->card);
1178 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1179 mutex_unlock(&codec->mutex);
1181 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1184 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1185 * @substream: the pcm substream
1186 * @hw: the hardware parameters
1188 * Sets the substream runtime hardware parameters.
1190 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1191 const struct snd_pcm_hardware *hw)
1193 struct snd_pcm_runtime *runtime = substream->runtime;
1194 runtime->hw.info = hw->info;
1195 runtime->hw.formats = hw->formats;
1196 runtime->hw.period_bytes_min = hw->period_bytes_min;
1197 runtime->hw.period_bytes_max = hw->period_bytes_max;
1198 runtime->hw.periods_min = hw->periods_min;
1199 runtime->hw.periods_max = hw->periods_max;
1200 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1201 runtime->hw.fifo_size = hw->fifo_size;
1204 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1207 * snd_soc_cnew - create new control
1208 * @_template: control template
1209 * @data: control private data
1210 * @lnng_name: control long name
1212 * Create a new mixer control from a template control.
1214 * Returns 0 for success, else error.
1216 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1217 void *data, char *long_name)
1219 struct snd_kcontrol_new template;
1221 memcpy(&template, _template, sizeof(template));
1223 template.name = long_name;
1226 return snd_ctl_new1(&template, data);
1228 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1231 * snd_soc_info_enum_double - enumerated double mixer info callback
1232 * @kcontrol: mixer control
1233 * @uinfo: control element information
1235 * Callback to provide information about a double enumerated
1238 * Returns 0 for success.
1240 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1241 struct snd_ctl_elem_info *uinfo)
1243 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1245 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1246 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1247 uinfo->value.enumerated.items = e->mask;
1249 if (uinfo->value.enumerated.item > e->mask - 1)
1250 uinfo->value.enumerated.item = e->mask - 1;
1251 strcpy(uinfo->value.enumerated.name,
1252 e->texts[uinfo->value.enumerated.item]);
1255 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1258 * snd_soc_get_enum_double - enumerated double mixer get callback
1259 * @kcontrol: mixer control
1260 * @uinfo: control element information
1262 * Callback to get the value of a double enumerated mixer.
1264 * Returns 0 for success.
1266 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1267 struct snd_ctl_elem_value *ucontrol)
1269 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1270 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1271 unsigned short val, bitmask;
1273 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1275 val = snd_soc_read(codec, e->reg);
1276 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1277 if (e->shift_l != e->shift_r)
1278 ucontrol->value.enumerated.item[1] =
1279 (val >> e->shift_r) & (bitmask - 1);
1283 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1286 * snd_soc_put_enum_double - enumerated double mixer put callback
1287 * @kcontrol: mixer control
1288 * @uinfo: control element information
1290 * Callback to set the value of a double enumerated mixer.
1292 * Returns 0 for success.
1294 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1295 struct snd_ctl_elem_value *ucontrol)
1297 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1298 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1300 unsigned short mask, bitmask;
1302 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1304 if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1306 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1307 mask = (bitmask - 1) << e->shift_l;
1308 if (e->shift_l != e->shift_r) {
1309 if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1311 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1312 mask |= (bitmask - 1) << e->shift_r;
1315 return snd_soc_update_bits(codec, e->reg, mask, val);
1317 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1320 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1321 * @kcontrol: mixer control
1322 * @uinfo: control element information
1324 * Callback to provide information about an external enumerated
1327 * Returns 0 for success.
1329 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1330 struct snd_ctl_elem_info *uinfo)
1332 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1334 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1336 uinfo->value.enumerated.items = e->mask;
1338 if (uinfo->value.enumerated.item > e->mask - 1)
1339 uinfo->value.enumerated.item = e->mask - 1;
1340 strcpy(uinfo->value.enumerated.name,
1341 e->texts[uinfo->value.enumerated.item]);
1344 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1347 * snd_soc_info_volsw_ext - external single mixer info callback
1348 * @kcontrol: mixer control
1349 * @uinfo: control element information
1351 * Callback to provide information about a single external mixer control.
1353 * Returns 0 for success.
1355 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1356 struct snd_ctl_elem_info *uinfo)
1358 int max = kcontrol->private_value;
1361 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1363 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1366 uinfo->value.integer.min = 0;
1367 uinfo->value.integer.max = max;
1370 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_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 max = (kcontrol->private_value >> 16) & 0xff;
1385 int shift = (kcontrol->private_value >> 8) & 0x0f;
1386 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1389 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1391 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1393 uinfo->count = shift == rshift ? 1 : 2;
1394 uinfo->value.integer.min = 0;
1395 uinfo->value.integer.max = max;
1398 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1401 * snd_soc_get_volsw - single mixer get callback
1402 * @kcontrol: mixer control
1403 * @uinfo: control element information
1405 * Callback to get the value of a single mixer control.
1407 * Returns 0 for success.
1409 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1410 struct snd_ctl_elem_value *ucontrol)
1412 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1413 int reg = kcontrol->private_value & 0xff;
1414 int shift = (kcontrol->private_value >> 8) & 0x0f;
1415 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1416 int max = (kcontrol->private_value >> 16) & 0xff;
1417 int mask = (1 << fls(max)) - 1;
1418 int invert = (kcontrol->private_value >> 24) & 0x01;
1420 ucontrol->value.integer.value[0] =
1421 (snd_soc_read(codec, reg) >> shift) & mask;
1422 if (shift != rshift)
1423 ucontrol->value.integer.value[1] =
1424 (snd_soc_read(codec, reg) >> rshift) & mask;
1426 ucontrol->value.integer.value[0] =
1427 max - ucontrol->value.integer.value[0];
1428 if (shift != rshift)
1429 ucontrol->value.integer.value[1] =
1430 max - ucontrol->value.integer.value[1];
1435 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1438 * snd_soc_put_volsw - single mixer put callback
1439 * @kcontrol: mixer control
1440 * @uinfo: control element information
1442 * Callback to set the value of a single mixer control.
1444 * Returns 0 for success.
1446 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1447 struct snd_ctl_elem_value *ucontrol)
1449 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1450 int reg = kcontrol->private_value & 0xff;
1451 int shift = (kcontrol->private_value >> 8) & 0x0f;
1452 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1453 int max = (kcontrol->private_value >> 16) & 0xff;
1454 int mask = (1 << fls(max)) - 1;
1455 int invert = (kcontrol->private_value >> 24) & 0x01;
1456 unsigned short val, val2, val_mask;
1458 val = (ucontrol->value.integer.value[0] & mask);
1461 val_mask = mask << shift;
1463 if (shift != rshift) {
1464 val2 = (ucontrol->value.integer.value[1] & mask);
1467 val_mask |= mask << rshift;
1468 val |= val2 << rshift;
1470 return snd_soc_update_bits(codec, reg, val_mask, val);
1472 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1475 * snd_soc_info_volsw_2r - double mixer info callback
1476 * @kcontrol: mixer control
1477 * @uinfo: control element information
1479 * Callback to provide information about a double mixer control that
1480 * spans 2 codec registers.
1482 * Returns 0 for success.
1484 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1485 struct snd_ctl_elem_info *uinfo)
1487 int max = (kcontrol->private_value >> 12) & 0xff;
1490 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1492 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1495 uinfo->value.integer.min = 0;
1496 uinfo->value.integer.max = max;
1499 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1502 * snd_soc_get_volsw_2r - double mixer get callback
1503 * @kcontrol: mixer control
1504 * @uinfo: control element information
1506 * Callback to get the value of a double mixer control that spans 2 registers.
1508 * Returns 0 for success.
1510 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1511 struct snd_ctl_elem_value *ucontrol)
1513 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1514 int reg = kcontrol->private_value & 0xff;
1515 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1516 int shift = (kcontrol->private_value >> 8) & 0x0f;
1517 int max = (kcontrol->private_value >> 12) & 0xff;
1518 int mask = (1<<fls(max))-1;
1519 int invert = (kcontrol->private_value >> 20) & 0x01;
1521 ucontrol->value.integer.value[0] =
1522 (snd_soc_read(codec, reg) >> shift) & mask;
1523 ucontrol->value.integer.value[1] =
1524 (snd_soc_read(codec, reg2) >> shift) & mask;
1526 ucontrol->value.integer.value[0] =
1527 max - ucontrol->value.integer.value[0];
1528 ucontrol->value.integer.value[1] =
1529 max - ucontrol->value.integer.value[1];
1534 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1537 * snd_soc_put_volsw_2r - double mixer set callback
1538 * @kcontrol: mixer control
1539 * @uinfo: control element information
1541 * Callback to set the value of a double mixer control that spans 2 registers.
1543 * Returns 0 for success.
1545 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1546 struct snd_ctl_elem_value *ucontrol)
1548 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1549 int reg = kcontrol->private_value & 0xff;
1550 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1551 int shift = (kcontrol->private_value >> 8) & 0x0f;
1552 int max = (kcontrol->private_value >> 12) & 0xff;
1553 int mask = (1 << fls(max)) - 1;
1554 int invert = (kcontrol->private_value >> 20) & 0x01;
1556 unsigned short val, val2, val_mask;
1558 val_mask = mask << shift;
1559 val = (ucontrol->value.integer.value[0] & mask);
1560 val2 = (ucontrol->value.integer.value[1] & mask);
1568 val2 = val2 << shift;
1570 if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
1573 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1576 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1578 static int __devinit snd_soc_init(void)
1580 printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1581 return platform_driver_register(&soc_driver);
1584 static void snd_soc_exit(void)
1586 platform_driver_unregister(&soc_driver);
1589 module_init(snd_soc_init);
1590 module_exit(snd_soc_exit);
1592 /* Module information */
1593 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1594 MODULE_DESCRIPTION("ALSA SoC Core");
1595 MODULE_LICENSE("GPL");