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 /* Reduce power 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_set_bias_level(socdev,
291 SND_SOC_BIAS_PREPARE);
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 /* Fall into standby 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_set_bias_level(socdev,
304 SND_SOC_BIAS_STANDBY);
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_set_bias_level(socdev,
365 SND_SOC_BIAS_STANDBY);
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->bias_level != SND_SOC_BIAS_ON) {
440 snd_soc_dapm_set_bias_level(socdev,
441 SND_SOC_BIAS_PREPARE);
443 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
444 snd_soc_dapm_stream_event(codec,
445 codec_dai->playback.stream_name,
446 SND_SOC_DAPM_STREAM_START);
448 snd_soc_dapm_stream_event(codec,
449 codec_dai->capture.stream_name,
450 SND_SOC_DAPM_STREAM_START);
452 snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
453 if (codec_dai->dai_ops.digital_mute)
454 codec_dai->dai_ops.digital_mute(codec_dai, 0);
457 /* codec already powered - power on widgets */
458 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
459 snd_soc_dapm_stream_event(codec,
460 codec_dai->playback.stream_name,
461 SND_SOC_DAPM_STREAM_START);
463 snd_soc_dapm_stream_event(codec,
464 codec_dai->capture.stream_name,
465 SND_SOC_DAPM_STREAM_START);
466 if (codec_dai->dai_ops.digital_mute)
467 codec_dai->dai_ops.digital_mute(codec_dai, 0);
472 mutex_unlock(&pcm_mutex);
477 * Called by ALSA when the hardware params are set by application. This
478 * function can also be called multiple times and can allocate buffers
479 * (using snd_pcm_lib_* ). It's non-atomic.
481 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
482 struct snd_pcm_hw_params *params)
484 struct snd_soc_pcm_runtime *rtd = substream->private_data;
485 struct snd_soc_device *socdev = rtd->socdev;
486 struct snd_soc_dai_link *machine = rtd->dai;
487 struct snd_soc_platform *platform = socdev->platform;
488 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
489 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
492 mutex_lock(&pcm_mutex);
494 if (machine->ops && machine->ops->hw_params) {
495 ret = machine->ops->hw_params(substream, params);
497 printk(KERN_ERR "asoc: machine hw_params failed\n");
502 if (codec_dai->ops.hw_params) {
503 ret = codec_dai->ops.hw_params(substream, params);
505 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
511 if (cpu_dai->ops.hw_params) {
512 ret = cpu_dai->ops.hw_params(substream, params);
514 printk(KERN_ERR "asoc: can't set interface %s hw params\n",
520 if (platform->pcm_ops->hw_params) {
521 ret = platform->pcm_ops->hw_params(substream, params);
523 printk(KERN_ERR "asoc: can't set platform %s hw params\n",
530 mutex_unlock(&pcm_mutex);
534 if (cpu_dai->ops.hw_free)
535 cpu_dai->ops.hw_free(substream);
538 if (codec_dai->ops.hw_free)
539 codec_dai->ops.hw_free(substream);
542 if(machine->ops && machine->ops->hw_free)
543 machine->ops->hw_free(substream);
545 mutex_unlock(&pcm_mutex);
550 * Free's resources allocated by hw_params, can be called multiple times
552 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
554 struct snd_soc_pcm_runtime *rtd = substream->private_data;
555 struct snd_soc_device *socdev = rtd->socdev;
556 struct snd_soc_dai_link *machine = rtd->dai;
557 struct snd_soc_platform *platform = socdev->platform;
558 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
559 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
560 struct snd_soc_codec *codec = socdev->codec;
562 mutex_lock(&pcm_mutex);
564 /* apply codec digital mute */
565 if (!codec->active && codec_dai->dai_ops.digital_mute)
566 codec_dai->dai_ops.digital_mute(codec_dai, 1);
568 /* free any machine hw params */
569 if (machine->ops && machine->ops->hw_free)
570 machine->ops->hw_free(substream);
572 /* free any DMA resources */
573 if (platform->pcm_ops->hw_free)
574 platform->pcm_ops->hw_free(substream);
576 /* now free hw params for the DAI's */
577 if (codec_dai->ops.hw_free)
578 codec_dai->ops.hw_free(substream);
580 if (cpu_dai->ops.hw_free)
581 cpu_dai->ops.hw_free(substream);
583 mutex_unlock(&pcm_mutex);
587 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
589 struct snd_soc_pcm_runtime *rtd = substream->private_data;
590 struct snd_soc_device *socdev = rtd->socdev;
591 struct snd_soc_dai_link *machine = rtd->dai;
592 struct snd_soc_platform *platform = socdev->platform;
593 struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
594 struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
597 if (codec_dai->ops.trigger) {
598 ret = codec_dai->ops.trigger(substream, cmd);
603 if (platform->pcm_ops->trigger) {
604 ret = platform->pcm_ops->trigger(substream, cmd);
609 if (cpu_dai->ops.trigger) {
610 ret = cpu_dai->ops.trigger(substream, cmd);
617 /* ASoC PCM operations */
618 static struct snd_pcm_ops soc_pcm_ops = {
619 .open = soc_pcm_open,
620 .close = soc_codec_close,
621 .hw_params = soc_pcm_hw_params,
622 .hw_free = soc_pcm_hw_free,
623 .prepare = soc_pcm_prepare,
624 .trigger = soc_pcm_trigger,
628 /* powers down audio subsystem for suspend */
629 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
631 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
632 struct snd_soc_machine *machine = socdev->machine;
633 struct snd_soc_platform *platform = socdev->platform;
634 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
635 struct snd_soc_codec *codec = socdev->codec;
638 /* mute any active DAC's */
639 for(i = 0; i < machine->num_links; i++) {
640 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
641 if (dai->dai_ops.digital_mute && dai->playback.active)
642 dai->dai_ops.digital_mute(dai, 1);
645 /* suspend all pcms */
646 for (i = 0; i < machine->num_links; i++)
647 snd_pcm_suspend_all(machine->dai_link[i].pcm);
649 if (machine->suspend_pre)
650 machine->suspend_pre(pdev, state);
652 for(i = 0; i < machine->num_links; i++) {
653 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
654 if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
655 cpu_dai->suspend(pdev, cpu_dai);
656 if (platform->suspend)
657 platform->suspend(pdev, cpu_dai);
660 /* close any waiting streams and save state */
661 run_delayed_work(&socdev->delayed_work);
662 codec->suspend_bias_level = codec->bias_level;
664 for(i = 0; i < codec->num_dai; i++) {
665 char *stream = codec->dai[i].playback.stream_name;
667 snd_soc_dapm_stream_event(codec, stream,
668 SND_SOC_DAPM_STREAM_SUSPEND);
669 stream = codec->dai[i].capture.stream_name;
671 snd_soc_dapm_stream_event(codec, stream,
672 SND_SOC_DAPM_STREAM_SUSPEND);
675 if (codec_dev->suspend)
676 codec_dev->suspend(pdev, state);
678 for(i = 0; i < machine->num_links; i++) {
679 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
680 if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
681 cpu_dai->suspend(pdev, cpu_dai);
684 if (machine->suspend_post)
685 machine->suspend_post(pdev, state);
690 /* powers up audio subsystem after a suspend */
691 static int soc_resume(struct platform_device *pdev)
693 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
694 struct snd_soc_machine *machine = socdev->machine;
695 struct snd_soc_platform *platform = socdev->platform;
696 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
697 struct snd_soc_codec *codec = socdev->codec;
700 if (machine->resume_pre)
701 machine->resume_pre(pdev);
703 for(i = 0; i < machine->num_links; i++) {
704 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
705 if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
706 cpu_dai->resume(pdev, cpu_dai);
709 if (codec_dev->resume)
710 codec_dev->resume(pdev);
712 for(i = 0; i < codec->num_dai; i++) {
713 char* stream = codec->dai[i].playback.stream_name;
715 snd_soc_dapm_stream_event(codec, stream,
716 SND_SOC_DAPM_STREAM_RESUME);
717 stream = codec->dai[i].capture.stream_name;
719 snd_soc_dapm_stream_event(codec, stream,
720 SND_SOC_DAPM_STREAM_RESUME);
723 /* unmute any active DAC's */
724 for(i = 0; i < machine->num_links; i++) {
725 struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
726 if (dai->dai_ops.digital_mute && dai->playback.active)
727 dai->dai_ops.digital_mute(dai, 0);
730 for(i = 0; i < machine->num_links; i++) {
731 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
732 if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
733 cpu_dai->resume(pdev, cpu_dai);
734 if (platform->resume)
735 platform->resume(pdev, cpu_dai);
738 if (machine->resume_post)
739 machine->resume_post(pdev);
745 #define soc_suspend NULL
746 #define soc_resume NULL
749 /* probes a new socdev */
750 static int soc_probe(struct platform_device *pdev)
753 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
754 struct snd_soc_machine *machine = socdev->machine;
755 struct snd_soc_platform *platform = socdev->platform;
756 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
758 if (machine->probe) {
759 ret = machine->probe(pdev);
764 for (i = 0; i < machine->num_links; i++) {
765 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
766 if (cpu_dai->probe) {
767 ret = cpu_dai->probe(pdev);
773 if (codec_dev->probe) {
774 ret = codec_dev->probe(pdev);
779 if (platform->probe) {
780 ret = platform->probe(pdev);
785 /* DAPM stream work */
786 INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
790 if (codec_dev->remove)
791 codec_dev->remove(pdev);
794 for (i--; i >= 0; i--) {
795 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
797 cpu_dai->remove(pdev);
801 machine->remove(pdev);
806 /* removes a socdev */
807 static int soc_remove(struct platform_device *pdev)
810 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
811 struct snd_soc_machine *machine = socdev->machine;
812 struct snd_soc_platform *platform = socdev->platform;
813 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
815 run_delayed_work(&socdev->delayed_work);
817 if (platform->remove)
818 platform->remove(pdev);
820 if (codec_dev->remove)
821 codec_dev->remove(pdev);
823 for (i = 0; i < machine->num_links; i++) {
824 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
826 cpu_dai->remove(pdev);
830 machine->remove(pdev);
835 /* ASoC platform driver */
836 static struct platform_driver soc_driver = {
839 .owner = THIS_MODULE,
842 .remove = soc_remove,
843 .suspend = soc_suspend,
844 .resume = soc_resume,
847 /* create a new pcm */
848 static int soc_new_pcm(struct snd_soc_device *socdev,
849 struct snd_soc_dai_link *dai_link, int num)
851 struct snd_soc_codec *codec = socdev->codec;
852 struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
853 struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
854 struct snd_soc_pcm_runtime *rtd;
857 int ret = 0, playback = 0, capture = 0;
859 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
864 rtd->socdev = socdev;
865 codec_dai->codec = socdev->codec;
867 /* check client and interface hw capabilities */
868 sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
869 get_dai_name(cpu_dai->type), num);
871 if (codec_dai->playback.channels_min)
873 if (codec_dai->capture.channels_min)
876 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
879 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
885 pcm->private_data = rtd;
886 soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
887 soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
888 soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
889 soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
890 soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
891 soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
892 soc_pcm_ops.page = socdev->platform->pcm_ops->page;
895 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
898 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
900 ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
902 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
907 pcm->private_free = socdev->platform->pcm_free;
908 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
913 /* codec register dump */
914 static ssize_t codec_reg_show(struct device *dev,
915 struct device_attribute *attr, char *buf)
917 struct snd_soc_device *devdata = dev_get_drvdata(dev);
918 struct snd_soc_codec *codec = devdata->codec;
919 int i, step = 1, count = 0;
921 if (!codec->reg_cache_size)
924 if (codec->reg_cache_step)
925 step = codec->reg_cache_step;
927 count += sprintf(buf, "%s registers\n", codec->name);
928 for(i = 0; i < codec->reg_cache_size; i += step)
929 count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
933 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
936 * snd_soc_new_ac97_codec - initailise AC97 device
937 * @codec: audio codec
938 * @ops: AC97 bus operations
939 * @num: AC97 codec number
941 * Initialises AC97 codec resources for use by ad-hoc devices only.
943 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
944 struct snd_ac97_bus_ops *ops, int num)
946 mutex_lock(&codec->mutex);
948 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
949 if (codec->ac97 == NULL) {
950 mutex_unlock(&codec->mutex);
954 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
955 if (codec->ac97->bus == NULL) {
958 mutex_unlock(&codec->mutex);
962 codec->ac97->bus->ops = ops;
963 codec->ac97->num = num;
964 mutex_unlock(&codec->mutex);
967 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
970 * snd_soc_free_ac97_codec - free AC97 codec device
971 * @codec: audio codec
973 * Frees AC97 codec device resources.
975 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
977 mutex_lock(&codec->mutex);
978 kfree(codec->ac97->bus);
981 mutex_unlock(&codec->mutex);
983 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
986 * snd_soc_update_bits - update codec register bits
987 * @codec: audio codec
988 * @reg: codec register
989 * @mask: register mask
992 * Writes new register value.
994 * Returns 1 for change else 0.
996 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
997 unsigned short mask, unsigned short value)
1000 unsigned short old, new;
1002 mutex_lock(&io_mutex);
1003 old = snd_soc_read(codec, reg);
1004 new = (old & ~mask) | value;
1005 change = old != new;
1007 snd_soc_write(codec, reg, new);
1009 mutex_unlock(&io_mutex);
1012 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1015 * snd_soc_test_bits - test register for change
1016 * @codec: audio codec
1017 * @reg: codec register
1018 * @mask: register mask
1021 * Tests a register with a new value and checks if the new value is
1022 * different from the old value.
1024 * Returns 1 for change else 0.
1026 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1027 unsigned short mask, unsigned short value)
1030 unsigned short old, new;
1032 mutex_lock(&io_mutex);
1033 old = snd_soc_read(codec, reg);
1034 new = (old & ~mask) | value;
1035 change = old != new;
1036 mutex_unlock(&io_mutex);
1040 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1043 * snd_soc_new_pcms - create new sound card and pcms
1044 * @socdev: the SoC audio device
1046 * Create a new sound card based upon the codec and interface pcms.
1048 * Returns 0 for success, else error.
1050 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1052 struct snd_soc_codec *codec = socdev->codec;
1053 struct snd_soc_machine *machine = socdev->machine;
1056 mutex_lock(&codec->mutex);
1058 /* register a sound card */
1059 codec->card = snd_card_new(idx, xid, codec->owner, 0);
1061 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1063 mutex_unlock(&codec->mutex);
1067 codec->card->dev = socdev->dev;
1068 codec->card->private_data = codec;
1069 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1071 /* create the pcms */
1072 for(i = 0; i < machine->num_links; i++) {
1073 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1075 printk(KERN_ERR "asoc: can't create pcm %s\n",
1076 machine->dai_link[i].stream_name);
1077 mutex_unlock(&codec->mutex);
1082 mutex_unlock(&codec->mutex);
1085 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1088 * snd_soc_register_card - register sound card
1089 * @socdev: the SoC audio device
1091 * Register a SoC sound card. Also registers an AC97 device if the
1092 * codec is AC97 for ad hoc devices.
1094 * Returns 0 for success, else error.
1096 int snd_soc_register_card(struct snd_soc_device *socdev)
1098 struct snd_soc_codec *codec = socdev->codec;
1099 struct snd_soc_machine *machine = socdev->machine;
1100 int ret = 0, i, ac97 = 0, err = 0;
1102 for(i = 0; i < machine->num_links; i++) {
1103 if (socdev->machine->dai_link[i].init) {
1104 err = socdev->machine->dai_link[i].init(codec);
1106 printk(KERN_ERR "asoc: failed to init %s\n",
1107 socdev->machine->dai_link[i].stream_name);
1111 if (socdev->machine->dai_link[i].codec_dai->type ==
1112 SND_SOC_DAI_AC97_BUS)
1115 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1116 "%s", machine->name);
1117 snprintf(codec->card->longname, sizeof(codec->card->longname),
1118 "%s (%s)", machine->name, codec->name);
1120 ret = snd_card_register(codec->card);
1122 printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
1127 mutex_lock(&codec->mutex);
1128 #ifdef CONFIG_SND_SOC_AC97_BUS
1130 ret = soc_ac97_dev_register(codec);
1132 printk(KERN_ERR "asoc: AC97 device register failed\n");
1133 snd_card_free(codec->card);
1134 mutex_unlock(&codec->mutex);
1140 err = snd_soc_dapm_sys_add(socdev->dev);
1142 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1144 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1146 printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
1148 mutex_unlock(&codec->mutex);
1153 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1156 * snd_soc_free_pcms - free sound card and pcms
1157 * @socdev: the SoC audio device
1159 * Frees sound card and pcms associated with the socdev.
1160 * Also unregister the codec if it is an AC97 device.
1162 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1164 struct snd_soc_codec *codec = socdev->codec;
1165 #ifdef CONFIG_SND_SOC_AC97_BUS
1166 struct snd_soc_codec_dai *codec_dai;
1170 mutex_lock(&codec->mutex);
1171 #ifdef CONFIG_SND_SOC_AC97_BUS
1172 for(i = 0; i < codec->num_dai; i++) {
1173 codec_dai = &codec->dai[i];
1174 if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
1175 soc_ac97_dev_unregister(codec);
1183 snd_card_free(codec->card);
1184 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1185 mutex_unlock(&codec->mutex);
1187 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1190 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1191 * @substream: the pcm substream
1192 * @hw: the hardware parameters
1194 * Sets the substream runtime hardware parameters.
1196 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1197 const struct snd_pcm_hardware *hw)
1199 struct snd_pcm_runtime *runtime = substream->runtime;
1200 runtime->hw.info = hw->info;
1201 runtime->hw.formats = hw->formats;
1202 runtime->hw.period_bytes_min = hw->period_bytes_min;
1203 runtime->hw.period_bytes_max = hw->period_bytes_max;
1204 runtime->hw.periods_min = hw->periods_min;
1205 runtime->hw.periods_max = hw->periods_max;
1206 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1207 runtime->hw.fifo_size = hw->fifo_size;
1210 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1213 * snd_soc_cnew - create new control
1214 * @_template: control template
1215 * @data: control private data
1216 * @lnng_name: control long name
1218 * Create a new mixer control from a template control.
1220 * Returns 0 for success, else error.
1222 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1223 void *data, char *long_name)
1225 struct snd_kcontrol_new template;
1227 memcpy(&template, _template, sizeof(template));
1229 template.name = long_name;
1232 return snd_ctl_new1(&template, data);
1234 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1237 * snd_soc_info_enum_double - enumerated double mixer info callback
1238 * @kcontrol: mixer control
1239 * @uinfo: control element information
1241 * Callback to provide information about a double enumerated
1244 * Returns 0 for success.
1246 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1247 struct snd_ctl_elem_info *uinfo)
1249 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1251 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1252 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1253 uinfo->value.enumerated.items = e->mask;
1255 if (uinfo->value.enumerated.item > e->mask - 1)
1256 uinfo->value.enumerated.item = e->mask - 1;
1257 strcpy(uinfo->value.enumerated.name,
1258 e->texts[uinfo->value.enumerated.item]);
1261 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1264 * snd_soc_get_enum_double - enumerated double mixer get callback
1265 * @kcontrol: mixer control
1266 * @uinfo: control element information
1268 * Callback to get the value of a double enumerated mixer.
1270 * Returns 0 for success.
1272 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1273 struct snd_ctl_elem_value *ucontrol)
1275 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1276 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1277 unsigned short val, bitmask;
1279 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1281 val = snd_soc_read(codec, e->reg);
1282 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1283 if (e->shift_l != e->shift_r)
1284 ucontrol->value.enumerated.item[1] =
1285 (val >> e->shift_r) & (bitmask - 1);
1289 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1292 * snd_soc_put_enum_double - enumerated double mixer put callback
1293 * @kcontrol: mixer control
1294 * @uinfo: control element information
1296 * Callback to set the value of a double enumerated mixer.
1298 * Returns 0 for success.
1300 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1301 struct snd_ctl_elem_value *ucontrol)
1303 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1304 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1306 unsigned short mask, bitmask;
1308 for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
1310 if (ucontrol->value.enumerated.item[0] > e->mask - 1)
1312 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1313 mask = (bitmask - 1) << e->shift_l;
1314 if (e->shift_l != e->shift_r) {
1315 if (ucontrol->value.enumerated.item[1] > e->mask - 1)
1317 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1318 mask |= (bitmask - 1) << e->shift_r;
1321 return snd_soc_update_bits(codec, e->reg, mask, val);
1323 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1326 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1327 * @kcontrol: mixer control
1328 * @uinfo: control element information
1330 * Callback to provide information about an external enumerated
1333 * Returns 0 for success.
1335 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_info *uinfo)
1338 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1340 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1342 uinfo->value.enumerated.items = e->mask;
1344 if (uinfo->value.enumerated.item > e->mask - 1)
1345 uinfo->value.enumerated.item = e->mask - 1;
1346 strcpy(uinfo->value.enumerated.name,
1347 e->texts[uinfo->value.enumerated.item]);
1350 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1353 * snd_soc_info_volsw_ext - external single mixer info callback
1354 * @kcontrol: mixer control
1355 * @uinfo: control element information
1357 * Callback to provide information about a single external mixer control.
1359 * Returns 0 for success.
1361 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1362 struct snd_ctl_elem_info *uinfo)
1364 int max = kcontrol->private_value;
1367 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1369 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1372 uinfo->value.integer.min = 0;
1373 uinfo->value.integer.max = max;
1376 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1379 * snd_soc_info_volsw - single mixer info callback
1380 * @kcontrol: mixer control
1381 * @uinfo: control element information
1383 * Callback to provide information about a single mixer control.
1385 * Returns 0 for success.
1387 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1388 struct snd_ctl_elem_info *uinfo)
1390 int max = (kcontrol->private_value >> 16) & 0xff;
1391 int shift = (kcontrol->private_value >> 8) & 0x0f;
1392 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1395 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1397 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1399 uinfo->count = shift == rshift ? 1 : 2;
1400 uinfo->value.integer.min = 0;
1401 uinfo->value.integer.max = max;
1404 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1407 * snd_soc_get_volsw - single mixer get callback
1408 * @kcontrol: mixer control
1409 * @uinfo: control element information
1411 * Callback to get the value of a single mixer control.
1413 * Returns 0 for success.
1415 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1416 struct snd_ctl_elem_value *ucontrol)
1418 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1419 int reg = kcontrol->private_value & 0xff;
1420 int shift = (kcontrol->private_value >> 8) & 0x0f;
1421 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1422 int max = (kcontrol->private_value >> 16) & 0xff;
1423 int mask = (1 << fls(max)) - 1;
1424 int invert = (kcontrol->private_value >> 24) & 0x01;
1426 ucontrol->value.integer.value[0] =
1427 (snd_soc_read(codec, reg) >> shift) & mask;
1428 if (shift != rshift)
1429 ucontrol->value.integer.value[1] =
1430 (snd_soc_read(codec, reg) >> rshift) & mask;
1432 ucontrol->value.integer.value[0] =
1433 max - ucontrol->value.integer.value[0];
1434 if (shift != rshift)
1435 ucontrol->value.integer.value[1] =
1436 max - ucontrol->value.integer.value[1];
1441 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1444 * snd_soc_put_volsw - single mixer put callback
1445 * @kcontrol: mixer control
1446 * @uinfo: control element information
1448 * Callback to set the value of a single mixer control.
1450 * Returns 0 for success.
1452 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1453 struct snd_ctl_elem_value *ucontrol)
1455 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1456 int reg = kcontrol->private_value & 0xff;
1457 int shift = (kcontrol->private_value >> 8) & 0x0f;
1458 int rshift = (kcontrol->private_value >> 12) & 0x0f;
1459 int max = (kcontrol->private_value >> 16) & 0xff;
1460 int mask = (1 << fls(max)) - 1;
1461 int invert = (kcontrol->private_value >> 24) & 0x01;
1462 unsigned short val, val2, val_mask;
1464 val = (ucontrol->value.integer.value[0] & mask);
1467 val_mask = mask << shift;
1469 if (shift != rshift) {
1470 val2 = (ucontrol->value.integer.value[1] & mask);
1473 val_mask |= mask << rshift;
1474 val |= val2 << rshift;
1476 return snd_soc_update_bits(codec, reg, val_mask, val);
1478 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1481 * snd_soc_info_volsw_2r - double mixer info callback
1482 * @kcontrol: mixer control
1483 * @uinfo: control element information
1485 * Callback to provide information about a double mixer control that
1486 * spans 2 codec registers.
1488 * Returns 0 for success.
1490 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1491 struct snd_ctl_elem_info *uinfo)
1493 int max = (kcontrol->private_value >> 12) & 0xff;
1496 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1498 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1501 uinfo->value.integer.min = 0;
1502 uinfo->value.integer.max = max;
1505 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1508 * snd_soc_get_volsw_2r - double mixer get callback
1509 * @kcontrol: mixer control
1510 * @uinfo: control element information
1512 * Callback to get the value of a double mixer control that spans 2 registers.
1514 * Returns 0 for success.
1516 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1517 struct snd_ctl_elem_value *ucontrol)
1519 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1520 int reg = kcontrol->private_value & 0xff;
1521 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1522 int shift = (kcontrol->private_value >> 8) & 0x0f;
1523 int max = (kcontrol->private_value >> 12) & 0xff;
1524 int mask = (1<<fls(max))-1;
1525 int invert = (kcontrol->private_value >> 20) & 0x01;
1527 ucontrol->value.integer.value[0] =
1528 (snd_soc_read(codec, reg) >> shift) & mask;
1529 ucontrol->value.integer.value[1] =
1530 (snd_soc_read(codec, reg2) >> shift) & mask;
1532 ucontrol->value.integer.value[0] =
1533 max - ucontrol->value.integer.value[0];
1534 ucontrol->value.integer.value[1] =
1535 max - ucontrol->value.integer.value[1];
1540 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1543 * snd_soc_put_volsw_2r - double mixer set callback
1544 * @kcontrol: mixer control
1545 * @uinfo: control element information
1547 * Callback to set the value of a double mixer control that spans 2 registers.
1549 * Returns 0 for success.
1551 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1552 struct snd_ctl_elem_value *ucontrol)
1554 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1555 int reg = kcontrol->private_value & 0xff;
1556 int reg2 = (kcontrol->private_value >> 24) & 0xff;
1557 int shift = (kcontrol->private_value >> 8) & 0x0f;
1558 int max = (kcontrol->private_value >> 12) & 0xff;
1559 int mask = (1 << fls(max)) - 1;
1560 int invert = (kcontrol->private_value >> 20) & 0x01;
1562 unsigned short val, val2, val_mask;
1564 val_mask = mask << shift;
1565 val = (ucontrol->value.integer.value[0] & mask);
1566 val2 = (ucontrol->value.integer.value[1] & mask);
1574 val2 = val2 << shift;
1576 if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
1579 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1582 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1584 static int __devinit snd_soc_init(void)
1586 printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
1587 return platform_driver_register(&soc_driver);
1590 static void snd_soc_exit(void)
1592 platform_driver_unregister(&soc_driver);
1595 module_init(snd_soc_init);
1596 module_exit(snd_soc_exit);
1598 /* Module information */
1599 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1600 MODULE_DESCRIPTION("ALSA SoC Core");
1601 MODULE_LICENSE("GPL");
1602 MODULE_ALIAS("platform:soc-audio");