2 * soc-core.c -- ALSA SoC Audio Layer
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 * with code, comments and ideas from :-
9 * Richard Purdie <richard@openedhand.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 * o Add hw rules to enforce rates, etc.
18 * o More testing with other codecs/machines.
19 * o Add more codecs and platforms to ensure good API coverage.
20 * o Support TDM on PCM and I2S
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
28 #include <linux/bitops.h>
29 #include <linux/debugfs.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>
38 static DEFINE_MUTEX(pcm_mutex);
39 static DEFINE_MUTEX(io_mutex);
40 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
42 #ifdef CONFIG_DEBUG_FS
43 static struct dentry *debugfs_root;
46 static DEFINE_MUTEX(client_mutex);
47 static LIST_HEAD(card_list);
48 static LIST_HEAD(dai_list);
49 static LIST_HEAD(platform_list);
50 static LIST_HEAD(codec_list);
52 static int snd_soc_register_card(struct snd_soc_card *card);
53 static int snd_soc_unregister_card(struct snd_soc_card *card);
56 * This is a timeout to do a DAPM powerdown after a stream is closed().
57 * It can be used to eliminate pops between different playback streams, e.g.
58 * between two audio tracks.
60 static int pmdown_time = 5000;
61 module_param(pmdown_time, int, 0);
62 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
65 * This function forces any delayed work to be queued and run.
67 static int run_delayed_work(struct delayed_work *dwork)
71 /* cancel any work waiting to be queued. */
72 ret = cancel_delayed_work(dwork);
74 /* if there was any work waiting then we run it now and
75 * wait for it's completion */
77 schedule_delayed_work(dwork, 0);
78 flush_scheduled_work();
83 #ifdef CONFIG_SND_SOC_AC97_BUS
84 /* unregister ac97 codec */
85 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
87 if (codec->ac97->dev.bus)
88 device_unregister(&codec->ac97->dev);
92 /* stop no dev release warning */
93 static void soc_ac97_device_release(struct device *dev){}
95 /* register ac97 codec to bus */
96 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
100 codec->ac97->dev.bus = &ac97_bus_type;
101 codec->ac97->dev.parent = codec->card->dev;
102 codec->ac97->dev.release = soc_ac97_device_release;
104 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
105 codec->card->number, 0, codec->name);
106 err = device_register(&codec->ac97->dev);
108 snd_printk(KERN_ERR "Can't register ac97 bus\n");
109 codec->ac97->dev.bus = NULL;
116 static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
118 struct snd_soc_pcm_runtime *rtd = substream->private_data;
119 struct snd_soc_device *socdev = rtd->socdev;
120 struct snd_soc_card *card = socdev->card;
121 struct snd_soc_dai_link *machine = rtd->dai;
122 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
123 struct snd_soc_dai *codec_dai = machine->codec_dai;
126 if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
127 machine->symmetric_rates) {
128 dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
131 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
132 SNDRV_PCM_HW_PARAM_RATE,
137 "Unable to apply rate symmetry constraint: %d\n", ret);
146 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
147 * then initialized and any private data can be allocated. This also calls
148 * startup for the cpu DAI, platform, machine and codec DAI.
150 static int soc_pcm_open(struct snd_pcm_substream *substream)
152 struct snd_soc_pcm_runtime *rtd = substream->private_data;
153 struct snd_soc_device *socdev = rtd->socdev;
154 struct snd_soc_card *card = socdev->card;
155 struct snd_pcm_runtime *runtime = substream->runtime;
156 struct snd_soc_dai_link *machine = rtd->dai;
157 struct snd_soc_platform *platform = card->platform;
158 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
159 struct snd_soc_dai *codec_dai = machine->codec_dai;
162 mutex_lock(&pcm_mutex);
164 /* startup the audio subsystem */
165 if (cpu_dai->ops->startup) {
166 ret = cpu_dai->ops->startup(substream, cpu_dai);
168 printk(KERN_ERR "asoc: can't open interface %s\n",
174 if (platform->pcm_ops->open) {
175 ret = platform->pcm_ops->open(substream);
177 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
182 if (codec_dai->ops->startup) {
183 ret = codec_dai->ops->startup(substream, codec_dai);
185 printk(KERN_ERR "asoc: can't open codec %s\n",
191 if (machine->ops && machine->ops->startup) {
192 ret = machine->ops->startup(substream);
194 printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
199 /* Check that the codec and cpu DAI's are compatible */
200 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
201 runtime->hw.rate_min =
202 max(codec_dai->playback.rate_min,
203 cpu_dai->playback.rate_min);
204 runtime->hw.rate_max =
205 min(codec_dai->playback.rate_max,
206 cpu_dai->playback.rate_max);
207 runtime->hw.channels_min =
208 max(codec_dai->playback.channels_min,
209 cpu_dai->playback.channels_min);
210 runtime->hw.channels_max =
211 min(codec_dai->playback.channels_max,
212 cpu_dai->playback.channels_max);
213 runtime->hw.formats =
214 codec_dai->playback.formats & cpu_dai->playback.formats;
216 codec_dai->playback.rates & cpu_dai->playback.rates;
218 runtime->hw.rate_min =
219 max(codec_dai->capture.rate_min,
220 cpu_dai->capture.rate_min);
221 runtime->hw.rate_max =
222 min(codec_dai->capture.rate_max,
223 cpu_dai->capture.rate_max);
224 runtime->hw.channels_min =
225 max(codec_dai->capture.channels_min,
226 cpu_dai->capture.channels_min);
227 runtime->hw.channels_max =
228 min(codec_dai->capture.channels_max,
229 cpu_dai->capture.channels_max);
230 runtime->hw.formats =
231 codec_dai->capture.formats & cpu_dai->capture.formats;
233 codec_dai->capture.rates & cpu_dai->capture.rates;
236 snd_pcm_limit_hw_rates(runtime);
237 if (!runtime->hw.rates) {
238 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
239 codec_dai->name, cpu_dai->name);
242 if (!runtime->hw.formats) {
243 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
244 codec_dai->name, cpu_dai->name);
247 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
248 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
249 codec_dai->name, cpu_dai->name);
253 /* Symmetry only applies if we've already got an active stream. */
254 if (cpu_dai->active || codec_dai->active) {
255 ret = soc_pcm_apply_symmetry(substream);
260 pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
261 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
262 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
263 runtime->hw.channels_max);
264 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
265 runtime->hw.rate_max);
267 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
268 cpu_dai->playback.active = codec_dai->playback.active = 1;
270 cpu_dai->capture.active = codec_dai->capture.active = 1;
271 cpu_dai->active = codec_dai->active = 1;
272 cpu_dai->runtime = runtime;
273 card->codec->active++;
274 mutex_unlock(&pcm_mutex);
278 if (machine->ops && machine->ops->shutdown)
279 machine->ops->shutdown(substream);
282 if (platform->pcm_ops->close)
283 platform->pcm_ops->close(substream);
286 if (cpu_dai->ops->shutdown)
287 cpu_dai->ops->shutdown(substream, cpu_dai);
289 mutex_unlock(&pcm_mutex);
294 * Power down the audio subsystem pmdown_time msecs after close is called.
295 * This is to ensure there are no pops or clicks in between any music tracks
296 * due to DAPM power cycling.
298 static void close_delayed_work(struct work_struct *work)
300 struct snd_soc_card *card = container_of(work, struct snd_soc_card,
302 struct snd_soc_codec *codec = card->codec;
303 struct snd_soc_dai *codec_dai;
306 mutex_lock(&pcm_mutex);
307 for (i = 0; i < codec->num_dai; i++) {
308 codec_dai = &codec->dai[i];
310 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
311 codec_dai->playback.stream_name,
312 codec_dai->playback.active ? "active" : "inactive",
313 codec_dai->pop_wait ? "yes" : "no");
315 /* are we waiting on this codec DAI stream */
316 if (codec_dai->pop_wait == 1) {
317 codec_dai->pop_wait = 0;
318 snd_soc_dapm_stream_event(codec,
319 codec_dai->playback.stream_name,
320 SND_SOC_DAPM_STREAM_STOP);
323 mutex_unlock(&pcm_mutex);
327 * Called by ALSA when a PCM substream is closed. Private data can be
328 * freed here. The cpu DAI, codec DAI, machine and platform are also
331 static int soc_codec_close(struct snd_pcm_substream *substream)
333 struct snd_soc_pcm_runtime *rtd = substream->private_data;
334 struct snd_soc_device *socdev = rtd->socdev;
335 struct snd_soc_card *card = socdev->card;
336 struct snd_soc_dai_link *machine = rtd->dai;
337 struct snd_soc_platform *platform = card->platform;
338 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
339 struct snd_soc_dai *codec_dai = machine->codec_dai;
340 struct snd_soc_codec *codec = card->codec;
342 mutex_lock(&pcm_mutex);
344 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
345 cpu_dai->playback.active = codec_dai->playback.active = 0;
347 cpu_dai->capture.active = codec_dai->capture.active = 0;
349 if (codec_dai->playback.active == 0 &&
350 codec_dai->capture.active == 0) {
351 cpu_dai->active = codec_dai->active = 0;
355 /* Muting the DAC suppresses artifacts caused during digital
356 * shutdown, for example from stopping clocks.
358 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
359 snd_soc_dai_digital_mute(codec_dai, 1);
361 if (cpu_dai->ops->shutdown)
362 cpu_dai->ops->shutdown(substream, cpu_dai);
364 if (codec_dai->ops->shutdown)
365 codec_dai->ops->shutdown(substream, codec_dai);
367 if (machine->ops && machine->ops->shutdown)
368 machine->ops->shutdown(substream);
370 if (platform->pcm_ops->close)
371 platform->pcm_ops->close(substream);
372 cpu_dai->runtime = NULL;
374 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
375 /* start delayed pop wq here for playback streams */
376 codec_dai->pop_wait = 1;
377 schedule_delayed_work(&card->delayed_work,
378 msecs_to_jiffies(pmdown_time));
380 /* capture streams can be powered down now */
381 snd_soc_dapm_stream_event(codec,
382 codec_dai->capture.stream_name,
383 SND_SOC_DAPM_STREAM_STOP);
386 mutex_unlock(&pcm_mutex);
391 * Called by ALSA when the PCM substream is prepared, can set format, sample
392 * rate, etc. This function is non atomic and can be called multiple times,
393 * it can refer to the runtime info.
395 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
397 struct snd_soc_pcm_runtime *rtd = substream->private_data;
398 struct snd_soc_device *socdev = rtd->socdev;
399 struct snd_soc_card *card = socdev->card;
400 struct snd_soc_dai_link *machine = rtd->dai;
401 struct snd_soc_platform *platform = card->platform;
402 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
403 struct snd_soc_dai *codec_dai = machine->codec_dai;
404 struct snd_soc_codec *codec = card->codec;
407 mutex_lock(&pcm_mutex);
409 if (machine->ops && machine->ops->prepare) {
410 ret = machine->ops->prepare(substream);
412 printk(KERN_ERR "asoc: machine prepare error\n");
417 if (platform->pcm_ops->prepare) {
418 ret = platform->pcm_ops->prepare(substream);
420 printk(KERN_ERR "asoc: platform prepare error\n");
425 if (codec_dai->ops->prepare) {
426 ret = codec_dai->ops->prepare(substream, codec_dai);
428 printk(KERN_ERR "asoc: codec DAI prepare error\n");
433 if (cpu_dai->ops->prepare) {
434 ret = cpu_dai->ops->prepare(substream, cpu_dai);
436 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
441 /* cancel any delayed stream shutdown that is pending */
442 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
443 codec_dai->pop_wait) {
444 codec_dai->pop_wait = 0;
445 cancel_delayed_work(&card->delayed_work);
448 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
449 snd_soc_dapm_stream_event(codec,
450 codec_dai->playback.stream_name,
451 SND_SOC_DAPM_STREAM_START);
453 snd_soc_dapm_stream_event(codec,
454 codec_dai->capture.stream_name,
455 SND_SOC_DAPM_STREAM_START);
457 snd_soc_dai_digital_mute(codec_dai, 0);
460 mutex_unlock(&pcm_mutex);
465 * Called by ALSA when the hardware params are set by application. This
466 * function can also be called multiple times and can allocate buffers
467 * (using snd_pcm_lib_* ). It's non-atomic.
469 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
470 struct snd_pcm_hw_params *params)
472 struct snd_soc_pcm_runtime *rtd = substream->private_data;
473 struct snd_soc_device *socdev = rtd->socdev;
474 struct snd_soc_dai_link *machine = rtd->dai;
475 struct snd_soc_card *card = socdev->card;
476 struct snd_soc_platform *platform = card->platform;
477 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
478 struct snd_soc_dai *codec_dai = machine->codec_dai;
481 mutex_lock(&pcm_mutex);
483 if (machine->ops && machine->ops->hw_params) {
484 ret = machine->ops->hw_params(substream, params);
486 printk(KERN_ERR "asoc: machine hw_params failed\n");
491 if (codec_dai->ops->hw_params) {
492 ret = codec_dai->ops->hw_params(substream, params, codec_dai);
494 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
500 if (cpu_dai->ops->hw_params) {
501 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
503 printk(KERN_ERR "asoc: interface %s hw params failed\n",
509 if (platform->pcm_ops->hw_params) {
510 ret = platform->pcm_ops->hw_params(substream, params);
512 printk(KERN_ERR "asoc: platform %s hw params failed\n",
518 machine->rate = params_rate(params);
521 mutex_unlock(&pcm_mutex);
525 if (cpu_dai->ops->hw_free)
526 cpu_dai->ops->hw_free(substream, cpu_dai);
529 if (codec_dai->ops->hw_free)
530 codec_dai->ops->hw_free(substream, codec_dai);
533 if (machine->ops && machine->ops->hw_free)
534 machine->ops->hw_free(substream);
536 mutex_unlock(&pcm_mutex);
541 * Free's resources allocated by hw_params, can be called multiple times
543 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
545 struct snd_soc_pcm_runtime *rtd = substream->private_data;
546 struct snd_soc_device *socdev = rtd->socdev;
547 struct snd_soc_dai_link *machine = rtd->dai;
548 struct snd_soc_card *card = socdev->card;
549 struct snd_soc_platform *platform = card->platform;
550 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
551 struct snd_soc_dai *codec_dai = machine->codec_dai;
552 struct snd_soc_codec *codec = card->codec;
554 mutex_lock(&pcm_mutex);
556 /* apply codec digital mute */
558 snd_soc_dai_digital_mute(codec_dai, 1);
560 /* free any machine hw params */
561 if (machine->ops && machine->ops->hw_free)
562 machine->ops->hw_free(substream);
564 /* free any DMA resources */
565 if (platform->pcm_ops->hw_free)
566 platform->pcm_ops->hw_free(substream);
568 /* now free hw params for the DAI's */
569 if (codec_dai->ops->hw_free)
570 codec_dai->ops->hw_free(substream, codec_dai);
572 if (cpu_dai->ops->hw_free)
573 cpu_dai->ops->hw_free(substream, cpu_dai);
575 mutex_unlock(&pcm_mutex);
579 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
581 struct snd_soc_pcm_runtime *rtd = substream->private_data;
582 struct snd_soc_device *socdev = rtd->socdev;
583 struct snd_soc_card *card= socdev->card;
584 struct snd_soc_dai_link *machine = rtd->dai;
585 struct snd_soc_platform *platform = card->platform;
586 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
587 struct snd_soc_dai *codec_dai = machine->codec_dai;
590 if (codec_dai->ops->trigger) {
591 ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
596 if (platform->pcm_ops->trigger) {
597 ret = platform->pcm_ops->trigger(substream, cmd);
602 if (cpu_dai->ops->trigger) {
603 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
610 /* ASoC PCM operations */
611 static struct snd_pcm_ops soc_pcm_ops = {
612 .open = soc_pcm_open,
613 .close = soc_codec_close,
614 .hw_params = soc_pcm_hw_params,
615 .hw_free = soc_pcm_hw_free,
616 .prepare = soc_pcm_prepare,
617 .trigger = soc_pcm_trigger,
621 /* powers down audio subsystem for suspend */
622 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
624 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
625 struct snd_soc_card *card = socdev->card;
626 struct snd_soc_platform *platform = card->platform;
627 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
628 struct snd_soc_codec *codec = card->codec;
631 /* Due to the resume being scheduled into a workqueue we could
632 * suspend before that's finished - wait for it to complete.
634 snd_power_lock(codec->card);
635 snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
636 snd_power_unlock(codec->card);
638 /* we're going to block userspace touching us until resume completes */
639 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
641 /* mute any active DAC's */
642 for (i = 0; i < card->num_links; i++) {
643 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
644 if (dai->ops->digital_mute && dai->playback.active)
645 dai->ops->digital_mute(dai, 1);
648 /* suspend all pcms */
649 for (i = 0; i < card->num_links; i++)
650 snd_pcm_suspend_all(card->dai_link[i].pcm);
652 if (card->suspend_pre)
653 card->suspend_pre(pdev, state);
655 for (i = 0; i < card->num_links; i++) {
656 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
657 if (cpu_dai->suspend && !cpu_dai->ac97_control)
658 cpu_dai->suspend(cpu_dai);
659 if (platform->suspend)
660 platform->suspend(cpu_dai);
663 /* close any waiting streams and save state */
664 run_delayed_work(&card->delayed_work);
665 codec->suspend_bias_level = codec->bias_level;
667 for (i = 0; i < codec->num_dai; i++) {
668 char *stream = codec->dai[i].playback.stream_name;
670 snd_soc_dapm_stream_event(codec, stream,
671 SND_SOC_DAPM_STREAM_SUSPEND);
672 stream = codec->dai[i].capture.stream_name;
674 snd_soc_dapm_stream_event(codec, stream,
675 SND_SOC_DAPM_STREAM_SUSPEND);
678 if (codec_dev->suspend)
679 codec_dev->suspend(pdev, state);
681 for (i = 0; i < card->num_links; i++) {
682 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
683 if (cpu_dai->suspend && cpu_dai->ac97_control)
684 cpu_dai->suspend(cpu_dai);
687 if (card->suspend_post)
688 card->suspend_post(pdev, state);
693 /* deferred resume work, so resume can complete before we finished
694 * setting our codec back up, which can be very slow on I2C
696 static void soc_resume_deferred(struct work_struct *work)
698 struct snd_soc_card *card = container_of(work,
700 deferred_resume_work);
701 struct snd_soc_device *socdev = card->socdev;
702 struct snd_soc_platform *platform = card->platform;
703 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
704 struct snd_soc_codec *codec = card->codec;
705 struct platform_device *pdev = to_platform_device(socdev->dev);
708 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
709 * so userspace apps are blocked from touching us
712 dev_dbg(socdev->dev, "starting resume work\n");
714 if (card->resume_pre)
715 card->resume_pre(pdev);
717 for (i = 0; i < card->num_links; i++) {
718 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
719 if (cpu_dai->resume && cpu_dai->ac97_control)
720 cpu_dai->resume(cpu_dai);
723 if (codec_dev->resume)
724 codec_dev->resume(pdev);
726 for (i = 0; i < codec->num_dai; i++) {
727 char *stream = codec->dai[i].playback.stream_name;
729 snd_soc_dapm_stream_event(codec, stream,
730 SND_SOC_DAPM_STREAM_RESUME);
731 stream = codec->dai[i].capture.stream_name;
733 snd_soc_dapm_stream_event(codec, stream,
734 SND_SOC_DAPM_STREAM_RESUME);
737 /* unmute any active DACs */
738 for (i = 0; i < card->num_links; i++) {
739 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
740 if (dai->ops->digital_mute && dai->playback.active)
741 dai->ops->digital_mute(dai, 0);
744 for (i = 0; i < card->num_links; i++) {
745 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
746 if (cpu_dai->resume && !cpu_dai->ac97_control)
747 cpu_dai->resume(cpu_dai);
748 if (platform->resume)
749 platform->resume(cpu_dai);
752 if (card->resume_post)
753 card->resume_post(pdev);
755 dev_dbg(socdev->dev, "resume work completed\n");
757 /* userspace can access us now we are back as we were before */
758 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
761 /* powers up audio subsystem after a suspend */
762 static int soc_resume(struct platform_device *pdev)
764 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
765 struct snd_soc_card *card = socdev->card;
766 struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
768 /* AC97 devices might have other drivers hanging off them so
769 * need to resume immediately. Other drivers don't have that
770 * problem and may take a substantial amount of time to resume
771 * due to I/O costs and anti-pop so handle them out of line.
773 if (cpu_dai->ac97_control) {
774 dev_dbg(socdev->dev, "Resuming AC97 immediately\n");
775 soc_resume_deferred(&card->deferred_resume_work);
777 dev_dbg(socdev->dev, "Scheduling resume work\n");
778 if (!schedule_work(&card->deferred_resume_work))
779 dev_err(socdev->dev, "resume work item may be lost\n");
786 #define soc_suspend NULL
787 #define soc_resume NULL
790 static void snd_soc_instantiate_card(struct snd_soc_card *card)
792 struct platform_device *pdev = container_of(card->dev,
793 struct platform_device,
795 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
796 struct snd_soc_platform *platform;
797 struct snd_soc_dai *dai;
798 int i, found, ret, ac97;
800 if (card->instantiated)
804 list_for_each_entry(platform, &platform_list, list)
805 if (card->platform == platform) {
810 dev_dbg(card->dev, "Platform %s not registered\n",
811 card->platform->name);
816 for (i = 0; i < card->num_links; i++) {
818 list_for_each_entry(dai, &dai_list, list)
819 if (card->dai_link[i].cpu_dai == dai) {
824 dev_dbg(card->dev, "DAI %s not registered\n",
825 card->dai_link[i].cpu_dai->name);
829 if (card->dai_link[i].cpu_dai->ac97_control)
833 /* If we have AC97 in the system then don't wait for the
834 * codec. This will need revisiting if we have to handle
835 * systems with mixed AC97 and non-AC97 parts. Only check for
836 * DAIs currently; we can't do this per link since some AC97
837 * codecs have non-AC97 DAIs.
840 for (i = 0; i < card->num_links; i++) {
842 list_for_each_entry(dai, &dai_list, list)
843 if (card->dai_link[i].codec_dai == dai) {
848 dev_dbg(card->dev, "DAI %s not registered\n",
849 card->dai_link[i].codec_dai->name);
854 /* Note that we do not current check for codec components */
856 dev_dbg(card->dev, "All components present, instantiating\n");
858 /* Found everything, bring it up */
860 ret = card->probe(pdev);
865 for (i = 0; i < card->num_links; i++) {
866 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
867 if (cpu_dai->probe) {
868 ret = cpu_dai->probe(pdev, cpu_dai);
874 if (codec_dev->probe) {
875 ret = codec_dev->probe(pdev);
880 if (platform->probe) {
881 ret = platform->probe(pdev);
886 /* DAPM stream work */
887 INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
889 /* deferred resume work */
890 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
893 card->instantiated = 1;
898 if (codec_dev->remove)
899 codec_dev->remove(pdev);
902 for (i--; i >= 0; i--) {
903 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
905 cpu_dai->remove(pdev, cpu_dai);
913 * Attempt to initialise any uninitalised cards. Must be called with
916 static void snd_soc_instantiate_cards(void)
918 struct snd_soc_card *card;
919 list_for_each_entry(card, &card_list, list)
920 snd_soc_instantiate_card(card);
923 /* probes a new socdev */
924 static int soc_probe(struct platform_device *pdev)
927 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
928 struct snd_soc_card *card = socdev->card;
930 /* Bodge while we push things out of socdev */
931 card->socdev = socdev;
933 /* Bodge while we unpick instantiation */
934 card->dev = &pdev->dev;
935 ret = snd_soc_register_card(card);
937 dev_err(&pdev->dev, "Failed to register card\n");
944 /* removes a socdev */
945 static int soc_remove(struct platform_device *pdev)
948 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
949 struct snd_soc_card *card = socdev->card;
950 struct snd_soc_platform *platform = card->platform;
951 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
953 if (!card->instantiated)
956 run_delayed_work(&card->delayed_work);
958 if (platform->remove)
959 platform->remove(pdev);
961 if (codec_dev->remove)
962 codec_dev->remove(pdev);
964 for (i = 0; i < card->num_links; i++) {
965 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
967 cpu_dai->remove(pdev, cpu_dai);
973 snd_soc_unregister_card(card);
978 /* ASoC platform driver */
979 static struct platform_driver soc_driver = {
982 .owner = THIS_MODULE,
985 .remove = soc_remove,
986 .suspend = soc_suspend,
987 .resume = soc_resume,
990 /* create a new pcm */
991 static int soc_new_pcm(struct snd_soc_device *socdev,
992 struct snd_soc_dai_link *dai_link, int num)
994 struct snd_soc_card *card = socdev->card;
995 struct snd_soc_codec *codec = card->codec;
996 struct snd_soc_platform *platform = card->platform;
997 struct snd_soc_dai *codec_dai = dai_link->codec_dai;
998 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
999 struct snd_soc_pcm_runtime *rtd;
1000 struct snd_pcm *pcm;
1002 int ret = 0, playback = 0, capture = 0;
1004 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
1008 rtd->dai = dai_link;
1009 rtd->socdev = socdev;
1010 codec_dai->codec = card->codec;
1012 /* check client and interface hw capabilities */
1013 sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name,
1016 if (codec_dai->playback.channels_min)
1018 if (codec_dai->capture.channels_min)
1021 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
1024 printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
1030 dai_link->pcm = pcm;
1031 pcm->private_data = rtd;
1032 soc_pcm_ops.mmap = platform->pcm_ops->mmap;
1033 soc_pcm_ops.pointer = platform->pcm_ops->pointer;
1034 soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
1035 soc_pcm_ops.copy = platform->pcm_ops->copy;
1036 soc_pcm_ops.silence = platform->pcm_ops->silence;
1037 soc_pcm_ops.ack = platform->pcm_ops->ack;
1038 soc_pcm_ops.page = platform->pcm_ops->page;
1041 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
1044 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
1046 ret = platform->pcm_new(codec->card, codec_dai, pcm);
1048 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
1053 pcm->private_free = platform->pcm_free;
1054 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
1059 /* codec register dump */
1060 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
1062 int i, step = 1, count = 0;
1064 if (!codec->reg_cache_size)
1067 if (codec->reg_cache_step)
1068 step = codec->reg_cache_step;
1070 count += sprintf(buf, "%s registers\n", codec->name);
1071 for (i = 0; i < codec->reg_cache_size; i += step) {
1072 count += sprintf(buf + count, "%2x: ", i);
1073 if (count >= PAGE_SIZE - 1)
1076 if (codec->display_register)
1077 count += codec->display_register(codec, buf + count,
1078 PAGE_SIZE - count, i);
1080 count += snprintf(buf + count, PAGE_SIZE - count,
1081 "%4x", codec->read(codec, i));
1083 if (count >= PAGE_SIZE - 1)
1086 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
1087 if (count >= PAGE_SIZE - 1)
1091 /* Truncate count; min() would cause a warning */
1092 if (count >= PAGE_SIZE)
1093 count = PAGE_SIZE - 1;
1097 static ssize_t codec_reg_show(struct device *dev,
1098 struct device_attribute *attr, char *buf)
1100 struct snd_soc_device *devdata = dev_get_drvdata(dev);
1101 return soc_codec_reg_show(devdata->card->codec, buf);
1104 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
1106 #ifdef CONFIG_DEBUG_FS
1107 static int codec_reg_open_file(struct inode *inode, struct file *file)
1109 file->private_data = inode->i_private;
1113 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
1114 size_t count, loff_t *ppos)
1117 struct snd_soc_codec *codec = file->private_data;
1118 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1121 ret = soc_codec_reg_show(codec, buf);
1123 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1128 static ssize_t codec_reg_write_file(struct file *file,
1129 const char __user *user_buf, size_t count, loff_t *ppos)
1134 unsigned long reg, value;
1136 struct snd_soc_codec *codec = file->private_data;
1138 buf_size = min(count, (sizeof(buf)-1));
1139 if (copy_from_user(buf, user_buf, buf_size))
1143 if (codec->reg_cache_step)
1144 step = codec->reg_cache_step;
1146 while (*start == ' ')
1148 reg = simple_strtoul(start, &start, 16);
1149 if ((reg >= codec->reg_cache_size) || (reg % step))
1151 while (*start == ' ')
1153 if (strict_strtoul(start, 16, &value))
1155 codec->write(codec, reg, value);
1159 static const struct file_operations codec_reg_fops = {
1160 .open = codec_reg_open_file,
1161 .read = codec_reg_read_file,
1162 .write = codec_reg_write_file,
1165 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
1167 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
1168 debugfs_root, codec,
1170 if (!codec->debugfs_reg)
1172 "ASoC: Failed to create codec register debugfs file\n");
1174 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
1177 if (!codec->debugfs_pop_time)
1179 "Failed to create pop time debugfs file\n");
1182 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
1184 debugfs_remove(codec->debugfs_pop_time);
1185 debugfs_remove(codec->debugfs_reg);
1190 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
1194 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
1200 * snd_soc_new_ac97_codec - initailise AC97 device
1201 * @codec: audio codec
1202 * @ops: AC97 bus operations
1203 * @num: AC97 codec number
1205 * Initialises AC97 codec resources for use by ad-hoc devices only.
1207 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1208 struct snd_ac97_bus_ops *ops, int num)
1210 mutex_lock(&codec->mutex);
1212 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1213 if (codec->ac97 == NULL) {
1214 mutex_unlock(&codec->mutex);
1218 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1219 if (codec->ac97->bus == NULL) {
1222 mutex_unlock(&codec->mutex);
1226 codec->ac97->bus->ops = ops;
1227 codec->ac97->num = num;
1228 mutex_unlock(&codec->mutex);
1231 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1234 * snd_soc_free_ac97_codec - free AC97 codec device
1235 * @codec: audio codec
1237 * Frees AC97 codec device resources.
1239 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1241 mutex_lock(&codec->mutex);
1242 kfree(codec->ac97->bus);
1245 mutex_unlock(&codec->mutex);
1247 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1250 * snd_soc_update_bits - update codec register bits
1251 * @codec: audio codec
1252 * @reg: codec register
1253 * @mask: register mask
1256 * Writes new register value.
1258 * Returns 1 for change else 0.
1260 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1261 unsigned short mask, unsigned short value)
1264 unsigned short old, new;
1266 mutex_lock(&io_mutex);
1267 old = snd_soc_read(codec, reg);
1268 new = (old & ~mask) | value;
1269 change = old != new;
1271 snd_soc_write(codec, reg, new);
1273 mutex_unlock(&io_mutex);
1276 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1279 * snd_soc_test_bits - test register for change
1280 * @codec: audio codec
1281 * @reg: codec register
1282 * @mask: register mask
1285 * Tests a register with a new value and checks if the new value is
1286 * different from the old value.
1288 * Returns 1 for change else 0.
1290 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1291 unsigned short mask, unsigned short value)
1294 unsigned short old, new;
1296 mutex_lock(&io_mutex);
1297 old = snd_soc_read(codec, reg);
1298 new = (old & ~mask) | value;
1299 change = old != new;
1300 mutex_unlock(&io_mutex);
1304 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1307 * snd_soc_new_pcms - create new sound card and pcms
1308 * @socdev: the SoC audio device
1309 * @idx: ALSA card index
1310 * @xid: card identification
1312 * Create a new sound card based upon the codec and interface pcms.
1314 * Returns 0 for success, else error.
1316 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1318 struct snd_soc_card *card = socdev->card;
1319 struct snd_soc_codec *codec = card->codec;
1322 mutex_lock(&codec->mutex);
1324 /* register a sound card */
1325 ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
1327 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1329 mutex_unlock(&codec->mutex);
1333 codec->socdev = socdev;
1334 codec->card->dev = socdev->dev;
1335 codec->card->private_data = codec;
1336 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1338 /* create the pcms */
1339 for (i = 0; i < card->num_links; i++) {
1340 ret = soc_new_pcm(socdev, &card->dai_link[i], i);
1342 printk(KERN_ERR "asoc: can't create pcm %s\n",
1343 card->dai_link[i].stream_name);
1344 mutex_unlock(&codec->mutex);
1349 mutex_unlock(&codec->mutex);
1352 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1355 * snd_soc_init_card - register sound card
1356 * @socdev: the SoC audio device
1358 * Register a SoC sound card. Also registers an AC97 device if the
1359 * codec is AC97 for ad hoc devices.
1361 * Returns 0 for success, else error.
1363 int snd_soc_init_card(struct snd_soc_device *socdev)
1365 struct snd_soc_card *card = socdev->card;
1366 struct snd_soc_codec *codec = card->codec;
1367 int ret = 0, i, ac97 = 0, err = 0;
1369 for (i = 0; i < card->num_links; i++) {
1370 if (card->dai_link[i].init) {
1371 err = card->dai_link[i].init(codec);
1373 printk(KERN_ERR "asoc: failed to init %s\n",
1374 card->dai_link[i].stream_name);
1378 if (card->dai_link[i].codec_dai->ac97_control)
1381 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1383 snprintf(codec->card->longname, sizeof(codec->card->longname),
1384 "%s (%s)", card->name, codec->name);
1386 ret = snd_card_register(codec->card);
1388 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1393 mutex_lock(&codec->mutex);
1394 #ifdef CONFIG_SND_SOC_AC97_BUS
1395 /* Only instantiate AC97 if not already done by the adaptor
1396 * for the generic AC97 subsystem.
1398 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1399 ret = soc_ac97_dev_register(codec);
1401 printk(KERN_ERR "asoc: AC97 device register failed\n");
1402 snd_card_free(codec->card);
1403 mutex_unlock(&codec->mutex);
1409 err = snd_soc_dapm_sys_add(socdev->dev);
1411 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1413 err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1415 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1417 soc_init_codec_debugfs(codec);
1418 mutex_unlock(&codec->mutex);
1423 EXPORT_SYMBOL_GPL(snd_soc_init_card);
1426 * snd_soc_free_pcms - free sound card and pcms
1427 * @socdev: the SoC audio device
1429 * Frees sound card and pcms associated with the socdev.
1430 * Also unregister the codec if it is an AC97 device.
1432 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1434 struct snd_soc_codec *codec = socdev->card->codec;
1435 #ifdef CONFIG_SND_SOC_AC97_BUS
1436 struct snd_soc_dai *codec_dai;
1440 mutex_lock(&codec->mutex);
1441 soc_cleanup_codec_debugfs(codec);
1442 #ifdef CONFIG_SND_SOC_AC97_BUS
1443 for (i = 0; i < codec->num_dai; i++) {
1444 codec_dai = &codec->dai[i];
1445 if (codec_dai->ac97_control && codec->ac97 &&
1446 strcmp(codec->name, "AC97") != 0) {
1447 soc_ac97_dev_unregister(codec);
1455 snd_card_free(codec->card);
1456 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1457 mutex_unlock(&codec->mutex);
1459 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1462 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1463 * @substream: the pcm substream
1464 * @hw: the hardware parameters
1466 * Sets the substream runtime hardware parameters.
1468 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1469 const struct snd_pcm_hardware *hw)
1471 struct snd_pcm_runtime *runtime = substream->runtime;
1472 runtime->hw.info = hw->info;
1473 runtime->hw.formats = hw->formats;
1474 runtime->hw.period_bytes_min = hw->period_bytes_min;
1475 runtime->hw.period_bytes_max = hw->period_bytes_max;
1476 runtime->hw.periods_min = hw->periods_min;
1477 runtime->hw.periods_max = hw->periods_max;
1478 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1479 runtime->hw.fifo_size = hw->fifo_size;
1482 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1485 * snd_soc_cnew - create new control
1486 * @_template: control template
1487 * @data: control private data
1488 * @long_name: control long name
1490 * Create a new mixer control from a template control.
1492 * Returns 0 for success, else error.
1494 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1495 void *data, char *long_name)
1497 struct snd_kcontrol_new template;
1499 memcpy(&template, _template, sizeof(template));
1501 template.name = long_name;
1504 return snd_ctl_new1(&template, data);
1506 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1509 * snd_soc_add_controls - add an array of controls to a codec.
1510 * Convienience function to add a list of controls. Many codecs were
1511 * duplicating this code.
1513 * @codec: codec to add controls to
1514 * @controls: array of controls to add
1515 * @num_controls: number of elements in the array
1517 * Return 0 for success, else error.
1519 int snd_soc_add_controls(struct snd_soc_codec *codec,
1520 const struct snd_kcontrol_new *controls, int num_controls)
1522 struct snd_card *card = codec->card;
1525 for (i = 0; i < num_controls; i++) {
1526 const struct snd_kcontrol_new *control = &controls[i];
1527 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
1529 dev_err(codec->dev, "%s: Failed to add %s\n",
1530 codec->name, control->name);
1537 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
1540 * snd_soc_info_enum_double - enumerated double mixer info callback
1541 * @kcontrol: mixer control
1542 * @uinfo: control element information
1544 * Callback to provide information about a double enumerated
1547 * Returns 0 for success.
1549 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_info *uinfo)
1552 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1554 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1555 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1556 uinfo->value.enumerated.items = e->max;
1558 if (uinfo->value.enumerated.item > e->max - 1)
1559 uinfo->value.enumerated.item = e->max - 1;
1560 strcpy(uinfo->value.enumerated.name,
1561 e->texts[uinfo->value.enumerated.item]);
1564 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1567 * snd_soc_get_enum_double - enumerated double mixer get callback
1568 * @kcontrol: mixer control
1569 * @ucontrol: control element information
1571 * Callback to get the value of a double enumerated mixer.
1573 * Returns 0 for success.
1575 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1576 struct snd_ctl_elem_value *ucontrol)
1578 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1579 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1580 unsigned short val, bitmask;
1582 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1584 val = snd_soc_read(codec, e->reg);
1585 ucontrol->value.enumerated.item[0]
1586 = (val >> e->shift_l) & (bitmask - 1);
1587 if (e->shift_l != e->shift_r)
1588 ucontrol->value.enumerated.item[1] =
1589 (val >> e->shift_r) & (bitmask - 1);
1593 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1596 * snd_soc_put_enum_double - enumerated double mixer put callback
1597 * @kcontrol: mixer control
1598 * @ucontrol: control element information
1600 * Callback to set the value of a double enumerated mixer.
1602 * Returns 0 for success.
1604 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1605 struct snd_ctl_elem_value *ucontrol)
1607 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1608 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1610 unsigned short mask, bitmask;
1612 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1614 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1616 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1617 mask = (bitmask - 1) << e->shift_l;
1618 if (e->shift_l != e->shift_r) {
1619 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1621 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1622 mask |= (bitmask - 1) << e->shift_r;
1625 return snd_soc_update_bits(codec, e->reg, mask, val);
1627 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1630 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
1631 * @kcontrol: mixer control
1632 * @ucontrol: control element information
1634 * Callback to get the value of a double semi enumerated mixer.
1636 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1637 * used for handling bitfield coded enumeration for example.
1639 * Returns 0 for success.
1641 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
1642 struct snd_ctl_elem_value *ucontrol)
1644 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1645 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1646 unsigned short reg_val, val, mux;
1648 reg_val = snd_soc_read(codec, e->reg);
1649 val = (reg_val >> e->shift_l) & e->mask;
1650 for (mux = 0; mux < e->max; mux++) {
1651 if (val == e->values[mux])
1654 ucontrol->value.enumerated.item[0] = mux;
1655 if (e->shift_l != e->shift_r) {
1656 val = (reg_val >> e->shift_r) & e->mask;
1657 for (mux = 0; mux < e->max; mux++) {
1658 if (val == e->values[mux])
1661 ucontrol->value.enumerated.item[1] = mux;
1666 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
1669 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
1670 * @kcontrol: mixer control
1671 * @ucontrol: control element information
1673 * Callback to set the value of a double semi enumerated mixer.
1675 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1676 * used for handling bitfield coded enumeration for example.
1678 * Returns 0 for success.
1680 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
1681 struct snd_ctl_elem_value *ucontrol)
1683 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1684 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1686 unsigned short mask;
1688 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1690 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1691 mask = e->mask << e->shift_l;
1692 if (e->shift_l != e->shift_r) {
1693 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1695 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1696 mask |= e->mask << e->shift_r;
1699 return snd_soc_update_bits(codec, e->reg, mask, val);
1701 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
1704 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1705 * @kcontrol: mixer control
1706 * @uinfo: control element information
1708 * Callback to provide information about an external enumerated
1711 * Returns 0 for success.
1713 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_info *uinfo)
1716 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1718 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1720 uinfo->value.enumerated.items = e->max;
1722 if (uinfo->value.enumerated.item > e->max - 1)
1723 uinfo->value.enumerated.item = e->max - 1;
1724 strcpy(uinfo->value.enumerated.name,
1725 e->texts[uinfo->value.enumerated.item]);
1728 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1731 * snd_soc_info_volsw_ext - external single mixer info callback
1732 * @kcontrol: mixer control
1733 * @uinfo: control element information
1735 * Callback to provide information about a single external mixer control.
1737 * Returns 0 for success.
1739 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_info *uinfo)
1742 int max = kcontrol->private_value;
1744 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
1745 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1747 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1750 uinfo->value.integer.min = 0;
1751 uinfo->value.integer.max = max;
1754 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1757 * snd_soc_info_volsw - single mixer info callback
1758 * @kcontrol: mixer control
1759 * @uinfo: control element information
1761 * Callback to provide information about a single mixer control.
1763 * Returns 0 for success.
1765 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_info *uinfo)
1768 struct soc_mixer_control *mc =
1769 (struct soc_mixer_control *)kcontrol->private_value;
1771 unsigned int shift = mc->shift;
1772 unsigned int rshift = mc->rshift;
1774 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
1775 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1777 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1779 uinfo->count = shift == rshift ? 1 : 2;
1780 uinfo->value.integer.min = 0;
1781 uinfo->value.integer.max = max;
1784 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1787 * snd_soc_get_volsw - single mixer get callback
1788 * @kcontrol: mixer control
1789 * @ucontrol: control element information
1791 * Callback to get the value of a single mixer control.
1793 * Returns 0 for success.
1795 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1796 struct snd_ctl_elem_value *ucontrol)
1798 struct soc_mixer_control *mc =
1799 (struct soc_mixer_control *)kcontrol->private_value;
1800 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1801 unsigned int reg = mc->reg;
1802 unsigned int shift = mc->shift;
1803 unsigned int rshift = mc->rshift;
1805 unsigned int mask = (1 << fls(max)) - 1;
1806 unsigned int invert = mc->invert;
1808 ucontrol->value.integer.value[0] =
1809 (snd_soc_read(codec, reg) >> shift) & mask;
1810 if (shift != rshift)
1811 ucontrol->value.integer.value[1] =
1812 (snd_soc_read(codec, reg) >> rshift) & mask;
1814 ucontrol->value.integer.value[0] =
1815 max - ucontrol->value.integer.value[0];
1816 if (shift != rshift)
1817 ucontrol->value.integer.value[1] =
1818 max - ucontrol->value.integer.value[1];
1823 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1826 * snd_soc_put_volsw - single mixer put callback
1827 * @kcontrol: mixer control
1828 * @ucontrol: control element information
1830 * Callback to set the value of a single mixer control.
1832 * Returns 0 for success.
1834 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1835 struct snd_ctl_elem_value *ucontrol)
1837 struct soc_mixer_control *mc =
1838 (struct soc_mixer_control *)kcontrol->private_value;
1839 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1840 unsigned int reg = mc->reg;
1841 unsigned int shift = mc->shift;
1842 unsigned int rshift = mc->rshift;
1844 unsigned int mask = (1 << fls(max)) - 1;
1845 unsigned int invert = mc->invert;
1846 unsigned short val, val2, val_mask;
1848 val = (ucontrol->value.integer.value[0] & mask);
1851 val_mask = mask << shift;
1853 if (shift != rshift) {
1854 val2 = (ucontrol->value.integer.value[1] & mask);
1857 val_mask |= mask << rshift;
1858 val |= val2 << rshift;
1860 return snd_soc_update_bits(codec, reg, val_mask, val);
1862 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1865 * snd_soc_info_volsw_2r - double mixer info callback
1866 * @kcontrol: mixer control
1867 * @uinfo: control element information
1869 * Callback to provide information about a double mixer control that
1870 * spans 2 codec registers.
1872 * Returns 0 for success.
1874 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1875 struct snd_ctl_elem_info *uinfo)
1877 struct soc_mixer_control *mc =
1878 (struct soc_mixer_control *)kcontrol->private_value;
1881 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
1882 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1884 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1887 uinfo->value.integer.min = 0;
1888 uinfo->value.integer.max = max;
1891 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1894 * snd_soc_get_volsw_2r - double mixer get callback
1895 * @kcontrol: mixer control
1896 * @ucontrol: control element information
1898 * Callback to get the value of a double mixer control that spans 2 registers.
1900 * Returns 0 for success.
1902 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1903 struct snd_ctl_elem_value *ucontrol)
1905 struct soc_mixer_control *mc =
1906 (struct soc_mixer_control *)kcontrol->private_value;
1907 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1908 unsigned int reg = mc->reg;
1909 unsigned int reg2 = mc->rreg;
1910 unsigned int shift = mc->shift;
1912 unsigned int mask = (1<<fls(max))-1;
1913 unsigned int invert = mc->invert;
1915 ucontrol->value.integer.value[0] =
1916 (snd_soc_read(codec, reg) >> shift) & mask;
1917 ucontrol->value.integer.value[1] =
1918 (snd_soc_read(codec, reg2) >> shift) & mask;
1920 ucontrol->value.integer.value[0] =
1921 max - ucontrol->value.integer.value[0];
1922 ucontrol->value.integer.value[1] =
1923 max - ucontrol->value.integer.value[1];
1928 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1931 * snd_soc_put_volsw_2r - double mixer set callback
1932 * @kcontrol: mixer control
1933 * @ucontrol: control element information
1935 * Callback to set the value of a double mixer control that spans 2 registers.
1937 * Returns 0 for success.
1939 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1940 struct snd_ctl_elem_value *ucontrol)
1942 struct soc_mixer_control *mc =
1943 (struct soc_mixer_control *)kcontrol->private_value;
1944 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1945 unsigned int reg = mc->reg;
1946 unsigned int reg2 = mc->rreg;
1947 unsigned int shift = mc->shift;
1949 unsigned int mask = (1 << fls(max)) - 1;
1950 unsigned int invert = mc->invert;
1952 unsigned short val, val2, val_mask;
1954 val_mask = mask << shift;
1955 val = (ucontrol->value.integer.value[0] & mask);
1956 val2 = (ucontrol->value.integer.value[1] & mask);
1964 val2 = val2 << shift;
1966 err = snd_soc_update_bits(codec, reg, val_mask, val);
1970 err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1973 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1976 * snd_soc_info_volsw_s8 - signed mixer info callback
1977 * @kcontrol: mixer control
1978 * @uinfo: control element information
1980 * Callback to provide information about a signed mixer control.
1982 * Returns 0 for success.
1984 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
1985 struct snd_ctl_elem_info *uinfo)
1987 struct soc_mixer_control *mc =
1988 (struct soc_mixer_control *)kcontrol->private_value;
1992 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1994 uinfo->value.integer.min = 0;
1995 uinfo->value.integer.max = max-min;
1998 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2001 * snd_soc_get_volsw_s8 - signed mixer get callback
2002 * @kcontrol: mixer control
2003 * @ucontrol: control element information
2005 * Callback to get the value of a signed mixer control.
2007 * Returns 0 for success.
2009 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2010 struct snd_ctl_elem_value *ucontrol)
2012 struct soc_mixer_control *mc =
2013 (struct soc_mixer_control *)kcontrol->private_value;
2014 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2015 unsigned int reg = mc->reg;
2017 int val = snd_soc_read(codec, reg);
2019 ucontrol->value.integer.value[0] =
2020 ((signed char)(val & 0xff))-min;
2021 ucontrol->value.integer.value[1] =
2022 ((signed char)((val >> 8) & 0xff))-min;
2025 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2028 * snd_soc_put_volsw_sgn - signed mixer put callback
2029 * @kcontrol: mixer control
2030 * @ucontrol: control element information
2032 * Callback to set the value of a signed mixer control.
2034 * Returns 0 for success.
2036 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2037 struct snd_ctl_elem_value *ucontrol)
2039 struct soc_mixer_control *mc =
2040 (struct soc_mixer_control *)kcontrol->private_value;
2041 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2042 unsigned int reg = mc->reg;
2046 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2047 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2049 return snd_soc_update_bits(codec, reg, 0xffff, val);
2051 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2054 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2056 * @clk_id: DAI specific clock ID
2057 * @freq: new clock frequency in Hz
2058 * @dir: new clock direction - input/output.
2060 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2062 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2063 unsigned int freq, int dir)
2065 if (dai->ops && dai->ops->set_sysclk)
2066 return dai->ops->set_sysclk(dai, clk_id, freq, dir);
2070 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2073 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2075 * @div_id: DAI specific clock divider ID
2076 * @div: new clock divisor.
2078 * Configures the clock dividers. This is used to derive the best DAI bit and
2079 * frame clocks from the system or master clock. It's best to set the DAI bit
2080 * and frame clocks as low as possible to save system power.
2082 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2083 int div_id, int div)
2085 if (dai->ops && dai->ops->set_clkdiv)
2086 return dai->ops->set_clkdiv(dai, div_id, div);
2090 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2093 * snd_soc_dai_set_pll - configure DAI PLL.
2095 * @pll_id: DAI specific PLL ID
2096 * @freq_in: PLL input clock frequency in Hz
2097 * @freq_out: requested PLL output clock frequency in Hz
2099 * Configures and enables PLL to generate output clock based on input clock.
2101 int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
2102 int pll_id, unsigned int freq_in, unsigned int freq_out)
2104 if (dai->ops && dai->ops->set_pll)
2105 return dai->ops->set_pll(dai, pll_id, freq_in, freq_out);
2109 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2112 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2114 * @fmt: SND_SOC_DAIFMT_ format value.
2116 * Configures the DAI hardware format and clocking.
2118 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2120 if (dai->ops && dai->ops->set_fmt)
2121 return dai->ops->set_fmt(dai, fmt);
2125 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2128 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2130 * @mask: DAI specific mask representing used slots.
2131 * @slots: Number of slots in use.
2133 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2136 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2137 unsigned int mask, int slots)
2139 if (dai->ops && dai->ops->set_tdm_slot)
2140 return dai->ops->set_tdm_slot(dai, mask, slots);
2144 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2147 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2149 * @tristate: tristate enable
2151 * Tristates the DAI so that others can use it.
2153 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2155 if (dai->ops && dai->ops->set_tristate)
2156 return dai->ops->set_tristate(dai, tristate);
2160 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2163 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2165 * @mute: mute enable
2167 * Mutes the DAI DAC.
2169 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2171 if (dai->ops && dai->ops->digital_mute)
2172 return dai->ops->digital_mute(dai, mute);
2176 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2179 * snd_soc_register_card - Register a card with the ASoC core
2181 * @card: Card to register
2183 * Note that currently this is an internal only function: it will be
2184 * exposed to machine drivers after further backporting of ASoC v2
2185 * registration APIs.
2187 static int snd_soc_register_card(struct snd_soc_card *card)
2189 if (!card->name || !card->dev)
2192 INIT_LIST_HEAD(&card->list);
2193 card->instantiated = 0;
2195 mutex_lock(&client_mutex);
2196 list_add(&card->list, &card_list);
2197 snd_soc_instantiate_cards();
2198 mutex_unlock(&client_mutex);
2200 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2206 * snd_soc_unregister_card - Unregister a card with the ASoC core
2208 * @card: Card to unregister
2210 * Note that currently this is an internal only function: it will be
2211 * exposed to machine drivers after further backporting of ASoC v2
2212 * registration APIs.
2214 static int snd_soc_unregister_card(struct snd_soc_card *card)
2216 mutex_lock(&client_mutex);
2217 list_del(&card->list);
2218 mutex_unlock(&client_mutex);
2220 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2225 static struct snd_soc_dai_ops null_dai_ops = {
2229 * snd_soc_register_dai - Register a DAI with the ASoC core
2231 * @dai: DAI to register
2233 int snd_soc_register_dai(struct snd_soc_dai *dai)
2238 /* The device should become mandatory over time */
2240 printk(KERN_WARNING "No device for DAI %s\n", dai->name);
2243 dai->ops = &null_dai_ops;
2245 INIT_LIST_HEAD(&dai->list);
2247 mutex_lock(&client_mutex);
2248 list_add(&dai->list, &dai_list);
2249 snd_soc_instantiate_cards();
2250 mutex_unlock(&client_mutex);
2252 pr_debug("Registered DAI '%s'\n", dai->name);
2256 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2259 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2261 * @dai: DAI to unregister
2263 void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2265 mutex_lock(&client_mutex);
2266 list_del(&dai->list);
2267 mutex_unlock(&client_mutex);
2269 pr_debug("Unregistered DAI '%s'\n", dai->name);
2271 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2274 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
2276 * @dai: Array of DAIs to register
2277 * @count: Number of DAIs
2279 int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count)
2283 for (i = 0; i < count; i++) {
2284 ret = snd_soc_register_dai(&dai[i]);
2292 for (i--; i >= 0; i--)
2293 snd_soc_unregister_dai(&dai[i]);
2297 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
2300 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
2302 * @dai: Array of DAIs to unregister
2303 * @count: Number of DAIs
2305 void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count)
2309 for (i = 0; i < count; i++)
2310 snd_soc_unregister_dai(&dai[i]);
2312 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
2315 * snd_soc_register_platform - Register a platform with the ASoC core
2317 * @platform: platform to register
2319 int snd_soc_register_platform(struct snd_soc_platform *platform)
2321 if (!platform->name)
2324 INIT_LIST_HEAD(&platform->list);
2326 mutex_lock(&client_mutex);
2327 list_add(&platform->list, &platform_list);
2328 snd_soc_instantiate_cards();
2329 mutex_unlock(&client_mutex);
2331 pr_debug("Registered platform '%s'\n", platform->name);
2335 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
2338 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
2340 * @platform: platform to unregister
2342 void snd_soc_unregister_platform(struct snd_soc_platform *platform)
2344 mutex_lock(&client_mutex);
2345 list_del(&platform->list);
2346 mutex_unlock(&client_mutex);
2348 pr_debug("Unregistered platform '%s'\n", platform->name);
2350 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
2352 static u64 codec_format_map[] = {
2353 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
2354 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
2355 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
2356 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
2357 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
2358 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
2359 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2360 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2361 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
2362 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
2363 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
2364 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
2365 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
2366 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
2367 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
2368 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
2371 /* Fix up the DAI formats for endianness: codecs don't actually see
2372 * the endianness of the data but we're using the CPU format
2373 * definitions which do need to include endianness so we ensure that
2374 * codec DAIs always have both big and little endian variants set.
2376 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
2380 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
2381 if (stream->formats & codec_format_map[i])
2382 stream->formats |= codec_format_map[i];
2386 * snd_soc_register_codec - Register a codec with the ASoC core
2388 * @codec: codec to register
2390 int snd_soc_register_codec(struct snd_soc_codec *codec)
2397 /* The device should become mandatory over time */
2399 printk(KERN_WARNING "No device for codec %s\n", codec->name);
2401 INIT_LIST_HEAD(&codec->list);
2403 for (i = 0; i < codec->num_dai; i++) {
2404 fixup_codec_formats(&codec->dai[i].playback);
2405 fixup_codec_formats(&codec->dai[i].capture);
2408 mutex_lock(&client_mutex);
2409 list_add(&codec->list, &codec_list);
2410 snd_soc_instantiate_cards();
2411 mutex_unlock(&client_mutex);
2413 pr_debug("Registered codec '%s'\n", codec->name);
2417 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
2420 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
2422 * @codec: codec to unregister
2424 void snd_soc_unregister_codec(struct snd_soc_codec *codec)
2426 mutex_lock(&client_mutex);
2427 list_del(&codec->list);
2428 mutex_unlock(&client_mutex);
2430 pr_debug("Unregistered codec '%s'\n", codec->name);
2432 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
2434 static int __init snd_soc_init(void)
2436 #ifdef CONFIG_DEBUG_FS
2437 debugfs_root = debugfs_create_dir("asoc", NULL);
2438 if (IS_ERR(debugfs_root) || !debugfs_root) {
2440 "ASoC: Failed to create debugfs directory\n");
2441 debugfs_root = NULL;
2445 return platform_driver_register(&soc_driver);
2448 static void __exit snd_soc_exit(void)
2450 #ifdef CONFIG_DEBUG_FS
2451 debugfs_remove_recursive(debugfs_root);
2453 platform_driver_unregister(&soc_driver);
2456 module_init(snd_soc_init);
2457 module_exit(snd_soc_exit);
2459 /* Module information */
2460 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2461 MODULE_DESCRIPTION("ALSA SoC Core");
2462 MODULE_LICENSE("GPL");
2463 MODULE_ALIAS("platform:soc-audio");