ARM: add a vma entry for the user accessible vector page
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / soc / soc-core.c
blobacc91daa1c5509df6a7844f684a0640ff7198109
1 /*
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.
16 * TODO:
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>
27 #include <linux/pm.h>
28 #include <linux/bitops.h>
29 #include <linux/debugfs.h>
30 #include <linux/platform_device.h>
31 #include <linux/slab.h>
32 #include <sound/ac97_codec.h>
33 #include <sound/core.h>
34 #include <sound/pcm.h>
35 #include <sound/pcm_params.h>
36 #include <sound/soc.h>
37 #include <sound/soc-dapm.h>
38 #include <sound/initval.h>
40 static DEFINE_MUTEX(pcm_mutex);
41 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
43 #ifdef CONFIG_DEBUG_FS
44 static struct dentry *debugfs_root;
45 #endif
47 static DEFINE_MUTEX(client_mutex);
48 static LIST_HEAD(card_list);
49 static LIST_HEAD(dai_list);
50 static LIST_HEAD(platform_list);
51 static LIST_HEAD(codec_list);
53 static int snd_soc_register_card(struct snd_soc_card *card);
54 static int snd_soc_unregister_card(struct snd_soc_card *card);
57 * This is a timeout to do a DAPM powerdown after a stream is closed().
58 * It can be used to eliminate pops between different playback streams, e.g.
59 * between two audio tracks.
61 static int pmdown_time = 5000;
62 module_param(pmdown_time, int, 0);
63 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
66 * This function forces any delayed work to be queued and run.
68 static int run_delayed_work(struct delayed_work *dwork)
70 int ret;
72 /* cancel any work waiting to be queued. */
73 ret = cancel_delayed_work(dwork);
75 /* if there was any work waiting then we run it now and
76 * wait for it's completion */
77 if (ret) {
78 schedule_delayed_work(dwork, 0);
79 flush_scheduled_work();
81 return ret;
84 /* codec register dump */
85 static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
87 int ret, i, step = 1, count = 0;
89 if (!codec->reg_cache_size)
90 return 0;
92 if (codec->reg_cache_step)
93 step = codec->reg_cache_step;
95 count += sprintf(buf, "%s registers\n", codec->name);
96 for (i = 0; i < codec->reg_cache_size; i += step) {
97 if (codec->readable_register && !codec->readable_register(i))
98 continue;
100 count += sprintf(buf + count, "%2x: ", i);
101 if (count >= PAGE_SIZE - 1)
102 break;
104 if (codec->display_register) {
105 count += codec->display_register(codec, buf + count,
106 PAGE_SIZE - count, i);
107 } else {
108 /* If the read fails it's almost certainly due to
109 * the register being volatile and the device being
110 * powered off.
112 ret = codec->read(codec, i);
113 if (ret >= 0)
114 count += snprintf(buf + count,
115 PAGE_SIZE - count,
116 "%4x", ret);
117 else
118 count += snprintf(buf + count,
119 PAGE_SIZE - count,
120 "<no data: %d>", ret);
123 if (count >= PAGE_SIZE - 1)
124 break;
126 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
127 if (count >= PAGE_SIZE - 1)
128 break;
131 /* Truncate count; min() would cause a warning */
132 if (count >= PAGE_SIZE)
133 count = PAGE_SIZE - 1;
135 return count;
137 static ssize_t codec_reg_show(struct device *dev,
138 struct device_attribute *attr, char *buf)
140 struct snd_soc_device *devdata = dev_get_drvdata(dev);
141 return soc_codec_reg_show(devdata->card->codec, buf);
144 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
146 static ssize_t pmdown_time_show(struct device *dev,
147 struct device_attribute *attr, char *buf)
149 struct snd_soc_device *socdev = dev_get_drvdata(dev);
150 struct snd_soc_card *card = socdev->card;
152 return sprintf(buf, "%ld\n", card->pmdown_time);
155 static ssize_t pmdown_time_set(struct device *dev,
156 struct device_attribute *attr,
157 const char *buf, size_t count)
159 struct snd_soc_device *socdev = dev_get_drvdata(dev);
160 struct snd_soc_card *card = socdev->card;
162 strict_strtol(buf, 10, &card->pmdown_time);
164 return count;
167 static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
169 #ifdef CONFIG_DEBUG_FS
170 static int codec_reg_open_file(struct inode *inode, struct file *file)
172 file->private_data = inode->i_private;
173 return 0;
176 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
177 size_t count, loff_t *ppos)
179 ssize_t ret;
180 struct snd_soc_codec *codec = file->private_data;
181 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
182 if (!buf)
183 return -ENOMEM;
184 ret = soc_codec_reg_show(codec, buf);
185 if (ret >= 0)
186 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
187 kfree(buf);
188 return ret;
191 static ssize_t codec_reg_write_file(struct file *file,
192 const char __user *user_buf, size_t count, loff_t *ppos)
194 char buf[32];
195 int buf_size;
196 char *start = buf;
197 unsigned long reg, value;
198 int step = 1;
199 struct snd_soc_codec *codec = file->private_data;
201 buf_size = min(count, (sizeof(buf)-1));
202 if (copy_from_user(buf, user_buf, buf_size))
203 return -EFAULT;
204 buf[buf_size] = 0;
206 if (codec->reg_cache_step)
207 step = codec->reg_cache_step;
209 while (*start == ' ')
210 start++;
211 reg = simple_strtoul(start, &start, 16);
212 if ((reg >= codec->reg_cache_size) || (reg % step))
213 return -EINVAL;
214 while (*start == ' ')
215 start++;
216 if (strict_strtoul(start, 16, &value))
217 return -EINVAL;
218 codec->write(codec, reg, value);
219 return buf_size;
222 static const struct file_operations codec_reg_fops = {
223 .open = codec_reg_open_file,
224 .read = codec_reg_read_file,
225 .write = codec_reg_write_file,
228 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
230 char codec_root[128];
232 if (codec->dev)
233 snprintf(codec_root, sizeof(codec_root),
234 "%s.%s", codec->name, dev_name(codec->dev));
235 else
236 snprintf(codec_root, sizeof(codec_root),
237 "%s", codec->name);
239 codec->debugfs_codec_root = debugfs_create_dir(codec_root,
240 debugfs_root);
241 if (!codec->debugfs_codec_root) {
242 printk(KERN_WARNING
243 "ASoC: Failed to create codec debugfs directory\n");
244 return;
247 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
248 codec->debugfs_codec_root,
249 codec, &codec_reg_fops);
250 if (!codec->debugfs_reg)
251 printk(KERN_WARNING
252 "ASoC: Failed to create codec register debugfs file\n");
254 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
255 codec->debugfs_codec_root,
256 &codec->pop_time);
257 if (!codec->debugfs_pop_time)
258 printk(KERN_WARNING
259 "Failed to create pop time debugfs file\n");
261 codec->debugfs_dapm = debugfs_create_dir("dapm",
262 codec->debugfs_codec_root);
263 if (!codec->debugfs_dapm)
264 printk(KERN_WARNING
265 "Failed to create DAPM debugfs directory\n");
267 snd_soc_dapm_debugfs_init(codec);
270 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
272 debugfs_remove_recursive(codec->debugfs_codec_root);
275 #else
277 static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
281 static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
284 #endif
286 #ifdef CONFIG_SND_SOC_AC97_BUS
287 /* unregister ac97 codec */
288 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
290 if (codec->ac97->dev.bus)
291 device_unregister(&codec->ac97->dev);
292 return 0;
295 /* stop no dev release warning */
296 static void soc_ac97_device_release(struct device *dev){}
298 /* register ac97 codec to bus */
299 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
301 int err;
303 codec->ac97->dev.bus = &ac97_bus_type;
304 codec->ac97->dev.parent = codec->card->dev;
305 codec->ac97->dev.release = soc_ac97_device_release;
307 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
308 codec->card->number, 0, codec->name);
309 err = device_register(&codec->ac97->dev);
310 if (err < 0) {
311 snd_printk(KERN_ERR "Can't register ac97 bus\n");
312 codec->ac97->dev.bus = NULL;
313 return err;
315 return 0;
317 #endif
319 static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
321 struct snd_soc_pcm_runtime *rtd = substream->private_data;
322 struct snd_soc_device *socdev = rtd->socdev;
323 struct snd_soc_card *card = socdev->card;
324 struct snd_soc_dai_link *machine = rtd->dai;
325 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
326 struct snd_soc_dai *codec_dai = machine->codec_dai;
327 int ret;
329 if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
330 machine->symmetric_rates) {
331 dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
332 machine->rate);
334 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
335 SNDRV_PCM_HW_PARAM_RATE,
336 machine->rate,
337 machine->rate);
338 if (ret < 0) {
339 dev_err(card->dev,
340 "Unable to apply rate symmetry constraint: %d\n", ret);
341 return ret;
345 return 0;
349 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
350 * then initialized and any private data can be allocated. This also calls
351 * startup for the cpu DAI, platform, machine and codec DAI.
353 static int soc_pcm_open(struct snd_pcm_substream *substream)
355 struct snd_soc_pcm_runtime *rtd = substream->private_data;
356 struct snd_soc_device *socdev = rtd->socdev;
357 struct snd_soc_card *card = socdev->card;
358 struct snd_pcm_runtime *runtime = substream->runtime;
359 struct snd_soc_dai_link *machine = rtd->dai;
360 struct snd_soc_platform *platform = card->platform;
361 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
362 struct snd_soc_dai *codec_dai = machine->codec_dai;
363 int ret = 0;
365 mutex_lock(&pcm_mutex);
367 /* startup the audio subsystem */
368 if (cpu_dai->ops->startup) {
369 ret = cpu_dai->ops->startup(substream, cpu_dai);
370 if (ret < 0) {
371 printk(KERN_ERR "asoc: can't open interface %s\n",
372 cpu_dai->name);
373 goto out;
377 if (platform->pcm_ops->open) {
378 ret = platform->pcm_ops->open(substream);
379 if (ret < 0) {
380 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
381 goto platform_err;
385 if (codec_dai->ops->startup) {
386 ret = codec_dai->ops->startup(substream, codec_dai);
387 if (ret < 0) {
388 printk(KERN_ERR "asoc: can't open codec %s\n",
389 codec_dai->name);
390 goto codec_dai_err;
394 if (machine->ops && machine->ops->startup) {
395 ret = machine->ops->startup(substream);
396 if (ret < 0) {
397 printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
398 goto machine_err;
402 /* Check that the codec and cpu DAI's are compatible */
403 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
404 runtime->hw.rate_min =
405 max(codec_dai->playback.rate_min,
406 cpu_dai->playback.rate_min);
407 runtime->hw.rate_max =
408 min(codec_dai->playback.rate_max,
409 cpu_dai->playback.rate_max);
410 runtime->hw.channels_min =
411 max(codec_dai->playback.channels_min,
412 cpu_dai->playback.channels_min);
413 runtime->hw.channels_max =
414 min(codec_dai->playback.channels_max,
415 cpu_dai->playback.channels_max);
416 runtime->hw.formats =
417 codec_dai->playback.formats & cpu_dai->playback.formats;
418 runtime->hw.rates =
419 codec_dai->playback.rates & cpu_dai->playback.rates;
420 if (codec_dai->playback.rates
421 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
422 runtime->hw.rates |= cpu_dai->playback.rates;
423 if (cpu_dai->playback.rates
424 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
425 runtime->hw.rates |= codec_dai->playback.rates;
426 } else {
427 runtime->hw.rate_min =
428 max(codec_dai->capture.rate_min,
429 cpu_dai->capture.rate_min);
430 runtime->hw.rate_max =
431 min(codec_dai->capture.rate_max,
432 cpu_dai->capture.rate_max);
433 runtime->hw.channels_min =
434 max(codec_dai->capture.channels_min,
435 cpu_dai->capture.channels_min);
436 runtime->hw.channels_max =
437 min(codec_dai->capture.channels_max,
438 cpu_dai->capture.channels_max);
439 runtime->hw.formats =
440 codec_dai->capture.formats & cpu_dai->capture.formats;
441 runtime->hw.rates =
442 codec_dai->capture.rates & cpu_dai->capture.rates;
443 if (codec_dai->capture.rates
444 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
445 runtime->hw.rates |= cpu_dai->capture.rates;
446 if (cpu_dai->capture.rates
447 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
448 runtime->hw.rates |= codec_dai->capture.rates;
451 snd_pcm_limit_hw_rates(runtime);
452 if (!runtime->hw.rates) {
453 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
454 codec_dai->name, cpu_dai->name);
455 goto config_err;
457 if (!runtime->hw.formats) {
458 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
459 codec_dai->name, cpu_dai->name);
460 goto config_err;
462 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
463 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
464 codec_dai->name, cpu_dai->name);
465 goto config_err;
468 /* Symmetry only applies if we've already got an active stream. */
469 if (cpu_dai->active || codec_dai->active) {
470 ret = soc_pcm_apply_symmetry(substream);
471 if (ret != 0)
472 goto config_err;
475 pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
476 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
477 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
478 runtime->hw.channels_max);
479 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
480 runtime->hw.rate_max);
482 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
483 cpu_dai->playback.active++;
484 codec_dai->playback.active++;
485 } else {
486 cpu_dai->capture.active++;
487 codec_dai->capture.active++;
489 cpu_dai->active++;
490 codec_dai->active++;
491 card->codec->active++;
492 mutex_unlock(&pcm_mutex);
493 return 0;
495 config_err:
496 if (machine->ops && machine->ops->shutdown)
497 machine->ops->shutdown(substream);
499 machine_err:
500 if (codec_dai->ops->shutdown)
501 codec_dai->ops->shutdown(substream, codec_dai);
503 codec_dai_err:
504 if (platform->pcm_ops->close)
505 platform->pcm_ops->close(substream);
507 platform_err:
508 if (cpu_dai->ops->shutdown)
509 cpu_dai->ops->shutdown(substream, cpu_dai);
510 out:
511 mutex_unlock(&pcm_mutex);
512 return ret;
516 * Power down the audio subsystem pmdown_time msecs after close is called.
517 * This is to ensure there are no pops or clicks in between any music tracks
518 * due to DAPM power cycling.
520 static void close_delayed_work(struct work_struct *work)
522 struct snd_soc_card *card = container_of(work, struct snd_soc_card,
523 delayed_work.work);
524 struct snd_soc_codec *codec = card->codec;
525 struct snd_soc_dai *codec_dai;
526 int i;
528 mutex_lock(&pcm_mutex);
529 for (i = 0; i < codec->num_dai; i++) {
530 codec_dai = &codec->dai[i];
532 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
533 codec_dai->playback.stream_name,
534 codec_dai->playback.active ? "active" : "inactive",
535 codec_dai->pop_wait ? "yes" : "no");
537 /* are we waiting on this codec DAI stream */
538 if (codec_dai->pop_wait == 1) {
539 codec_dai->pop_wait = 0;
540 snd_soc_dapm_stream_event(codec,
541 codec_dai->playback.stream_name,
542 SND_SOC_DAPM_STREAM_STOP);
545 mutex_unlock(&pcm_mutex);
549 * Called by ALSA when a PCM substream is closed. Private data can be
550 * freed here. The cpu DAI, codec DAI, machine and platform are also
551 * shutdown.
553 static int soc_codec_close(struct snd_pcm_substream *substream)
555 struct snd_soc_pcm_runtime *rtd = substream->private_data;
556 struct snd_soc_device *socdev = rtd->socdev;
557 struct snd_soc_card *card = socdev->card;
558 struct snd_soc_dai_link *machine = rtd->dai;
559 struct snd_soc_platform *platform = card->platform;
560 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
561 struct snd_soc_dai *codec_dai = machine->codec_dai;
562 struct snd_soc_codec *codec = card->codec;
564 mutex_lock(&pcm_mutex);
566 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
567 cpu_dai->playback.active--;
568 codec_dai->playback.active--;
569 } else {
570 cpu_dai->capture.active--;
571 codec_dai->capture.active--;
574 cpu_dai->active--;
575 codec_dai->active--;
576 codec->active--;
578 /* Muting the DAC suppresses artifacts caused during digital
579 * shutdown, for example from stopping clocks.
581 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
582 snd_soc_dai_digital_mute(codec_dai, 1);
584 if (cpu_dai->ops->shutdown)
585 cpu_dai->ops->shutdown(substream, cpu_dai);
587 if (codec_dai->ops->shutdown)
588 codec_dai->ops->shutdown(substream, codec_dai);
590 if (machine->ops && machine->ops->shutdown)
591 machine->ops->shutdown(substream);
593 if (platform->pcm_ops->close)
594 platform->pcm_ops->close(substream);
596 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
597 /* start delayed pop wq here for playback streams */
598 codec_dai->pop_wait = 1;
599 schedule_delayed_work(&card->delayed_work,
600 msecs_to_jiffies(card->pmdown_time));
601 } else {
602 /* capture streams can be powered down now */
603 snd_soc_dapm_stream_event(codec,
604 codec_dai->capture.stream_name,
605 SND_SOC_DAPM_STREAM_STOP);
608 mutex_unlock(&pcm_mutex);
609 return 0;
613 * Called by ALSA when the PCM substream is prepared, can set format, sample
614 * rate, etc. This function is non atomic and can be called multiple times,
615 * it can refer to the runtime info.
617 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
619 struct snd_soc_pcm_runtime *rtd = substream->private_data;
620 struct snd_soc_device *socdev = rtd->socdev;
621 struct snd_soc_card *card = socdev->card;
622 struct snd_soc_dai_link *machine = rtd->dai;
623 struct snd_soc_platform *platform = card->platform;
624 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
625 struct snd_soc_dai *codec_dai = machine->codec_dai;
626 struct snd_soc_codec *codec = card->codec;
627 int ret = 0;
629 mutex_lock(&pcm_mutex);
631 if (machine->ops && machine->ops->prepare) {
632 ret = machine->ops->prepare(substream);
633 if (ret < 0) {
634 printk(KERN_ERR "asoc: machine prepare error\n");
635 goto out;
639 if (platform->pcm_ops->prepare) {
640 ret = platform->pcm_ops->prepare(substream);
641 if (ret < 0) {
642 printk(KERN_ERR "asoc: platform prepare error\n");
643 goto out;
647 if (codec_dai->ops->prepare) {
648 ret = codec_dai->ops->prepare(substream, codec_dai);
649 if (ret < 0) {
650 printk(KERN_ERR "asoc: codec DAI prepare error\n");
651 goto out;
655 if (cpu_dai->ops->prepare) {
656 ret = cpu_dai->ops->prepare(substream, cpu_dai);
657 if (ret < 0) {
658 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
659 goto out;
663 /* cancel any delayed stream shutdown that is pending */
664 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
665 codec_dai->pop_wait) {
666 codec_dai->pop_wait = 0;
667 cancel_delayed_work(&card->delayed_work);
670 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
671 snd_soc_dapm_stream_event(codec,
672 codec_dai->playback.stream_name,
673 SND_SOC_DAPM_STREAM_START);
674 else
675 snd_soc_dapm_stream_event(codec,
676 codec_dai->capture.stream_name,
677 SND_SOC_DAPM_STREAM_START);
679 snd_soc_dai_digital_mute(codec_dai, 0);
681 out:
682 mutex_unlock(&pcm_mutex);
683 return ret;
687 * Called by ALSA when the hardware params are set by application. This
688 * function can also be called multiple times and can allocate buffers
689 * (using snd_pcm_lib_* ). It's non-atomic.
691 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
692 struct snd_pcm_hw_params *params)
694 struct snd_soc_pcm_runtime *rtd = substream->private_data;
695 struct snd_soc_device *socdev = rtd->socdev;
696 struct snd_soc_dai_link *machine = rtd->dai;
697 struct snd_soc_card *card = socdev->card;
698 struct snd_soc_platform *platform = card->platform;
699 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
700 struct snd_soc_dai *codec_dai = machine->codec_dai;
701 int ret = 0;
703 mutex_lock(&pcm_mutex);
705 if (machine->ops && machine->ops->hw_params) {
706 ret = machine->ops->hw_params(substream, params);
707 if (ret < 0) {
708 printk(KERN_ERR "asoc: machine hw_params failed\n");
709 goto out;
713 if (codec_dai->ops->hw_params) {
714 ret = codec_dai->ops->hw_params(substream, params, codec_dai);
715 if (ret < 0) {
716 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
717 codec_dai->name);
718 goto codec_err;
722 if (cpu_dai->ops->hw_params) {
723 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
724 if (ret < 0) {
725 printk(KERN_ERR "asoc: interface %s hw params failed\n",
726 cpu_dai->name);
727 goto interface_err;
731 if (platform->pcm_ops->hw_params) {
732 ret = platform->pcm_ops->hw_params(substream, params);
733 if (ret < 0) {
734 printk(KERN_ERR "asoc: platform %s hw params failed\n",
735 platform->name);
736 goto platform_err;
740 machine->rate = params_rate(params);
742 out:
743 mutex_unlock(&pcm_mutex);
744 return ret;
746 platform_err:
747 if (cpu_dai->ops->hw_free)
748 cpu_dai->ops->hw_free(substream, cpu_dai);
750 interface_err:
751 if (codec_dai->ops->hw_free)
752 codec_dai->ops->hw_free(substream, codec_dai);
754 codec_err:
755 if (machine->ops && machine->ops->hw_free)
756 machine->ops->hw_free(substream);
758 mutex_unlock(&pcm_mutex);
759 return ret;
763 * Free's resources allocated by hw_params, can be called multiple times
765 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
767 struct snd_soc_pcm_runtime *rtd = substream->private_data;
768 struct snd_soc_device *socdev = rtd->socdev;
769 struct snd_soc_dai_link *machine = rtd->dai;
770 struct snd_soc_card *card = socdev->card;
771 struct snd_soc_platform *platform = card->platform;
772 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
773 struct snd_soc_dai *codec_dai = machine->codec_dai;
774 struct snd_soc_codec *codec = card->codec;
776 mutex_lock(&pcm_mutex);
778 /* apply codec digital mute */
779 if (!codec->active)
780 snd_soc_dai_digital_mute(codec_dai, 1);
782 /* free any machine hw params */
783 if (machine->ops && machine->ops->hw_free)
784 machine->ops->hw_free(substream);
786 /* free any DMA resources */
787 if (platform->pcm_ops->hw_free)
788 platform->pcm_ops->hw_free(substream);
790 /* now free hw params for the DAI's */
791 if (codec_dai->ops->hw_free)
792 codec_dai->ops->hw_free(substream, codec_dai);
794 if (cpu_dai->ops->hw_free)
795 cpu_dai->ops->hw_free(substream, cpu_dai);
797 mutex_unlock(&pcm_mutex);
798 return 0;
801 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
803 struct snd_soc_pcm_runtime *rtd = substream->private_data;
804 struct snd_soc_device *socdev = rtd->socdev;
805 struct snd_soc_card *card= socdev->card;
806 struct snd_soc_dai_link *machine = rtd->dai;
807 struct snd_soc_platform *platform = card->platform;
808 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
809 struct snd_soc_dai *codec_dai = machine->codec_dai;
810 int ret;
812 if (codec_dai->ops->trigger) {
813 ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
814 if (ret < 0)
815 return ret;
818 if (platform->pcm_ops->trigger) {
819 ret = platform->pcm_ops->trigger(substream, cmd);
820 if (ret < 0)
821 return ret;
824 if (cpu_dai->ops->trigger) {
825 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
826 if (ret < 0)
827 return ret;
829 return 0;
833 * soc level wrapper for pointer callback
834 * If cpu_dai, codec_dai, platform driver has the delay callback, than
835 * the runtime->delay will be updated accordingly.
837 static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
839 struct snd_soc_pcm_runtime *rtd = substream->private_data;
840 struct snd_soc_device *socdev = rtd->socdev;
841 struct snd_soc_card *card = socdev->card;
842 struct snd_soc_platform *platform = card->platform;
843 struct snd_soc_dai_link *machine = rtd->dai;
844 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
845 struct snd_soc_dai *codec_dai = machine->codec_dai;
846 struct snd_pcm_runtime *runtime = substream->runtime;
847 snd_pcm_uframes_t offset = 0;
848 snd_pcm_sframes_t delay = 0;
850 if (platform->pcm_ops->pointer)
851 offset = platform->pcm_ops->pointer(substream);
853 if (cpu_dai->ops->delay)
854 delay += cpu_dai->ops->delay(substream, cpu_dai);
856 if (codec_dai->ops->delay)
857 delay += codec_dai->ops->delay(substream, codec_dai);
859 if (platform->delay)
860 delay += platform->delay(substream, codec_dai);
862 runtime->delay = delay;
864 return offset;
867 /* ASoC PCM operations */
868 static struct snd_pcm_ops soc_pcm_ops = {
869 .open = soc_pcm_open,
870 .close = soc_codec_close,
871 .hw_params = soc_pcm_hw_params,
872 .hw_free = soc_pcm_hw_free,
873 .prepare = soc_pcm_prepare,
874 .trigger = soc_pcm_trigger,
875 .pointer = soc_pcm_pointer,
878 #ifdef CONFIG_PM
879 /* powers down audio subsystem for suspend */
880 static int soc_suspend(struct device *dev)
882 struct platform_device *pdev = to_platform_device(dev);
883 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
884 struct snd_soc_card *card = socdev->card;
885 struct snd_soc_platform *platform = card->platform;
886 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
887 struct snd_soc_codec *codec = card->codec;
888 int i;
890 /* If the initialization of this soc device failed, there is no codec
891 * associated with it. Just bail out in this case.
893 if (!codec)
894 return 0;
896 /* Due to the resume being scheduled into a workqueue we could
897 * suspend before that's finished - wait for it to complete.
899 snd_power_lock(codec->card);
900 snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
901 snd_power_unlock(codec->card);
903 /* we're going to block userspace touching us until resume completes */
904 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
906 /* mute any active DAC's */
907 for (i = 0; i < card->num_links; i++) {
908 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
910 if (card->dai_link[i].ignore_suspend)
911 continue;
913 if (dai->ops->digital_mute && dai->playback.active)
914 dai->ops->digital_mute(dai, 1);
917 /* suspend all pcms */
918 for (i = 0; i < card->num_links; i++) {
919 if (card->dai_link[i].ignore_suspend)
920 continue;
922 snd_pcm_suspend_all(card->dai_link[i].pcm);
925 if (card->suspend_pre)
926 card->suspend_pre(pdev, PMSG_SUSPEND);
928 for (i = 0; i < card->num_links; i++) {
929 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
931 if (card->dai_link[i].ignore_suspend)
932 continue;
934 if (cpu_dai->suspend && !cpu_dai->ac97_control)
935 cpu_dai->suspend(cpu_dai);
936 if (platform->suspend)
937 platform->suspend(&card->dai_link[i]);
940 /* close any waiting streams and save state */
941 run_delayed_work(&card->delayed_work);
942 codec->suspend_bias_level = codec->bias_level;
944 for (i = 0; i < codec->num_dai; i++) {
945 char *stream = codec->dai[i].playback.stream_name;
947 if (card->dai_link[i].ignore_suspend)
948 continue;
950 if (stream != NULL)
951 snd_soc_dapm_stream_event(codec, stream,
952 SND_SOC_DAPM_STREAM_SUSPEND);
953 stream = codec->dai[i].capture.stream_name;
954 if (stream != NULL)
955 snd_soc_dapm_stream_event(codec, stream,
956 SND_SOC_DAPM_STREAM_SUSPEND);
959 /* If there are paths active then the CODEC will be held with
960 * bias _ON and should not be suspended. */
961 if (codec_dev->suspend) {
962 switch (codec->bias_level) {
963 case SND_SOC_BIAS_STANDBY:
964 case SND_SOC_BIAS_OFF:
965 codec_dev->suspend(pdev, PMSG_SUSPEND);
966 break;
967 default:
968 dev_dbg(socdev->dev, "CODEC is on over suspend\n");
969 break;
973 for (i = 0; i < card->num_links; i++) {
974 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
976 if (card->dai_link[i].ignore_suspend)
977 continue;
979 if (cpu_dai->suspend && cpu_dai->ac97_control)
980 cpu_dai->suspend(cpu_dai);
983 if (card->suspend_post)
984 card->suspend_post(pdev, PMSG_SUSPEND);
986 return 0;
989 /* deferred resume work, so resume can complete before we finished
990 * setting our codec back up, which can be very slow on I2C
992 static void soc_resume_deferred(struct work_struct *work)
994 struct snd_soc_card *card = container_of(work,
995 struct snd_soc_card,
996 deferred_resume_work);
997 struct snd_soc_device *socdev = card->socdev;
998 struct snd_soc_platform *platform = card->platform;
999 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1000 struct snd_soc_codec *codec = card->codec;
1001 struct platform_device *pdev = to_platform_device(socdev->dev);
1002 int i;
1004 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
1005 * so userspace apps are blocked from touching us
1008 dev_dbg(socdev->dev, "starting resume work\n");
1010 /* Bring us up into D2 so that DAPM starts enabling things */
1011 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D2);
1013 if (card->resume_pre)
1014 card->resume_pre(pdev);
1016 for (i = 0; i < card->num_links; i++) {
1017 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1019 if (card->dai_link[i].ignore_suspend)
1020 continue;
1022 if (cpu_dai->resume && cpu_dai->ac97_control)
1023 cpu_dai->resume(cpu_dai);
1026 /* If the CODEC was idle over suspend then it will have been
1027 * left with bias OFF or STANDBY and suspended so we must now
1028 * resume. Otherwise the suspend was suppressed.
1030 if (codec_dev->resume) {
1031 switch (codec->bias_level) {
1032 case SND_SOC_BIAS_STANDBY:
1033 case SND_SOC_BIAS_OFF:
1034 codec_dev->resume(pdev);
1035 break;
1036 default:
1037 dev_dbg(socdev->dev, "CODEC was on over suspend\n");
1038 break;
1042 for (i = 0; i < codec->num_dai; i++) {
1043 char *stream = codec->dai[i].playback.stream_name;
1045 if (card->dai_link[i].ignore_suspend)
1046 continue;
1048 if (stream != NULL)
1049 snd_soc_dapm_stream_event(codec, stream,
1050 SND_SOC_DAPM_STREAM_RESUME);
1051 stream = codec->dai[i].capture.stream_name;
1052 if (stream != NULL)
1053 snd_soc_dapm_stream_event(codec, stream,
1054 SND_SOC_DAPM_STREAM_RESUME);
1057 /* unmute any active DACs */
1058 for (i = 0; i < card->num_links; i++) {
1059 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
1061 if (card->dai_link[i].ignore_suspend)
1062 continue;
1064 if (dai->ops->digital_mute && dai->playback.active)
1065 dai->ops->digital_mute(dai, 0);
1068 for (i = 0; i < card->num_links; i++) {
1069 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1071 if (card->dai_link[i].ignore_suspend)
1072 continue;
1074 if (cpu_dai->resume && !cpu_dai->ac97_control)
1075 cpu_dai->resume(cpu_dai);
1076 if (platform->resume)
1077 platform->resume(&card->dai_link[i]);
1080 if (card->resume_post)
1081 card->resume_post(pdev);
1083 dev_dbg(socdev->dev, "resume work completed\n");
1085 /* userspace can access us now we are back as we were before */
1086 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
1089 /* powers up audio subsystem after a suspend */
1090 static int soc_resume(struct device *dev)
1092 struct platform_device *pdev = to_platform_device(dev);
1093 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1094 struct snd_soc_card *card = socdev->card;
1095 struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
1097 /* If the initialization of this soc device failed, there is no codec
1098 * associated with it. Just bail out in this case.
1100 if (!card->codec)
1101 return 0;
1103 /* AC97 devices might have other drivers hanging off them so
1104 * need to resume immediately. Other drivers don't have that
1105 * problem and may take a substantial amount of time to resume
1106 * due to I/O costs and anti-pop so handle them out of line.
1108 if (cpu_dai->ac97_control) {
1109 dev_dbg(socdev->dev, "Resuming AC97 immediately\n");
1110 soc_resume_deferred(&card->deferred_resume_work);
1111 } else {
1112 dev_dbg(socdev->dev, "Scheduling resume work\n");
1113 if (!schedule_work(&card->deferred_resume_work))
1114 dev_err(socdev->dev, "resume work item may be lost\n");
1117 return 0;
1119 #else
1120 #define soc_suspend NULL
1121 #define soc_resume NULL
1122 #endif
1124 static struct snd_soc_dai_ops null_dai_ops = {
1127 static void snd_soc_instantiate_card(struct snd_soc_card *card)
1129 struct platform_device *pdev = container_of(card->dev,
1130 struct platform_device,
1131 dev);
1132 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
1133 struct snd_soc_codec *codec;
1134 struct snd_soc_platform *platform;
1135 struct snd_soc_dai *dai;
1136 int i, found, ret, ac97;
1138 if (card->instantiated)
1139 return;
1141 found = 0;
1142 list_for_each_entry(platform, &platform_list, list)
1143 if (card->platform == platform) {
1144 found = 1;
1145 break;
1147 if (!found) {
1148 dev_dbg(card->dev, "Platform %s not registered\n",
1149 card->platform->name);
1150 return;
1153 ac97 = 0;
1154 for (i = 0; i < card->num_links; i++) {
1155 found = 0;
1156 list_for_each_entry(dai, &dai_list, list)
1157 if (card->dai_link[i].cpu_dai == dai) {
1158 found = 1;
1159 break;
1161 if (!found) {
1162 dev_dbg(card->dev, "DAI %s not registered\n",
1163 card->dai_link[i].cpu_dai->name);
1164 return;
1167 if (card->dai_link[i].cpu_dai->ac97_control)
1168 ac97 = 1;
1171 for (i = 0; i < card->num_links; i++) {
1172 if (!card->dai_link[i].codec_dai->ops)
1173 card->dai_link[i].codec_dai->ops = &null_dai_ops;
1176 /* If we have AC97 in the system then don't wait for the
1177 * codec. This will need revisiting if we have to handle
1178 * systems with mixed AC97 and non-AC97 parts. Only check for
1179 * DAIs currently; we can't do this per link since some AC97
1180 * codecs have non-AC97 DAIs.
1182 if (!ac97)
1183 for (i = 0; i < card->num_links; i++) {
1184 found = 0;
1185 list_for_each_entry(dai, &dai_list, list)
1186 if (card->dai_link[i].codec_dai == dai) {
1187 found = 1;
1188 break;
1190 if (!found) {
1191 dev_dbg(card->dev, "DAI %s not registered\n",
1192 card->dai_link[i].codec_dai->name);
1193 return;
1197 /* Note that we do not current check for codec components */
1199 dev_dbg(card->dev, "All components present, instantiating\n");
1201 /* Found everything, bring it up */
1202 card->pmdown_time = pmdown_time;
1204 if (card->probe) {
1205 ret = card->probe(pdev);
1206 if (ret < 0)
1207 return;
1210 for (i = 0; i < card->num_links; i++) {
1211 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1212 if (cpu_dai->probe) {
1213 ret = cpu_dai->probe(pdev, cpu_dai);
1214 if (ret < 0)
1215 goto cpu_dai_err;
1219 if (codec_dev->probe) {
1220 ret = codec_dev->probe(pdev);
1221 if (ret < 0)
1222 goto cpu_dai_err;
1224 codec = card->codec;
1226 if (platform->probe) {
1227 ret = platform->probe(pdev);
1228 if (ret < 0)
1229 goto platform_err;
1232 /* DAPM stream work */
1233 INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
1234 #ifdef CONFIG_PM
1235 /* deferred resume work */
1236 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1237 #endif
1239 for (i = 0; i < card->num_links; i++) {
1240 if (card->dai_link[i].init) {
1241 ret = card->dai_link[i].init(codec);
1242 if (ret < 0) {
1243 printk(KERN_ERR "asoc: failed to init %s\n",
1244 card->dai_link[i].stream_name);
1245 continue;
1248 if (card->dai_link[i].codec_dai->ac97_control)
1249 ac97 = 1;
1252 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1253 "%s", card->name);
1254 snprintf(codec->card->longname, sizeof(codec->card->longname),
1255 "%s (%s)", card->name, codec->name);
1257 /* Make sure all DAPM widgets are instantiated */
1258 snd_soc_dapm_new_widgets(codec);
1260 ret = snd_card_register(codec->card);
1261 if (ret < 0) {
1262 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1263 codec->name);
1264 goto card_err;
1267 mutex_lock(&codec->mutex);
1268 #ifdef CONFIG_SND_SOC_AC97_BUS
1269 /* Only instantiate AC97 if not already done by the adaptor
1270 * for the generic AC97 subsystem.
1272 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1273 ret = soc_ac97_dev_register(codec);
1274 if (ret < 0) {
1275 printk(KERN_ERR "asoc: AC97 device register failed\n");
1276 snd_card_free(codec->card);
1277 mutex_unlock(&codec->mutex);
1278 goto card_err;
1281 #endif
1283 ret = snd_soc_dapm_sys_add(card->socdev->dev);
1284 if (ret < 0)
1285 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1287 ret = device_create_file(card->socdev->dev, &dev_attr_pmdown_time);
1288 if (ret < 0)
1289 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1291 ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg);
1292 if (ret < 0)
1293 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1295 soc_init_codec_debugfs(codec);
1296 mutex_unlock(&codec->mutex);
1298 card->instantiated = 1;
1300 return;
1302 card_err:
1303 if (platform->remove)
1304 platform->remove(pdev);
1306 platform_err:
1307 if (codec_dev->remove)
1308 codec_dev->remove(pdev);
1310 cpu_dai_err:
1311 for (i--; i >= 0; i--) {
1312 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1313 if (cpu_dai->remove)
1314 cpu_dai->remove(pdev, cpu_dai);
1317 if (card->remove)
1318 card->remove(pdev);
1322 * Attempt to initialise any uninitialised cards. Must be called with
1323 * client_mutex.
1325 static void snd_soc_instantiate_cards(void)
1327 struct snd_soc_card *card;
1328 list_for_each_entry(card, &card_list, list)
1329 snd_soc_instantiate_card(card);
1332 /* probes a new socdev */
1333 static int soc_probe(struct platform_device *pdev)
1335 int ret = 0;
1336 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1337 struct snd_soc_card *card = socdev->card;
1339 /* Bodge while we push things out of socdev */
1340 card->socdev = socdev;
1342 /* Bodge while we unpick instantiation */
1343 card->dev = &pdev->dev;
1344 ret = snd_soc_register_card(card);
1345 if (ret != 0) {
1346 dev_err(&pdev->dev, "Failed to register card\n");
1347 return ret;
1350 return 0;
1353 /* removes a socdev */
1354 static int soc_remove(struct platform_device *pdev)
1356 int i;
1357 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1358 struct snd_soc_card *card = socdev->card;
1359 struct snd_soc_platform *platform = card->platform;
1360 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1362 if (card->instantiated) {
1363 run_delayed_work(&card->delayed_work);
1365 if (platform->remove)
1366 platform->remove(pdev);
1368 if (codec_dev->remove)
1369 codec_dev->remove(pdev);
1371 for (i = 0; i < card->num_links; i++) {
1372 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1373 if (cpu_dai->remove)
1374 cpu_dai->remove(pdev, cpu_dai);
1377 if (card->remove)
1378 card->remove(pdev);
1381 snd_soc_unregister_card(card);
1383 return 0;
1386 static int soc_poweroff(struct device *dev)
1388 struct platform_device *pdev = to_platform_device(dev);
1389 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1390 struct snd_soc_card *card = socdev->card;
1392 if (!card->instantiated)
1393 return 0;
1395 /* Flush out pmdown_time work - we actually do want to run it
1396 * now, we're shutting down so no imminent restart. */
1397 run_delayed_work(&card->delayed_work);
1399 snd_soc_dapm_shutdown(socdev);
1401 return 0;
1404 static const struct dev_pm_ops soc_pm_ops = {
1405 .suspend = soc_suspend,
1406 .resume = soc_resume,
1407 .poweroff = soc_poweroff,
1410 /* ASoC platform driver */
1411 static struct platform_driver soc_driver = {
1412 .driver = {
1413 .name = "soc-audio",
1414 .owner = THIS_MODULE,
1415 .pm = &soc_pm_ops,
1417 .probe = soc_probe,
1418 .remove = soc_remove,
1421 /* create a new pcm */
1422 static int soc_new_pcm(struct snd_soc_device *socdev,
1423 struct snd_soc_dai_link *dai_link, int num)
1425 struct snd_soc_card *card = socdev->card;
1426 struct snd_soc_codec *codec = card->codec;
1427 struct snd_soc_platform *platform = card->platform;
1428 struct snd_soc_dai *codec_dai = dai_link->codec_dai;
1429 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
1430 struct snd_soc_pcm_runtime *rtd;
1431 struct snd_pcm *pcm;
1432 char new_name[64];
1433 int ret = 0, playback = 0, capture = 0;
1435 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
1436 if (rtd == NULL)
1437 return -ENOMEM;
1439 rtd->dai = dai_link;
1440 rtd->socdev = socdev;
1441 codec_dai->codec = card->codec;
1443 /* check client and interface hw capabilities */
1444 snprintf(new_name, sizeof(new_name), "%s %s-%d",
1445 dai_link->stream_name, codec_dai->name, num);
1447 if (codec_dai->playback.channels_min)
1448 playback = 1;
1449 if (codec_dai->capture.channels_min)
1450 capture = 1;
1452 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
1453 capture, &pcm);
1454 if (ret < 0) {
1455 printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
1456 codec->name);
1457 kfree(rtd);
1458 return ret;
1461 dai_link->pcm = pcm;
1462 pcm->private_data = rtd;
1463 soc_pcm_ops.mmap = platform->pcm_ops->mmap;
1464 soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
1465 soc_pcm_ops.copy = platform->pcm_ops->copy;
1466 soc_pcm_ops.silence = platform->pcm_ops->silence;
1467 soc_pcm_ops.ack = platform->pcm_ops->ack;
1468 soc_pcm_ops.page = platform->pcm_ops->page;
1470 if (playback)
1471 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
1473 if (capture)
1474 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
1476 ret = platform->pcm_new(codec->card, codec_dai, pcm);
1477 if (ret < 0) {
1478 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
1479 kfree(rtd);
1480 return ret;
1483 pcm->private_free = platform->pcm_free;
1484 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
1485 cpu_dai->name);
1486 return ret;
1490 * snd_soc_codec_volatile_register: Report if a register is volatile.
1492 * @codec: CODEC to query.
1493 * @reg: Register to query.
1495 * Boolean function indiciating if a CODEC register is volatile.
1497 int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
1499 if (codec->volatile_register)
1500 return codec->volatile_register(reg);
1501 else
1502 return 0;
1504 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1507 * snd_soc_new_ac97_codec - initailise AC97 device
1508 * @codec: audio codec
1509 * @ops: AC97 bus operations
1510 * @num: AC97 codec number
1512 * Initialises AC97 codec resources for use by ad-hoc devices only.
1514 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1515 struct snd_ac97_bus_ops *ops, int num)
1517 mutex_lock(&codec->mutex);
1519 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1520 if (codec->ac97 == NULL) {
1521 mutex_unlock(&codec->mutex);
1522 return -ENOMEM;
1525 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1526 if (codec->ac97->bus == NULL) {
1527 kfree(codec->ac97);
1528 codec->ac97 = NULL;
1529 mutex_unlock(&codec->mutex);
1530 return -ENOMEM;
1533 codec->ac97->bus->ops = ops;
1534 codec->ac97->num = num;
1535 codec->dev = &codec->ac97->dev;
1536 mutex_unlock(&codec->mutex);
1537 return 0;
1539 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1542 * snd_soc_free_ac97_codec - free AC97 codec device
1543 * @codec: audio codec
1545 * Frees AC97 codec device resources.
1547 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1549 mutex_lock(&codec->mutex);
1550 kfree(codec->ac97->bus);
1551 kfree(codec->ac97);
1552 codec->ac97 = NULL;
1553 mutex_unlock(&codec->mutex);
1555 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1558 * snd_soc_update_bits - update codec register bits
1559 * @codec: audio codec
1560 * @reg: codec register
1561 * @mask: register mask
1562 * @value: new value
1564 * Writes new register value.
1566 * Returns 1 for change else 0.
1568 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1569 unsigned int mask, unsigned int value)
1571 int change;
1572 unsigned int old, new;
1574 old = snd_soc_read(codec, reg);
1575 new = (old & ~mask) | value;
1576 change = old != new;
1577 if (change)
1578 snd_soc_write(codec, reg, new);
1580 return change;
1582 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1585 * snd_soc_update_bits_locked - update codec register bits
1586 * @codec: audio codec
1587 * @reg: codec register
1588 * @mask: register mask
1589 * @value: new value
1591 * Writes new register value, and takes the codec mutex.
1593 * Returns 1 for change else 0.
1595 int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1596 unsigned short reg, unsigned int mask,
1597 unsigned int value)
1599 int change;
1601 mutex_lock(&codec->mutex);
1602 change = snd_soc_update_bits(codec, reg, mask, value);
1603 mutex_unlock(&codec->mutex);
1605 return change;
1607 EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
1610 * snd_soc_test_bits - test register for change
1611 * @codec: audio codec
1612 * @reg: codec register
1613 * @mask: register mask
1614 * @value: new value
1616 * Tests a register with a new value and checks if the new value is
1617 * different from the old value.
1619 * Returns 1 for change else 0.
1621 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1622 unsigned int mask, unsigned int value)
1624 int change;
1625 unsigned int old, new;
1627 old = snd_soc_read(codec, reg);
1628 new = (old & ~mask) | value;
1629 change = old != new;
1631 return change;
1633 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1636 * snd_soc_new_pcms - create new sound card and pcms
1637 * @socdev: the SoC audio device
1638 * @idx: ALSA card index
1639 * @xid: card identification
1641 * Create a new sound card based upon the codec and interface pcms.
1643 * Returns 0 for success, else error.
1645 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1647 struct snd_soc_card *card = socdev->card;
1648 struct snd_soc_codec *codec = card->codec;
1649 int ret, i;
1651 mutex_lock(&codec->mutex);
1653 /* register a sound card */
1654 ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
1655 if (ret < 0) {
1656 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1657 codec->name);
1658 mutex_unlock(&codec->mutex);
1659 return ret;
1662 codec->socdev = socdev;
1663 codec->card->dev = socdev->dev;
1664 codec->card->private_data = codec;
1665 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1667 /* create the pcms */
1668 for (i = 0; i < card->num_links; i++) {
1669 ret = soc_new_pcm(socdev, &card->dai_link[i], i);
1670 if (ret < 0) {
1671 printk(KERN_ERR "asoc: can't create pcm %s\n",
1672 card->dai_link[i].stream_name);
1673 mutex_unlock(&codec->mutex);
1674 return ret;
1676 /* Check for codec->ac97 to handle the ac97.c fun */
1677 if (card->dai_link[i].codec_dai->ac97_control && codec->ac97) {
1678 snd_ac97_dev_add_pdata(codec->ac97,
1679 card->dai_link[i].cpu_dai->ac97_pdata);
1683 mutex_unlock(&codec->mutex);
1684 return ret;
1686 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1689 * snd_soc_free_pcms - free sound card and pcms
1690 * @socdev: the SoC audio device
1692 * Frees sound card and pcms associated with the socdev.
1693 * Also unregister the codec if it is an AC97 device.
1695 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1697 struct snd_soc_codec *codec = socdev->card->codec;
1698 #ifdef CONFIG_SND_SOC_AC97_BUS
1699 struct snd_soc_dai *codec_dai;
1700 int i;
1701 #endif
1703 mutex_lock(&codec->mutex);
1704 soc_cleanup_codec_debugfs(codec);
1705 #ifdef CONFIG_SND_SOC_AC97_BUS
1706 for (i = 0; i < codec->num_dai; i++) {
1707 codec_dai = &codec->dai[i];
1708 if (codec_dai->ac97_control && codec->ac97 &&
1709 strcmp(codec->name, "AC97") != 0) {
1710 soc_ac97_dev_unregister(codec);
1711 goto free_card;
1714 free_card:
1715 #endif
1717 if (codec->card)
1718 snd_card_free(codec->card);
1719 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1720 mutex_unlock(&codec->mutex);
1722 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1725 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1726 * @substream: the pcm substream
1727 * @hw: the hardware parameters
1729 * Sets the substream runtime hardware parameters.
1731 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1732 const struct snd_pcm_hardware *hw)
1734 struct snd_pcm_runtime *runtime = substream->runtime;
1735 runtime->hw.info = hw->info;
1736 runtime->hw.formats = hw->formats;
1737 runtime->hw.period_bytes_min = hw->period_bytes_min;
1738 runtime->hw.period_bytes_max = hw->period_bytes_max;
1739 runtime->hw.periods_min = hw->periods_min;
1740 runtime->hw.periods_max = hw->periods_max;
1741 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1742 runtime->hw.fifo_size = hw->fifo_size;
1743 return 0;
1745 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1748 * snd_soc_cnew - create new control
1749 * @_template: control template
1750 * @data: control private data
1751 * @long_name: control long name
1753 * Create a new mixer control from a template control.
1755 * Returns 0 for success, else error.
1757 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1758 void *data, char *long_name)
1760 struct snd_kcontrol_new template;
1762 memcpy(&template, _template, sizeof(template));
1763 if (long_name)
1764 template.name = long_name;
1765 template.index = 0;
1767 return snd_ctl_new1(&template, data);
1769 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1772 * snd_soc_add_controls - add an array of controls to a codec.
1773 * Convienience function to add a list of controls. Many codecs were
1774 * duplicating this code.
1776 * @codec: codec to add controls to
1777 * @controls: array of controls to add
1778 * @num_controls: number of elements in the array
1780 * Return 0 for success, else error.
1782 int snd_soc_add_controls(struct snd_soc_codec *codec,
1783 const struct snd_kcontrol_new *controls, int num_controls)
1785 struct snd_card *card = codec->card;
1786 int err, i;
1788 for (i = 0; i < num_controls; i++) {
1789 const struct snd_kcontrol_new *control = &controls[i];
1790 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
1791 if (err < 0) {
1792 dev_err(codec->dev, "%s: Failed to add %s\n",
1793 codec->name, control->name);
1794 return err;
1798 return 0;
1800 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
1803 * snd_soc_info_enum_double - enumerated double mixer info callback
1804 * @kcontrol: mixer control
1805 * @uinfo: control element information
1807 * Callback to provide information about a double enumerated
1808 * mixer control.
1810 * Returns 0 for success.
1812 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1813 struct snd_ctl_elem_info *uinfo)
1815 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1817 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1818 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1819 uinfo->value.enumerated.items = e->max;
1821 if (uinfo->value.enumerated.item > e->max - 1)
1822 uinfo->value.enumerated.item = e->max - 1;
1823 strcpy(uinfo->value.enumerated.name,
1824 e->texts[uinfo->value.enumerated.item]);
1825 return 0;
1827 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1830 * snd_soc_get_enum_double - enumerated double mixer get callback
1831 * @kcontrol: mixer control
1832 * @ucontrol: control element information
1834 * Callback to get the value of a double enumerated mixer.
1836 * Returns 0 for success.
1838 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1839 struct snd_ctl_elem_value *ucontrol)
1841 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1842 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1843 unsigned int val, bitmask;
1845 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1847 val = snd_soc_read(codec, e->reg);
1848 ucontrol->value.enumerated.item[0]
1849 = (val >> e->shift_l) & (bitmask - 1);
1850 if (e->shift_l != e->shift_r)
1851 ucontrol->value.enumerated.item[1] =
1852 (val >> e->shift_r) & (bitmask - 1);
1854 return 0;
1856 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1859 * snd_soc_put_enum_double - enumerated double mixer put callback
1860 * @kcontrol: mixer control
1861 * @ucontrol: control element information
1863 * Callback to set the value of a double enumerated mixer.
1865 * Returns 0 for success.
1867 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1868 struct snd_ctl_elem_value *ucontrol)
1870 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1871 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1872 unsigned int val;
1873 unsigned int mask, bitmask;
1875 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1877 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1878 return -EINVAL;
1879 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1880 mask = (bitmask - 1) << e->shift_l;
1881 if (e->shift_l != e->shift_r) {
1882 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1883 return -EINVAL;
1884 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1885 mask |= (bitmask - 1) << e->shift_r;
1888 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
1890 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1893 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
1894 * @kcontrol: mixer control
1895 * @ucontrol: control element information
1897 * Callback to get the value of a double semi enumerated mixer.
1899 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1900 * used for handling bitfield coded enumeration for example.
1902 * Returns 0 for success.
1904 int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
1905 struct snd_ctl_elem_value *ucontrol)
1907 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1908 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1909 unsigned int reg_val, val, mux;
1911 reg_val = snd_soc_read(codec, e->reg);
1912 val = (reg_val >> e->shift_l) & e->mask;
1913 for (mux = 0; mux < e->max; mux++) {
1914 if (val == e->values[mux])
1915 break;
1917 ucontrol->value.enumerated.item[0] = mux;
1918 if (e->shift_l != e->shift_r) {
1919 val = (reg_val >> e->shift_r) & e->mask;
1920 for (mux = 0; mux < e->max; mux++) {
1921 if (val == e->values[mux])
1922 break;
1924 ucontrol->value.enumerated.item[1] = mux;
1927 return 0;
1929 EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
1932 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
1933 * @kcontrol: mixer control
1934 * @ucontrol: control element information
1936 * Callback to set the value of a double semi enumerated mixer.
1938 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1939 * used for handling bitfield coded enumeration for example.
1941 * Returns 0 for success.
1943 int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
1944 struct snd_ctl_elem_value *ucontrol)
1946 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1947 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1948 unsigned int val;
1949 unsigned int mask;
1951 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1952 return -EINVAL;
1953 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1954 mask = e->mask << e->shift_l;
1955 if (e->shift_l != e->shift_r) {
1956 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1957 return -EINVAL;
1958 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1959 mask |= e->mask << e->shift_r;
1962 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
1964 EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
1967 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1968 * @kcontrol: mixer control
1969 * @uinfo: control element information
1971 * Callback to provide information about an external enumerated
1972 * single mixer.
1974 * Returns 0 for success.
1976 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1977 struct snd_ctl_elem_info *uinfo)
1979 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1981 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1982 uinfo->count = 1;
1983 uinfo->value.enumerated.items = e->max;
1985 if (uinfo->value.enumerated.item > e->max - 1)
1986 uinfo->value.enumerated.item = e->max - 1;
1987 strcpy(uinfo->value.enumerated.name,
1988 e->texts[uinfo->value.enumerated.item]);
1989 return 0;
1991 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1994 * snd_soc_info_volsw_ext - external single mixer info callback
1995 * @kcontrol: mixer control
1996 * @uinfo: control element information
1998 * Callback to provide information about a single external mixer control.
2000 * Returns 0 for success.
2002 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_info *uinfo)
2005 int max = kcontrol->private_value;
2007 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
2008 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2009 else
2010 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2012 uinfo->count = 1;
2013 uinfo->value.integer.min = 0;
2014 uinfo->value.integer.max = max;
2015 return 0;
2017 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2020 * snd_soc_info_volsw - single mixer info callback
2021 * @kcontrol: mixer control
2022 * @uinfo: control element information
2024 * Callback to provide information about a single mixer control.
2026 * Returns 0 for success.
2028 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2029 struct snd_ctl_elem_info *uinfo)
2031 struct soc_mixer_control *mc =
2032 (struct soc_mixer_control *)kcontrol->private_value;
2033 int platform_max;
2034 unsigned int shift = mc->shift;
2035 unsigned int rshift = mc->rshift;
2037 if (!mc->platform_max)
2038 mc->platform_max = mc->max;
2039 platform_max = mc->platform_max;
2041 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2042 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2043 else
2044 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2046 uinfo->count = shift == rshift ? 1 : 2;
2047 uinfo->value.integer.min = 0;
2048 uinfo->value.integer.max = platform_max;
2049 return 0;
2051 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2054 * snd_soc_get_volsw - single mixer get callback
2055 * @kcontrol: mixer control
2056 * @ucontrol: control element information
2058 * Callback to get the value of a single mixer control.
2060 * Returns 0 for success.
2062 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2063 struct snd_ctl_elem_value *ucontrol)
2065 struct soc_mixer_control *mc =
2066 (struct soc_mixer_control *)kcontrol->private_value;
2067 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2068 unsigned int reg = mc->reg;
2069 unsigned int shift = mc->shift;
2070 unsigned int rshift = mc->rshift;
2071 int max = mc->max;
2072 unsigned int mask = (1 << fls(max)) - 1;
2073 unsigned int invert = mc->invert;
2075 ucontrol->value.integer.value[0] =
2076 (snd_soc_read(codec, reg) >> shift) & mask;
2077 if (shift != rshift)
2078 ucontrol->value.integer.value[1] =
2079 (snd_soc_read(codec, reg) >> rshift) & mask;
2080 if (invert) {
2081 ucontrol->value.integer.value[0] =
2082 max - ucontrol->value.integer.value[0];
2083 if (shift != rshift)
2084 ucontrol->value.integer.value[1] =
2085 max - ucontrol->value.integer.value[1];
2088 return 0;
2090 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2093 * snd_soc_put_volsw - single mixer put callback
2094 * @kcontrol: mixer control
2095 * @ucontrol: control element information
2097 * Callback to set the value of a single mixer control.
2099 * Returns 0 for success.
2101 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2102 struct snd_ctl_elem_value *ucontrol)
2104 struct soc_mixer_control *mc =
2105 (struct soc_mixer_control *)kcontrol->private_value;
2106 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2107 unsigned int reg = mc->reg;
2108 unsigned int shift = mc->shift;
2109 unsigned int rshift = mc->rshift;
2110 int max = mc->max;
2111 unsigned int mask = (1 << fls(max)) - 1;
2112 unsigned int invert = mc->invert;
2113 unsigned int val, val2, val_mask;
2115 val = (ucontrol->value.integer.value[0] & mask);
2116 if (invert)
2117 val = max - val;
2118 val_mask = mask << shift;
2119 val = val << shift;
2120 if (shift != rshift) {
2121 val2 = (ucontrol->value.integer.value[1] & mask);
2122 if (invert)
2123 val2 = max - val2;
2124 val_mask |= mask << rshift;
2125 val |= val2 << rshift;
2127 return snd_soc_update_bits_locked(codec, reg, val_mask, val);
2129 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2132 * snd_soc_info_volsw_2r - double mixer info callback
2133 * @kcontrol: mixer control
2134 * @uinfo: control element information
2136 * Callback to provide information about a double mixer control that
2137 * spans 2 codec registers.
2139 * Returns 0 for success.
2141 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_info *uinfo)
2144 struct soc_mixer_control *mc =
2145 (struct soc_mixer_control *)kcontrol->private_value;
2146 int platform_max;
2148 if (!mc->platform_max)
2149 mc->platform_max = mc->max;
2150 platform_max = mc->platform_max;
2152 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
2153 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2154 else
2155 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2157 uinfo->count = 2;
2158 uinfo->value.integer.min = 0;
2159 uinfo->value.integer.max = platform_max;
2160 return 0;
2162 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
2165 * snd_soc_get_volsw_2r - double mixer get callback
2166 * @kcontrol: mixer control
2167 * @ucontrol: control element information
2169 * Callback to get the value of a double mixer control that spans 2 registers.
2171 * Returns 0 for success.
2173 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
2174 struct snd_ctl_elem_value *ucontrol)
2176 struct soc_mixer_control *mc =
2177 (struct soc_mixer_control *)kcontrol->private_value;
2178 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2179 unsigned int reg = mc->reg;
2180 unsigned int reg2 = mc->rreg;
2181 unsigned int shift = mc->shift;
2182 int max = mc->max;
2183 unsigned int mask = (1 << fls(max)) - 1;
2184 unsigned int invert = mc->invert;
2186 ucontrol->value.integer.value[0] =
2187 (snd_soc_read(codec, reg) >> shift) & mask;
2188 ucontrol->value.integer.value[1] =
2189 (snd_soc_read(codec, reg2) >> shift) & mask;
2190 if (invert) {
2191 ucontrol->value.integer.value[0] =
2192 max - ucontrol->value.integer.value[0];
2193 ucontrol->value.integer.value[1] =
2194 max - ucontrol->value.integer.value[1];
2197 return 0;
2199 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
2202 * snd_soc_put_volsw_2r - double mixer set callback
2203 * @kcontrol: mixer control
2204 * @ucontrol: control element information
2206 * Callback to set the value of a double mixer control that spans 2 registers.
2208 * Returns 0 for success.
2210 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_value *ucontrol)
2213 struct soc_mixer_control *mc =
2214 (struct soc_mixer_control *)kcontrol->private_value;
2215 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2216 unsigned int reg = mc->reg;
2217 unsigned int reg2 = mc->rreg;
2218 unsigned int shift = mc->shift;
2219 int max = mc->max;
2220 unsigned int mask = (1 << fls(max)) - 1;
2221 unsigned int invert = mc->invert;
2222 int err;
2223 unsigned int val, val2, val_mask;
2225 val_mask = mask << shift;
2226 val = (ucontrol->value.integer.value[0] & mask);
2227 val2 = (ucontrol->value.integer.value[1] & mask);
2229 if (invert) {
2230 val = max - val;
2231 val2 = max - val2;
2234 val = val << shift;
2235 val2 = val2 << shift;
2237 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2238 if (err < 0)
2239 return err;
2241 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2242 return err;
2244 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
2247 * snd_soc_info_volsw_s8 - signed mixer info callback
2248 * @kcontrol: mixer control
2249 * @uinfo: control element information
2251 * Callback to provide information about a signed mixer control.
2253 * Returns 0 for success.
2255 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2256 struct snd_ctl_elem_info *uinfo)
2258 struct soc_mixer_control *mc =
2259 (struct soc_mixer_control *)kcontrol->private_value;
2260 int platform_max;
2261 int min = mc->min;
2263 if (!mc->platform_max)
2264 mc->platform_max = mc->max;
2265 platform_max = mc->platform_max;
2267 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2268 uinfo->count = 2;
2269 uinfo->value.integer.min = 0;
2270 uinfo->value.integer.max = platform_max - min;
2271 return 0;
2273 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2276 * snd_soc_get_volsw_s8 - signed mixer get callback
2277 * @kcontrol: mixer control
2278 * @ucontrol: control element information
2280 * Callback to get the value of a signed mixer control.
2282 * Returns 0 for success.
2284 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2285 struct snd_ctl_elem_value *ucontrol)
2287 struct soc_mixer_control *mc =
2288 (struct soc_mixer_control *)kcontrol->private_value;
2289 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2290 unsigned int reg = mc->reg;
2291 int min = mc->min;
2292 int val = snd_soc_read(codec, reg);
2294 ucontrol->value.integer.value[0] =
2295 ((signed char)(val & 0xff))-min;
2296 ucontrol->value.integer.value[1] =
2297 ((signed char)((val >> 8) & 0xff))-min;
2298 return 0;
2300 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2303 * snd_soc_put_volsw_sgn - signed mixer put callback
2304 * @kcontrol: mixer control
2305 * @ucontrol: control element information
2307 * Callback to set the value of a signed mixer control.
2309 * Returns 0 for success.
2311 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2312 struct snd_ctl_elem_value *ucontrol)
2314 struct soc_mixer_control *mc =
2315 (struct soc_mixer_control *)kcontrol->private_value;
2316 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2317 unsigned int reg = mc->reg;
2318 int min = mc->min;
2319 unsigned int val;
2321 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2322 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2324 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
2326 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2329 * snd_soc_limit_volume - Set new limit to an existing volume control.
2331 * @codec: where to look for the control
2332 * @name: Name of the control
2333 * @max: new maximum limit
2335 * Return 0 for success, else error.
2337 int snd_soc_limit_volume(struct snd_soc_codec *codec,
2338 const char *name, int max)
2340 struct snd_card *card = codec->card;
2341 struct snd_kcontrol *kctl;
2342 struct soc_mixer_control *mc;
2343 int found = 0;
2344 int ret = -EINVAL;
2346 /* Sanity check for name and max */
2347 if (unlikely(!name || max <= 0))
2348 return -EINVAL;
2350 list_for_each_entry(kctl, &card->controls, list) {
2351 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2352 found = 1;
2353 break;
2356 if (found) {
2357 mc = (struct soc_mixer_control *)kctl->private_value;
2358 if (max <= mc->max) {
2359 mc->platform_max = max;
2360 ret = 0;
2363 return ret;
2365 EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2368 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2369 * mixer info callback
2370 * @kcontrol: mixer control
2371 * @uinfo: control element information
2373 * Returns 0 for success.
2375 int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2376 struct snd_ctl_elem_info *uinfo)
2378 struct soc_mixer_control *mc =
2379 (struct soc_mixer_control *)kcontrol->private_value;
2380 int max = mc->max;
2381 int min = mc->min;
2383 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2384 uinfo->count = 2;
2385 uinfo->value.integer.min = 0;
2386 uinfo->value.integer.max = max-min;
2388 return 0;
2390 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2393 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2394 * mixer get callback
2395 * @kcontrol: mixer control
2396 * @uinfo: control element information
2398 * Returns 0 for success.
2400 int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2401 struct snd_ctl_elem_value *ucontrol)
2403 struct soc_mixer_control *mc =
2404 (struct soc_mixer_control *)kcontrol->private_value;
2405 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2406 unsigned int mask = (1<<mc->shift)-1;
2407 int min = mc->min;
2408 int val = snd_soc_read(codec, mc->reg) & mask;
2409 int valr = snd_soc_read(codec, mc->rreg) & mask;
2411 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2412 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
2413 return 0;
2415 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2418 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2419 * mixer put callback
2420 * @kcontrol: mixer control
2421 * @uinfo: control element information
2423 * Returns 0 for success.
2425 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2426 struct snd_ctl_elem_value *ucontrol)
2428 struct soc_mixer_control *mc =
2429 (struct soc_mixer_control *)kcontrol->private_value;
2430 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2431 unsigned int mask = (1<<mc->shift)-1;
2432 int min = mc->min;
2433 int ret;
2434 unsigned int val, valr, oval, ovalr;
2436 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2437 val &= mask;
2438 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2439 valr &= mask;
2441 oval = snd_soc_read(codec, mc->reg) & mask;
2442 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2444 ret = 0;
2445 if (oval != val) {
2446 ret = snd_soc_write(codec, mc->reg, val);
2447 if (ret < 0)
2448 return ret;
2450 if (ovalr != valr) {
2451 ret = snd_soc_write(codec, mc->rreg, valr);
2452 if (ret < 0)
2453 return ret;
2456 return 0;
2458 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2461 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2462 * @dai: DAI
2463 * @clk_id: DAI specific clock ID
2464 * @freq: new clock frequency in Hz
2465 * @dir: new clock direction - input/output.
2467 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2469 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2470 unsigned int freq, int dir)
2472 if (dai->ops && dai->ops->set_sysclk)
2473 return dai->ops->set_sysclk(dai, clk_id, freq, dir);
2474 else
2475 return -EINVAL;
2477 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2480 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2481 * @dai: DAI
2482 * @div_id: DAI specific clock divider ID
2483 * @div: new clock divisor.
2485 * Configures the clock dividers. This is used to derive the best DAI bit and
2486 * frame clocks from the system or master clock. It's best to set the DAI bit
2487 * and frame clocks as low as possible to save system power.
2489 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2490 int div_id, int div)
2492 if (dai->ops && dai->ops->set_clkdiv)
2493 return dai->ops->set_clkdiv(dai, div_id, div);
2494 else
2495 return -EINVAL;
2497 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2500 * snd_soc_dai_set_pll - configure DAI PLL.
2501 * @dai: DAI
2502 * @pll_id: DAI specific PLL ID
2503 * @source: DAI specific source for the PLL
2504 * @freq_in: PLL input clock frequency in Hz
2505 * @freq_out: requested PLL output clock frequency in Hz
2507 * Configures and enables PLL to generate output clock based on input clock.
2509 int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2510 unsigned int freq_in, unsigned int freq_out)
2512 if (dai->ops && dai->ops->set_pll)
2513 return dai->ops->set_pll(dai, pll_id, source,
2514 freq_in, freq_out);
2515 else
2516 return -EINVAL;
2518 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2521 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2522 * @dai: DAI
2523 * @fmt: SND_SOC_DAIFMT_ format value.
2525 * Configures the DAI hardware format and clocking.
2527 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2529 if (dai->ops && dai->ops->set_fmt)
2530 return dai->ops->set_fmt(dai, fmt);
2531 else
2532 return -EINVAL;
2534 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2537 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2538 * @dai: DAI
2539 * @tx_mask: bitmask representing active TX slots.
2540 * @rx_mask: bitmask representing active RX slots.
2541 * @slots: Number of slots in use.
2542 * @slot_width: Width in bits for each slot.
2544 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2545 * specific.
2547 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2548 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2550 if (dai->ops && dai->ops->set_tdm_slot)
2551 return dai->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2552 slots, slot_width);
2553 else
2554 return -EINVAL;
2556 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2559 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2560 * @dai: DAI
2561 * @tx_num: how many TX channels
2562 * @tx_slot: pointer to an array which imply the TX slot number channel
2563 * 0~num-1 uses
2564 * @rx_num: how many RX channels
2565 * @rx_slot: pointer to an array which imply the RX slot number channel
2566 * 0~num-1 uses
2568 * configure the relationship between channel number and TDM slot number.
2570 int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2571 unsigned int tx_num, unsigned int *tx_slot,
2572 unsigned int rx_num, unsigned int *rx_slot)
2574 if (dai->ops && dai->ops->set_channel_map)
2575 return dai->ops->set_channel_map(dai, tx_num, tx_slot,
2576 rx_num, rx_slot);
2577 else
2578 return -EINVAL;
2580 EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2583 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2584 * @dai: DAI
2585 * @tristate: tristate enable
2587 * Tristates the DAI so that others can use it.
2589 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2591 if (dai->ops && dai->ops->set_tristate)
2592 return dai->ops->set_tristate(dai, tristate);
2593 else
2594 return -EINVAL;
2596 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2599 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2600 * @dai: DAI
2601 * @mute: mute enable
2603 * Mutes the DAI DAC.
2605 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2607 if (dai->ops && dai->ops->digital_mute)
2608 return dai->ops->digital_mute(dai, mute);
2609 else
2610 return -EINVAL;
2612 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2615 * snd_soc_register_card - Register a card with the ASoC core
2617 * @card: Card to register
2619 * Note that currently this is an internal only function: it will be
2620 * exposed to machine drivers after further backporting of ASoC v2
2621 * registration APIs.
2623 static int snd_soc_register_card(struct snd_soc_card *card)
2625 if (!card->name || !card->dev)
2626 return -EINVAL;
2628 INIT_LIST_HEAD(&card->list);
2629 card->instantiated = 0;
2631 mutex_lock(&client_mutex);
2632 list_add(&card->list, &card_list);
2633 snd_soc_instantiate_cards();
2634 mutex_unlock(&client_mutex);
2636 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2638 return 0;
2642 * snd_soc_unregister_card - Unregister a card with the ASoC core
2644 * @card: Card to unregister
2646 * Note that currently this is an internal only function: it will be
2647 * exposed to machine drivers after further backporting of ASoC v2
2648 * registration APIs.
2650 static int snd_soc_unregister_card(struct snd_soc_card *card)
2652 mutex_lock(&client_mutex);
2653 list_del(&card->list);
2654 mutex_unlock(&client_mutex);
2656 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2658 return 0;
2662 * snd_soc_register_dai - Register a DAI with the ASoC core
2664 * @dai: DAI to register
2666 int snd_soc_register_dai(struct snd_soc_dai *dai)
2668 if (!dai->name)
2669 return -EINVAL;
2671 /* The device should become mandatory over time */
2672 if (!dai->dev)
2673 printk(KERN_WARNING "No device for DAI %s\n", dai->name);
2675 if (!dai->ops)
2676 dai->ops = &null_dai_ops;
2678 INIT_LIST_HEAD(&dai->list);
2680 mutex_lock(&client_mutex);
2681 list_add(&dai->list, &dai_list);
2682 snd_soc_instantiate_cards();
2683 mutex_unlock(&client_mutex);
2685 pr_debug("Registered DAI '%s'\n", dai->name);
2687 return 0;
2689 EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2692 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2694 * @dai: DAI to unregister
2696 void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2698 mutex_lock(&client_mutex);
2699 list_del(&dai->list);
2700 mutex_unlock(&client_mutex);
2702 pr_debug("Unregistered DAI '%s'\n", dai->name);
2704 EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2707 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
2709 * @dai: Array of DAIs to register
2710 * @count: Number of DAIs
2712 int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count)
2714 int i, ret;
2716 for (i = 0; i < count; i++) {
2717 ret = snd_soc_register_dai(&dai[i]);
2718 if (ret != 0)
2719 goto err;
2722 return 0;
2724 err:
2725 for (i--; i >= 0; i--)
2726 snd_soc_unregister_dai(&dai[i]);
2728 return ret;
2730 EXPORT_SYMBOL_GPL(snd_soc_register_dais);
2733 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
2735 * @dai: Array of DAIs to unregister
2736 * @count: Number of DAIs
2738 void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count)
2740 int i;
2742 for (i = 0; i < count; i++)
2743 snd_soc_unregister_dai(&dai[i]);
2745 EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
2748 * snd_soc_register_platform - Register a platform with the ASoC core
2750 * @platform: platform to register
2752 int snd_soc_register_platform(struct snd_soc_platform *platform)
2754 if (!platform->name)
2755 return -EINVAL;
2757 INIT_LIST_HEAD(&platform->list);
2759 mutex_lock(&client_mutex);
2760 list_add(&platform->list, &platform_list);
2761 snd_soc_instantiate_cards();
2762 mutex_unlock(&client_mutex);
2764 pr_debug("Registered platform '%s'\n", platform->name);
2766 return 0;
2768 EXPORT_SYMBOL_GPL(snd_soc_register_platform);
2771 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
2773 * @platform: platform to unregister
2775 void snd_soc_unregister_platform(struct snd_soc_platform *platform)
2777 mutex_lock(&client_mutex);
2778 list_del(&platform->list);
2779 mutex_unlock(&client_mutex);
2781 pr_debug("Unregistered platform '%s'\n", platform->name);
2783 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
2785 static u64 codec_format_map[] = {
2786 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
2787 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
2788 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
2789 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
2790 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
2791 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
2792 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2793 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2794 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
2795 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
2796 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
2797 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
2798 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
2799 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
2800 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
2801 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
2804 /* Fix up the DAI formats for endianness: codecs don't actually see
2805 * the endianness of the data but we're using the CPU format
2806 * definitions which do need to include endianness so we ensure that
2807 * codec DAIs always have both big and little endian variants set.
2809 static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
2811 int i;
2813 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
2814 if (stream->formats & codec_format_map[i])
2815 stream->formats |= codec_format_map[i];
2819 * snd_soc_register_codec - Register a codec with the ASoC core
2821 * @codec: codec to register
2823 int snd_soc_register_codec(struct snd_soc_codec *codec)
2825 int i;
2827 if (!codec->name)
2828 return -EINVAL;
2830 /* The device should become mandatory over time */
2831 if (!codec->dev)
2832 printk(KERN_WARNING "No device for codec %s\n", codec->name);
2834 INIT_LIST_HEAD(&codec->list);
2836 for (i = 0; i < codec->num_dai; i++) {
2837 fixup_codec_formats(&codec->dai[i].playback);
2838 fixup_codec_formats(&codec->dai[i].capture);
2841 mutex_lock(&client_mutex);
2842 list_add(&codec->list, &codec_list);
2843 snd_soc_instantiate_cards();
2844 mutex_unlock(&client_mutex);
2846 pr_debug("Registered codec '%s'\n", codec->name);
2848 return 0;
2850 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
2853 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
2855 * @codec: codec to unregister
2857 void snd_soc_unregister_codec(struct snd_soc_codec *codec)
2859 mutex_lock(&client_mutex);
2860 list_del(&codec->list);
2861 mutex_unlock(&client_mutex);
2863 pr_debug("Unregistered codec '%s'\n", codec->name);
2865 EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
2867 static int __init snd_soc_init(void)
2869 #ifdef CONFIG_DEBUG_FS
2870 debugfs_root = debugfs_create_dir("asoc", NULL);
2871 if (IS_ERR(debugfs_root) || !debugfs_root) {
2872 printk(KERN_WARNING
2873 "ASoC: Failed to create debugfs directory\n");
2874 debugfs_root = NULL;
2876 #endif
2878 return platform_driver_register(&soc_driver);
2881 static void __exit snd_soc_exit(void)
2883 #ifdef CONFIG_DEBUG_FS
2884 debugfs_remove_recursive(debugfs_root);
2885 #endif
2886 platform_driver_unregister(&soc_driver);
2889 module_init(snd_soc_init);
2890 module_exit(snd_soc_exit);
2892 /* Module information */
2893 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
2894 MODULE_DESCRIPTION("ALSA SoC Core");
2895 MODULE_LICENSE("GPL");
2896 MODULE_ALIAS("platform:soc-audio");