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, cpu_dai->playback.rate_min);
182 runtime->hw.rate_max =
183 min(codec_dai->playback.rate_max, cpu_dai->playback.rate_max);
184 runtime->hw.channels_min =
185 max(codec_dai->playback.channels_min,
186 cpu_dai->playback.channels_min);
187 runtime->hw.channels_max =
188 min(codec_dai->playback.channels_max,
189 cpu_dai->playback.channels_max);
190 runtime->hw.formats =
191 codec_dai->playback.formats & cpu_dai->playback.formats;
193 codec_dai->playback.rates & cpu_dai->playback.rates;
195 runtime->hw.rate_min =
196 max(codec_dai->capture.rate_min, cpu_dai->capture.rate_min);
197 runtime->hw.rate_max =
198 min(codec_dai->capture.rate_max, cpu_dai->capture.rate_max);
199 runtime->hw.channels_min =
200 max(codec_dai->capture.channels_min,
201 cpu_dai->capture.channels_min);
202 runtime->hw.channels_max =
203 min(codec_dai->capture.channels_max,
204 cpu_dai->capture.channels_max);
205 runtime->hw.formats =
206 codec_dai->capture.formats & cpu_dai->capture.formats;
208 codec_dai->capture.rates & cpu_dai->capture.rates;
211 snd_pcm_limit_hw_rates(runtime);
212 if (!runtime->hw.rates) {
213 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
214 codec_dai->name, cpu_dai->name);
217 if (!runtime->hw.formats) {
218 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
219 codec_dai->name, cpu_dai->name);
222 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
223 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
224 codec_dai->name, cpu_dai->name);
228 dbg("asoc: %s <-> %s info:\n",codec_dai->name, cpu_dai->name);
229 dbg("asoc: rate mask 0x%x\n", runtime->hw.rates);
230 dbg("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
231 runtime->hw.channels_max);
232 dbg("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
233 runtime->hw.rate_max);
235 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
236 cpu_dai->playback.active = codec_dai->playback.active = 1;
238 cpu_dai->capture.active = codec_dai->capture.active = 1;
239 cpu_dai->active = codec_dai->active = 1;
240 cpu_dai->runtime = runtime;
241 socdev->codec->active++;
242 mutex_unlock(&pcm_mutex);
246 if (machine->ops && machine->ops->shutdown)
247 machine->ops->shutdown(substream);
250 if (platform->pcm_ops->close)
251 platform->pcm_ops->close(substream);
254 if (cpu_dai->ops.shutdown)
255 cpu_dai->ops.shutdown(substream);
257 mutex_unlock(&pcm_mutex);
262 * Power down the audio subsystem pmdown_time msecs after close is called.
263 * This is to ensure there are no pops or clicks in between any music tracks
264 * due to DAPM power cycling.
266 static void close_delayed_work(struct work_struct *work)
268 struct snd_soc_device *socdev =
269 container_of(work, struct snd_soc_device, delayed_work.work);
270 struct snd_soc_codec *codec = socdev->codec;
271 struct snd_soc_codec_dai *codec_dai;
274 mutex_lock(&pcm_mutex);
275 for(i = 0; i < codec->num_dai; i++) {
276 codec_dai = &codec->dai[i];
278 dbg("pop wq checking: %s status: %s waiting: %s\n",
279 codec_dai->playback.stream_name,
280 codec_dai->playback.active ? "active" : "inactive",
281 codec_dai->pop_wait ? "yes" : "no");
283 /* are we waiting on this codec DAI stream */
284 if (codec_dai->pop_wait == 1) {
286 /* power down the codec to D1 if no longer active */
287 if (codec->active == 0) {
288 dbg("pop wq D1 %s %s\n", codec->name,
289 codec_dai->playback.stream_name);
290 snd_soc_dapm_device_event(socdev,
294 codec_dai->pop_wait = 0;
295 snd_soc_dapm_stream_event(codec,
296 codec_dai->playback.stream_name,
297 SND_SOC_DAPM_STREAM_STOP);
299 /* power down the codec power domain if no longer active */
300 if (codec->active == 0) {
301 dbg("pop wq D3 %s %s\n", codec->name,
302 codec_dai->playback.stream_name);
303 snd_soc_dapm_device_event(socdev,
304 SNDRV_CTL_POWER_D3hot);
308 mutex_unlock(&pcm_mutex);
312 * Called by ALSA when a PCM substream is closed. Private data can be
313 * freed here. The cpu DAI, codec DAI, machine and platform are also
316 static int soc_codec_close(struct snd_pcm_substream *substream)
318 struct snd_soc_pcm_runtime *rtd = substream->private_data;
319 struct snd_soc_device *socdev = rtd->socdev;
320 struct snd_soc_dai_link *machine = rtd->dai;
321 struct snd_soc_platform *platform = socdev->platform;
322 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
323 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
324 struct snd_soc_codec *codec = socdev->codec;
326 mutex_lock(&pcm_mutex);
328 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
329 cpu_dai->playback.active = codec_dai->playback.active = 0;
331 cpu_dai->capture.active = codec_dai->capture.active = 0;
333 if (codec_dai->playback.active == 0 &&
334 codec_dai->capture.active == 0) {
335 cpu_dai->active = codec_dai->active = 0;
339 if (cpu_dai->ops.shutdown)
340 cpu_dai->ops.shutdown(substream);
342 if (codec_dai->ops.shutdown)
343 codec_dai->ops.shutdown(substream);
345 if (machine->ops && machine->ops->shutdown)
346 machine->ops->shutdown(substream);
348 if (platform->pcm_ops->close)
349 platform->pcm_ops->close(substream);
350 cpu_dai->runtime = NULL;
352 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
353 /* start delayed pop wq here for playback streams */
354 codec_dai->pop_wait = 1;
355 schedule_delayed_work(&socdev->delayed_work,
356 msecs_to_jiffies(pmdown_time));
358 /* capture streams can be powered down now */
359 snd_soc_dapm_stream_event(codec,
360 codec_dai->capture.stream_name,
361 SND_SOC_DAPM_STREAM_STOP);
363 if (codec->active == 0 && codec_dai->pop_wait == 0)
364 snd_soc_dapm_device_event(socdev,
365 SNDRV_CTL_POWER_D3hot);
368 mutex_unlock(&pcm_mutex);
373 * Called by ALSA when the PCM substream is prepared, can set format, sample
374 * rate, etc. This function is non atomic and can be called multiple times,
375 * it can refer to the runtime info.
377 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
379 struct snd_soc_pcm_runtime *rtd = substream->private_data;
380 struct snd_soc_device *socdev = rtd->socdev;
381 struct snd_soc_dai_link *machine = rtd->dai;
382 struct snd_soc_platform *platform = socdev->platform;
383 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
384 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
385 struct snd_soc_codec *codec = socdev->codec;
388 mutex_lock(&pcm_mutex);
390 if (machine->ops && machine->ops->prepare) {
391 ret = machine->ops->prepare(substream);
393 printk(KERN_ERR "asoc: machine prepare error\n");
398 if (platform->pcm_ops->prepare) {
399 ret = platform->pcm_ops->prepare(substream);
401 printk(KERN_ERR "asoc: platform prepare error\n");
406 if (codec_dai->ops.prepare) {
407 ret = codec_dai->ops.prepare(substream);
409 printk(KERN_ERR "asoc: codec DAI prepare error\n");
414 if (cpu_dai->ops.prepare) {
415 ret = cpu_dai->ops.prepare(substream);
417 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
422 /* we only want to start a DAPM playback stream if we are not waiting
423 * on an existing one stopping */
424 if (codec_dai->pop_wait) {
425 /* we are waiting for the delayed work to start */
426 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
427 snd_soc_dapm_stream_event(socdev->codec,
428 codec_dai->capture.stream_name,
429 SND_SOC_DAPM_STREAM_START);
431 codec_dai->pop_wait = 0;
432 cancel_delayed_work(&socdev->delayed_work);
433 if (codec_dai->dai_ops.digital_mute)
434 codec_dai->dai_ops.digital_mute(codec_dai, 0);
437 /* no delayed work - do we need to power up codec */
438 if (codec->dapm_state != SNDRV_CTL_POWER_D0) {
440 snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D1);
442 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
443 snd_soc_dapm_stream_event(codec,
444 codec_dai->playback.stream_name,
445 SND_SOC_DAPM_STREAM_START);
447 snd_soc_dapm_stream_event(codec,
448 codec_dai->capture.stream_name,
449 SND_SOC_DAPM_STREAM_START);
451 snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D0);
452 if (codec_dai->dai_ops.digital_mute)
453 codec_dai->dai_ops.digital_mute(codec_dai, 0);
456 /* codec already powered - power on widgets */
457 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
458 snd_soc_dapm_stream_event(codec,
459 codec_dai->playback.stream_name,
460 SND_SOC_DAPM_STREAM_START);
462 snd_soc_dapm_stream_event(codec,
463 codec_dai->capture.stream_name,
464 SND_SOC_DAPM_STREAM_START);
465 if (codec_dai->dai_ops.digital_mute)
466 codec_dai->dai_ops.digital_mute(codec_dai, 0);
471 mutex_unlock(&pcm_mutex);
476 * Called by ALSA when the hardware params are set by application. This
477 * function can also be called multiple times and can allocate buffers
478 * (using snd_pcm_lib_* ). It's non-atomic.
480 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
481 struct snd_pcm_hw_params *params)
483 struct snd_soc_pcm_runtime *rtd = substream->private_data;
484 struct snd_soc_device *socdev = rtd->socdev;
485 struct snd_soc_dai_link *machine = rtd->dai;
486 struct snd_soc_platform *platform = socdev->platform;
487 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
488 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
491 mutex_lock(&pcm_mutex);
493 if (machine->ops && machine->ops->hw_params) {
494 ret = machine->ops->hw_params(substream, params);
496 printk(KERN_ERR "asoc: machine hw_params failed\n");
501 if (codec_dai->ops.hw_params) {
502 ret = codec_dai->ops.hw_params(substream, params);
504 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
510 if (cpu_dai->ops.hw_params) {
511 ret = cpu_dai->ops.hw_params(substream, params);
513 printk(KERN_ERR "asoc: can't set interface %s hw params\n",
519 if (platform->pcm_ops->hw_params) {
520 ret = platform->pcm_ops->hw_params(substream, params);
522 printk(KERN_ERR "asoc: can't set platform %s hw params\n",
529 mutex_unlock(&pcm_mutex);
533 if (cpu_dai->ops.hw_free)
534 cpu_dai->ops.hw_free(substream);
537 if (codec_dai->ops.hw_free)
538 codec_dai->ops.hw_free(substream);
541 if(machine->ops && machine->ops->hw_free)
542 machine->ops->hw_free(substream);
544 mutex_unlock(&pcm_mutex);
549 * Free's resources allocated by hw_params, can be called multiple times
551 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
553 struct snd_soc_pcm_runtime *rtd = substream->private_data;
554 struct snd_soc_device *socdev = rtd->socdev;
555 struct snd_soc_dai_link *machine = rtd->dai;
556 struct snd_soc_platform *platform = socdev->platform;
557 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
558 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
559 struct snd_soc_codec *codec = socdev->codec;
561 mutex_lock(&pcm_mutex);
563 /* apply codec digital mute */
564 if (!codec->active && codec_dai->dai_ops.digital_mute)
565 codec_dai->dai_ops.digital_mute(codec_dai, 1);
567 /* free any machine hw params */
568 if (machine->ops && machine->ops->hw_free)
569 machine->ops->hw_free(substream);
571 /* free any DMA resources */
572 if (platform->pcm_ops->hw_free)
573 platform->pcm_ops->hw_free(substream);
575 /* now free hw params for the DAI's */
576 if (codec_dai->ops.hw_free)
577 codec_dai->ops.hw_free(substream);
579 if (cpu_dai->ops.hw_free)
580 cpu_dai->ops.hw_free(substream);
582 mutex_unlock(&pcm_mutex);
586 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
588 struct snd_soc_pcm_runtime *rtd = substream->private_data;
589 struct snd_soc_device *socdev = rtd->socdev;
590 struct snd_soc_dai_link *machine = rtd->dai;
591 struct snd_soc_platform *platform = socdev->platform;
592 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
593 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
596 if (codec_dai->ops.trigger) {
597 ret = codec_dai->ops.trigger(substream, cmd);
602 if (platform->pcm_ops->trigger) {
603 ret = platform->pcm_ops->trigger(substream, cmd);
608 if (cpu_dai->ops.trigger) {
609 ret = cpu_dai->ops.trigger(substream, cmd);
616 /* ASoC PCM operations */
617 static struct snd_pcm_ops soc_pcm_ops = {
618 .open = soc_pcm_open,
619 .close = soc_codec_close,
620 .hw_params = soc_pcm_hw_params,
621 .hw_free = soc_pcm_hw_free,
622 .prepare = soc_pcm_prepare,
623 .trigger = soc_pcm_trigger,
627 /* powers down audio subsystem for suspend */
628 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
630 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
631 struct snd_soc_machine *machine = socdev->machine;
632 struct snd_soc_platform *platform = socdev->platform;
633 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
634 struct snd_soc_codec *codec = socdev->codec;
637 /* mute any active DAC's */
638 for(i = 0; i < machine->num_links; i++) {
639 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
640 if (dai->dai_ops.digital_mute && dai->playback.active)
641 dai->dai_ops.digital_mute(dai, 1);
644 /* suspend all pcms */
645 for (i = 0; i < machine->num_links; i++)
646 snd_pcm_suspend_all(machine->dai_link[i].pcm);
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 = {
838 .owner = THIS_MODULE,
841 .remove = soc_remove,
842 .suspend = soc_suspend,
843 .resume = soc_resume,
846 /* create a new pcm */
847 static int soc_new_pcm(struct snd_soc_device *socdev,
848 struct snd_soc_dai_link *dai_link, int num)
850 struct snd_soc_codec *codec = socdev->codec;
851 struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
852 struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
853 struct snd_soc_pcm_runtime *rtd;
856 int ret = 0, playback = 0, capture = 0;
858 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
863 rtd->socdev = socdev;
864 codec_dai->codec = socdev->codec;
866 /* check client and interface hw capabilities */
867 sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
868 get_dai_name(cpu_dai->type), num);
870 if (codec_dai->playback.channels_min)
872 if (codec_dai->capture.channels_min)
875 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
878 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
884 pcm->private_data = rtd;
885 soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
886 soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
887 soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
888 soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
889 soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
890 soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
891 soc_pcm_ops.page = socdev->platform->pcm_ops->page;
894 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
897 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
899 ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
901 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
906 pcm->private_free = socdev->platform->pcm_free;
907 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
912 /* codec register dump */
913 static ssize_t codec_reg_show(struct device *dev,
914 struct device_attribute *attr, char *buf)
916 struct snd_soc_device *devdata = dev_get_drvdata(dev);
917 struct snd_soc_codec *codec = devdata->codec;
918 int i, step = 1, count = 0;
920 if (!codec->reg_cache_size)
923 if (codec->reg_cache_step)
924 step = codec->reg_cache_step;
926 count += sprintf(buf, "%s registers\n", codec->name);
927 for(i = 0; i < codec->reg_cache_size; i += step)
928 count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
932 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
935 * snd_soc_new_ac97_codec - initailise AC97 device
936 * @codec: audio codec
937 * @ops: AC97 bus operations
938 * @num: AC97 codec number
940 * Initialises AC97 codec resources for use by ad-hoc devices only.
942 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
943 struct snd_ac97_bus_ops *ops, int num)
945 mutex_lock(&codec->mutex);
947 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
948 if (codec->ac97 == NULL) {
949 mutex_unlock(&codec->mutex);
953 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
954 if (codec->ac97->bus == NULL) {
957 mutex_unlock(&codec->mutex);
961 codec->ac97->bus->ops = ops;
962 codec->ac97->num = num;
963 mutex_unlock(&codec->mutex);
966 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
969 * snd_soc_free_ac97_codec - free AC97 codec device
970 * @codec: audio codec
972 * Frees AC97 codec device resources.
974 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
976 mutex_lock(&codec->mutex);
977 kfree(codec->ac97->bus);
980 mutex_unlock(&codec->mutex);
982 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
985 * snd_soc_update_bits - update codec register bits
986 * @codec: audio codec
987 * @reg: codec register
988 * @mask: register mask
991 * Writes new register value.
993 * Returns 1 for change else 0.
995 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
996 unsigned short mask, unsigned short value)
999 unsigned short old, new;
1001 mutex_lock(&io_mutex);
1002 old = snd_soc_read(codec, reg);
1003 new = (old & ~mask) | value;
1004 change = old != new;
1006 snd_soc_write(codec, reg, new);
1008 mutex_unlock(&io_mutex);
1011 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1014 * snd_soc_test_bits - test register for change
1015 * @codec: audio codec
1016 * @reg: codec register
1017 * @mask: register mask
1020 * Tests a register with a new value and checks if the new value is
1021 * different from the old value.
1023 * Returns 1 for change else 0.
1025 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1026 unsigned short mask, unsigned short value)
1029 unsigned short old, new;
1031 mutex_lock(&io_mutex);
1032 old = snd_soc_read(codec, reg);
1033 new = (old & ~mask) | value;
1034 change = old != new;
1035 mutex_unlock(&io_mutex);
1039 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1042 * snd_soc_new_pcms - create new sound card and pcms
1043 * @socdev: the SoC audio device
1045 * Create a new sound card based upon the codec and interface pcms.
1047 * Returns 0 for success, else error.
1049 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1051 struct snd_soc_codec *codec = socdev->codec;
1052 struct snd_soc_machine *machine = socdev->machine;
1055 mutex_lock(&codec->mutex);
1057 /* register a sound card */
1058 codec->card = snd_card_new(idx, xid, codec->owner, 0);
1060 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1062 mutex_unlock(&codec->mutex);
1066 codec->card->dev = socdev->dev;
1067 codec->card->private_data = codec;
1068 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1070 /* create the pcms */
1071 for(i = 0; i < machine->num_links; i++) {
1072 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1074 printk(KERN_ERR "asoc: can't create pcm %s\n",
1075 machine->dai_link[i].stream_name);
1076 mutex_unlock(&codec->mutex);
1081 mutex_unlock(&codec->mutex);
1084 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1087 * snd_soc_register_card - register sound card
1088 * @socdev: the SoC audio device
1090 * Register a SoC sound card. Also registers an AC97 device if the
1091 * codec is AC97 for ad hoc devices.
1093 * Returns 0 for success, else error.
1095 int snd_soc_register_card(struct snd_soc_device *socdev)
1097 struct snd_soc_codec *codec = socdev->codec;
1098 struct snd_soc_machine *machine = socdev->machine;
1099 int ret = 0, i, ac97 = 0, err = 0;
1101 for(i = 0; i < machine->num_links; i++) {
1102 if (socdev->machine->dai_link[i].init) {
1103 err = socdev->machine->dai_link[i].init(codec);
1105 printk(KERN_ERR "asoc: failed to init %s\n",
1106 socdev->machine->dai_link[i].stream_name);
1110 if (socdev->machine->dai_link[i].codec_dai->type ==
1111 SND_SOC_DAI_AC97_BUS)
1114 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1115 "%s", machine->name);
1116 snprintf(codec->card->longname, sizeof(codec->card->longname),
1117 "%s (%s)", machine->name, codec->name);
1119 ret = snd_card_register(codec->card);
1121 printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
1126 mutex_lock(&codec->mutex);
1127 #ifdef CONFIG_SND_SOC_AC97_BUS
1129 ret = soc_ac97_dev_register(codec);
1131 printk(KERN_ERR "asoc: AC97 device register failed\n");
1132 snd_card_free(codec->card);
1133 mutex_unlock(&codec->mutex);
1139 err = snd_soc_dapm_sys_add(socdev->dev);
1141 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1143 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1145 printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
1147 mutex_unlock(&codec->mutex);
1152 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1155 * snd_soc_free_pcms - free sound card and pcms
1156 * @socdev: the SoC audio device
1158 * Frees sound card and pcms associated with the socdev.
1159 * Also unregister the codec if it is an AC97 device.
1161 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1163 struct snd_soc_codec *codec = socdev->codec;
1164 #ifdef CONFIG_SND_SOC_AC97_BUS
1165 struct snd_soc_codec_dai *codec_dai;
1169 mutex_lock(&codec->mutex);
1170 #ifdef CONFIG_SND_SOC_AC97_BUS
1171 for(i = 0; i < codec->num_dai; i++) {
1172 codec_dai = &codec->dai[i];
1173 if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
1174 soc_ac97_dev_unregister(codec);
1182 snd_card_free(codec->card);
1183 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1184 mutex_unlock(&codec->mutex);
1186 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1189 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1190 * @substream: the pcm substream
1191 * @hw: the hardware parameters
1193 * Sets the substream runtime hardware parameters.
1195 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1196 const struct snd_pcm_hardware *hw)
1198 struct snd_pcm_runtime *runtime = substream->runtime;
1199 runtime->hw.info = hw->info;
1200 runtime->hw.formats = hw->formats;
1201 runtime->hw.period_bytes_min = hw->period_bytes_min;
1202 runtime->hw.period_bytes_max = hw->period_bytes_max;
1203 runtime->hw.periods_min = hw->periods_min;
1204 runtime->hw.periods_max = hw->periods_max;
1205 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1206 runtime->hw.fifo_size = hw->fifo_size;
1209 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1212 * snd_soc_cnew - create new control
1213 * @_template: control template
1214 * @data: control private data
1215 * @lnng_name: control long name
1217 * Create a new mixer control from a template control.
1219 * Returns 0 for success, else error.
1221 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1222 void *data, char *long_name)
1224 struct snd_kcontrol_new template;
1226 memcpy(&template, _template, sizeof(template));
1228 template.name = long_name;
1231 return snd_ctl_new1(&template, data);
1233 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1236 * snd_soc_info_enum_double - enumerated double mixer info callback
1237 * @kcontrol: mixer control
1238 * @uinfo: control element information
1240 * Callback to provide information about a double enumerated
1243 * Returns 0 for success.
1245 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1246 struct snd_ctl_elem_info *uinfo)
1248 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1250 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1251 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1252 uinfo->value.enumerated.items = e->mask;
1254 if (uinfo->value.enumerated.item > e->mask - 1)
1255 uinfo->value.enumerated.item = e->mask - 1;
1256 strcpy(uinfo->value.enumerated.name,
1257 e->texts[uinfo->value.enumerated.item]);
1260 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1263 * snd_soc_get_enum_double - enumerated double mixer get callback
1264 * @kcontrol: mixer control
1265 * @uinfo: control element information
1267 * Callback to get the value of a double enumerated mixer.
1269 * Returns 0 for success.
1271 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1272 struct snd_ctl_elem_value *ucontrol)
1274 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1275 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1276 unsigned short val, bitmask;
1278 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1280 val = snd_soc_read(codec, e->reg);
1281 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1282 if (e->shift_l != e->shift_r)
1283 ucontrol->value.enumerated.item[1] =
1284 (val >> e->shift_r) & (bitmask - 1);
1288 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1291 * snd_soc_put_enum_double - enumerated double mixer put callback
1292 * @kcontrol: mixer control
1293 * @uinfo: control element information
1295 * Callback to set the value of a double enumerated mixer.
1297 * Returns 0 for success.
1299 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1300 struct snd_ctl_elem_value *ucontrol)
1302 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1303 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1305 unsigned short mask, bitmask;
1307 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1309 if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1311 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1312 mask = (bitmask - 1) << e->shift_l;
1313 if (e->shift_l != e->shift_r) {
1314 if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1316 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1317 mask |= (bitmask - 1) << e->shift_r;
1320 return snd_soc_update_bits(codec, e->reg, mask, val);
1322 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1325 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1326 * @kcontrol: mixer control
1327 * @uinfo: control element information
1329 * Callback to provide information about an external enumerated
1332 * Returns 0 for success.
1334 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1335 struct snd_ctl_elem_info *uinfo)
1337 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1339 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1341 uinfo->value.enumerated.items = e->mask;
1343 if (uinfo->value.enumerated.item > e->mask - 1)
1344 uinfo->value.enumerated.item = e->mask - 1;
1345 strcpy(uinfo->value.enumerated.name,
1346 e->texts[uinfo->value.enumerated.item]);
1349 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1352 * snd_soc_info_volsw_ext - external single mixer info callback
1353 * @kcontrol: mixer control
1354 * @uinfo: control element information
1356 * Callback to provide information about a single external mixer control.
1358 * Returns 0 for success.
1360 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1361 struct snd_ctl_elem_info *uinfo)
1363 int max = kcontrol->private_value;
1366 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1368 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1371 uinfo->value.integer.min = 0;
1372 uinfo->value.integer.max = max;
1375 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1378 * snd_soc_info_volsw - single mixer info callback
1379 * @kcontrol: mixer control
1380 * @uinfo: control element information
1382 * Callback to provide information about a single mixer control.
1384 * Returns 0 for success.
1386 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1387 struct snd_ctl_elem_info *uinfo)
1389 int max = (kcontrol->private_value >> 16) & 0xff;
1390 int shift = (kcontrol->private_value >> 8) & 0x0f;
1391 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1394 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1396 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1398 uinfo->count = shift == rshift ? 1 : 2;
1399 uinfo->value.integer.min = 0;
1400 uinfo->value.integer.max = max;
1403 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1406 * snd_soc_get_volsw - single mixer get callback
1407 * @kcontrol: mixer control
1408 * @uinfo: control element information
1410 * Callback to get the value of a single mixer control.
1412 * Returns 0 for success.
1414 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1415 struct snd_ctl_elem_value *ucontrol)
1417 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1418 int reg = kcontrol->private_value & 0xff;
1419 int shift = (kcontrol->private_value >> 8) & 0x0f;
1420 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1421 int max = (kcontrol->private_value >> 16) & 0xff;
1422 int mask = (1 << fls(max)) - 1;
1423 int invert = (kcontrol->private_value >> 24) & 0x01;
1425 ucontrol->value.integer.value[0] =
1426 (snd_soc_read(codec, reg) >> shift) & mask;
1427 if (shift != rshift)
1428 ucontrol->value.integer.value[1] =
1429 (snd_soc_read(codec, reg) >> rshift) & mask;
1431 ucontrol->value.integer.value[0] =
1432 max - ucontrol->value.integer.value[0];
1433 if (shift != rshift)
1434 ucontrol->value.integer.value[1] =
1435 max - ucontrol->value.integer.value[1];
1440 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1443 * snd_soc_put_volsw - single mixer put callback
1444 * @kcontrol: mixer control
1445 * @uinfo: control element information
1447 * Callback to set the value of a single mixer control.
1449 * Returns 0 for success.
1451 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1452 struct snd_ctl_elem_value *ucontrol)
1454 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1455 int reg = kcontrol->private_value & 0xff;
1456 int shift = (kcontrol->private_value >> 8) & 0x0f;
1457 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1458 int max = (kcontrol->private_value >> 16) & 0xff;
1459 int mask = (1 << fls(max)) - 1;
1460 int invert = (kcontrol->private_value >> 24) & 0x01;
1461 unsigned short val, val2, val_mask;
1463 val = (ucontrol->value.integer.value[0] & mask);
1466 val_mask = mask << shift;
1468 if (shift != rshift) {
1469 val2 = (ucontrol->value.integer.value[1] & mask);
1472 val_mask |= mask << rshift;
1473 val |= val2 << rshift;
1475 return snd_soc_update_bits(codec, reg, val_mask, val);
1477 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1480 * snd_soc_info_volsw_2r - double mixer info callback
1481 * @kcontrol: mixer control
1482 * @uinfo: control element information
1484 * Callback to provide information about a double mixer control that
1485 * spans 2 codec registers.
1487 * Returns 0 for success.
1489 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_info *uinfo)
1492 int max = (kcontrol->private_value >> 12) & 0xff;
1495 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1497 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1500 uinfo->value.integer.min = 0;
1501 uinfo->value.integer.max = max;
1504 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1507 * snd_soc_get_volsw_2r - double mixer get callback
1508 * @kcontrol: mixer control
1509 * @uinfo: control element information
1511 * Callback to get the value of a double mixer control that spans 2 registers.
1513 * Returns 0 for success.
1515 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1516 struct snd_ctl_elem_value *ucontrol)
1518 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1519 int reg = kcontrol->private_value & 0xff;
1520 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1521 int shift = (kcontrol->private_value >> 8) & 0x0f;
1522 int max = (kcontrol->private_value >> 12) & 0xff;
1523 int mask = (1<<fls(max))-1;
1524 int invert = (kcontrol->private_value >> 20) & 0x01;
1526 ucontrol->value.integer.value[0] =
1527 (snd_soc_read(codec, reg) >> shift) & mask;
1528 ucontrol->value.integer.value[1] =
1529 (snd_soc_read(codec, reg2) >> shift) & mask;
1531 ucontrol->value.integer.value[0] =
1532 max - ucontrol->value.integer.value[0];
1533 ucontrol->value.integer.value[1] =
1534 max - ucontrol->value.integer.value[1];
1539 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1542 * snd_soc_put_volsw_2r - double mixer set callback
1543 * @kcontrol: mixer control
1544 * @uinfo: control element information
1546 * Callback to set the value of a double mixer control that spans 2 registers.
1548 * Returns 0 for success.
1550 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_value *ucontrol)
1553 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1554 int reg = kcontrol->private_value & 0xff;
1555 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1556 int shift = (kcontrol->private_value >> 8) & 0x0f;
1557 int max = (kcontrol->private_value >> 12) & 0xff;
1558 int mask = (1 << fls(max)) - 1;
1559 int invert = (kcontrol->private_value >> 20) & 0x01;
1561 unsigned short val, val2, val_mask;
1563 val_mask = mask << shift;
1564 val = (ucontrol->value.integer.value[0] & mask);
1565 val2 = (ucontrol->value.integer.value[1] & mask);
1573 val2 = val2 << shift;
1575 if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
1578 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1581 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1583 static int __devinit snd_soc_init(void)
1585 printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1586 return platform_driver_register(&soc_driver);
1589 static void snd_soc_exit(void)
1591 platform_driver_unregister(&soc_driver);
1594 module_init(snd_soc_init);
1595 module_exit(snd_soc_exit);
1597 /* Module information */
1598 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1599 MODULE_DESCRIPTION("ALSA SoC Core");
1600 MODULE_LICENSE("GPL");
1601 MODULE_ALIAS("platform:soc-audio");