9feaa7b6dc348ca9701267abee09d5116b27bfaf
[safe/jmp/linux-2.6] / sound / soc / soc-core.c
1 /*
2  * soc-core.c  --  ALSA SoC Audio Layer
3  *
4  * Copyright 2005 Wolfson Microelectronics PLC.
5  * Copyright 2005 Openedhand Ltd.
6  *
7  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8  *         with code, comments and ideas from :-
9  *         Richard Purdie <richard@openedhand.com>
10  *
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.
15  *
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
21  */
22
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 <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>
37
38 static DEFINE_MUTEX(pcm_mutex);
39 static DEFINE_MUTEX(io_mutex);
40 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
41
42 /*
43  * This is a timeout to do a DAPM powerdown after a stream is closed().
44  * It can be used to eliminate pops between different playback streams, e.g.
45  * between two audio tracks.
46  */
47 static int pmdown_time = 5000;
48 module_param(pmdown_time, int, 0);
49 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
50
51 /*
52  * This function forces any delayed work to be queued and run.
53  */
54 static int run_delayed_work(struct delayed_work *dwork)
55 {
56         int ret;
57
58         /* cancel any work waiting to be queued. */
59         ret = cancel_delayed_work(dwork);
60
61         /* if there was any work waiting then we run it now and
62          * wait for it's completion */
63         if (ret) {
64                 schedule_delayed_work(dwork, 0);
65                 flush_scheduled_work();
66         }
67         return ret;
68 }
69
70 #ifdef CONFIG_SND_SOC_AC97_BUS
71 /* unregister ac97 codec */
72 static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
73 {
74         if (codec->ac97->dev.bus)
75                 device_unregister(&codec->ac97->dev);
76         return 0;
77 }
78
79 /* stop no dev release warning */
80 static void soc_ac97_device_release(struct device *dev){}
81
82 /* register ac97 codec to bus */
83 static int soc_ac97_dev_register(struct snd_soc_codec *codec)
84 {
85         int err;
86
87         codec->ac97->dev.bus = &ac97_bus_type;
88         codec->ac97->dev.parent = NULL;
89         codec->ac97->dev.release = soc_ac97_device_release;
90
91         snprintf(codec->ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
92                  codec->card->number, 0, codec->name);
93         err = device_register(&codec->ac97->dev);
94         if (err < 0) {
95                 snd_printk(KERN_ERR "Can't register ac97 bus\n");
96                 codec->ac97->dev.bus = NULL;
97                 return err;
98         }
99         return 0;
100 }
101 #endif
102
103 static inline const char *get_dai_name(int type)
104 {
105         switch (type) {
106         case SND_SOC_DAI_AC97_BUS:
107         case SND_SOC_DAI_AC97:
108                 return "AC97";
109         case SND_SOC_DAI_I2S:
110                 return "I2S";
111         case SND_SOC_DAI_PCM:
112                 return "PCM";
113         }
114         return NULL;
115 }
116
117 /*
118  * Called by ALSA when a PCM substream is opened, the runtime->hw record is
119  * then initialized and any private data can be allocated. This also calls
120  * startup for the cpu DAI, platform, machine and codec DAI.
121  */
122 static int soc_pcm_open(struct snd_pcm_substream *substream)
123 {
124         struct snd_soc_pcm_runtime *rtd = substream->private_data;
125         struct snd_soc_device *socdev = rtd->socdev;
126         struct snd_pcm_runtime *runtime = substream->runtime;
127         struct snd_soc_dai_link *machine = rtd->dai;
128         struct snd_soc_platform *platform = socdev->platform;
129         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
130         struct snd_soc_dai *codec_dai = machine->codec_dai;
131         int ret = 0;
132
133         mutex_lock(&pcm_mutex);
134
135         /* startup the audio subsystem */
136         if (cpu_dai->ops.startup) {
137                 ret = cpu_dai->ops.startup(substream);
138                 if (ret < 0) {
139                         printk(KERN_ERR "asoc: can't open interface %s\n",
140                                 cpu_dai->name);
141                         goto out;
142                 }
143         }
144
145         if (platform->pcm_ops->open) {
146                 ret = platform->pcm_ops->open(substream);
147                 if (ret < 0) {
148                         printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
149                         goto platform_err;
150                 }
151         }
152
153         if (codec_dai->ops.startup) {
154                 ret = codec_dai->ops.startup(substream);
155                 if (ret < 0) {
156                         printk(KERN_ERR "asoc: can't open codec %s\n",
157                                 codec_dai->name);
158                         goto codec_dai_err;
159                 }
160         }
161
162         if (machine->ops && machine->ops->startup) {
163                 ret = machine->ops->startup(substream);
164                 if (ret < 0) {
165                         printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
166                         goto machine_err;
167                 }
168         }
169
170         /* Check that the codec and cpu DAI's are compatible */
171         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
172                 runtime->hw.rate_min =
173                         max(codec_dai->playback.rate_min,
174                             cpu_dai->playback.rate_min);
175                 runtime->hw.rate_max =
176                         min(codec_dai->playback.rate_max,
177                             cpu_dai->playback.rate_max);
178                 runtime->hw.channels_min =
179                         max(codec_dai->playback.channels_min,
180                                 cpu_dai->playback.channels_min);
181                 runtime->hw.channels_max =
182                         min(codec_dai->playback.channels_max,
183                                 cpu_dai->playback.channels_max);
184                 runtime->hw.formats =
185                         codec_dai->playback.formats & cpu_dai->playback.formats;
186                 runtime->hw.rates =
187                         codec_dai->playback.rates & cpu_dai->playback.rates;
188         } else {
189                 runtime->hw.rate_min =
190                         max(codec_dai->capture.rate_min,
191                             cpu_dai->capture.rate_min);
192                 runtime->hw.rate_max =
193                         min(codec_dai->capture.rate_max,
194                             cpu_dai->capture.rate_max);
195                 runtime->hw.channels_min =
196                         max(codec_dai->capture.channels_min,
197                                 cpu_dai->capture.channels_min);
198                 runtime->hw.channels_max =
199                         min(codec_dai->capture.channels_max,
200                                 cpu_dai->capture.channels_max);
201                 runtime->hw.formats =
202                         codec_dai->capture.formats & cpu_dai->capture.formats;
203                 runtime->hw.rates =
204                         codec_dai->capture.rates & cpu_dai->capture.rates;
205         }
206
207         snd_pcm_limit_hw_rates(runtime);
208         if (!runtime->hw.rates) {
209                 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
210                         codec_dai->name, cpu_dai->name);
211                 goto machine_err;
212         }
213         if (!runtime->hw.formats) {
214                 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
215                         codec_dai->name, cpu_dai->name);
216                 goto machine_err;
217         }
218         if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
219                 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
220                         codec_dai->name, cpu_dai->name);
221                 goto machine_err;
222         }
223
224         pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
225         pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
226         pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
227                  runtime->hw.channels_max);
228         pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
229                  runtime->hw.rate_max);
230
231         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
232                 cpu_dai->playback.active = codec_dai->playback.active = 1;
233         else
234                 cpu_dai->capture.active = codec_dai->capture.active = 1;
235         cpu_dai->active = codec_dai->active = 1;
236         cpu_dai->runtime = runtime;
237         socdev->codec->active++;
238         mutex_unlock(&pcm_mutex);
239         return 0;
240
241 machine_err:
242         if (machine->ops && machine->ops->shutdown)
243                 machine->ops->shutdown(substream);
244
245 codec_dai_err:
246         if (platform->pcm_ops->close)
247                 platform->pcm_ops->close(substream);
248
249 platform_err:
250         if (cpu_dai->ops.shutdown)
251                 cpu_dai->ops.shutdown(substream);
252 out:
253         mutex_unlock(&pcm_mutex);
254         return ret;
255 }
256
257 /*
258  * Power down the audio subsystem pmdown_time msecs after close is called.
259  * This is to ensure there are no pops or clicks in between any music tracks
260  * due to DAPM power cycling.
261  */
262 static void close_delayed_work(struct work_struct *work)
263 {
264         struct snd_soc_device *socdev =
265                 container_of(work, struct snd_soc_device, delayed_work.work);
266         struct snd_soc_codec *codec = socdev->codec;
267         struct snd_soc_dai *codec_dai;
268         int i;
269
270         mutex_lock(&pcm_mutex);
271         for (i = 0; i < codec->num_dai; i++) {
272                 codec_dai = &codec->dai[i];
273
274                 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
275                          codec_dai->playback.stream_name,
276                          codec_dai->playback.active ? "active" : "inactive",
277                          codec_dai->pop_wait ? "yes" : "no");
278
279                 /* are we waiting on this codec DAI stream */
280                 if (codec_dai->pop_wait == 1) {
281
282                         /* Reduce power if no longer active */
283                         if (codec->active == 0) {
284                                 pr_debug("pop wq D1 %s %s\n", codec->name,
285                                          codec_dai->playback.stream_name);
286                                 snd_soc_dapm_set_bias_level(socdev,
287                                         SND_SOC_BIAS_PREPARE);
288                         }
289
290                         codec_dai->pop_wait = 0;
291                         snd_soc_dapm_stream_event(codec,
292                                 codec_dai->playback.stream_name,
293                                 SND_SOC_DAPM_STREAM_STOP);
294
295                         /* Fall into standby if no longer active */
296                         if (codec->active == 0) {
297                                 pr_debug("pop wq D3 %s %s\n", codec->name,
298                                          codec_dai->playback.stream_name);
299                                 snd_soc_dapm_set_bias_level(socdev,
300                                         SND_SOC_BIAS_STANDBY);
301                         }
302                 }
303         }
304         mutex_unlock(&pcm_mutex);
305 }
306
307 /*
308  * Called by ALSA when a PCM substream is closed. Private data can be
309  * freed here. The cpu DAI, codec DAI, machine and platform are also
310  * shutdown.
311  */
312 static int soc_codec_close(struct snd_pcm_substream *substream)
313 {
314         struct snd_soc_pcm_runtime *rtd = substream->private_data;
315         struct snd_soc_device *socdev = rtd->socdev;
316         struct snd_soc_dai_link *machine = rtd->dai;
317         struct snd_soc_platform *platform = socdev->platform;
318         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
319         struct snd_soc_dai *codec_dai = machine->codec_dai;
320         struct snd_soc_codec *codec = socdev->codec;
321
322         mutex_lock(&pcm_mutex);
323
324         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
325                 cpu_dai->playback.active = codec_dai->playback.active = 0;
326         else
327                 cpu_dai->capture.active = codec_dai->capture.active = 0;
328
329         if (codec_dai->playback.active == 0 &&
330                 codec_dai->capture.active == 0) {
331                 cpu_dai->active = codec_dai->active = 0;
332         }
333         codec->active--;
334
335         /* Muting the DAC suppresses artifacts caused during digital
336          * shutdown, for example from stopping clocks.
337          */
338         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
339                 snd_soc_dai_digital_mute(codec_dai, 1);
340
341         if (cpu_dai->ops.shutdown)
342                 cpu_dai->ops.shutdown(substream);
343
344         if (codec_dai->ops.shutdown)
345                 codec_dai->ops.shutdown(substream);
346
347         if (machine->ops && machine->ops->shutdown)
348                 machine->ops->shutdown(substream);
349
350         if (platform->pcm_ops->close)
351                 platform->pcm_ops->close(substream);
352         cpu_dai->runtime = NULL;
353
354         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
355                 /* start delayed pop wq here for playback streams */
356                 codec_dai->pop_wait = 1;
357                 schedule_delayed_work(&socdev->delayed_work,
358                         msecs_to_jiffies(pmdown_time));
359         } else {
360                 /* capture streams can be powered down now */
361                 snd_soc_dapm_stream_event(codec,
362                         codec_dai->capture.stream_name,
363                         SND_SOC_DAPM_STREAM_STOP);
364
365                 if (codec->active == 0 && codec_dai->pop_wait == 0)
366                         snd_soc_dapm_set_bias_level(socdev,
367                                                 SND_SOC_BIAS_STANDBY);
368         }
369
370         mutex_unlock(&pcm_mutex);
371         return 0;
372 }
373
374 /*
375  * Called by ALSA when the PCM substream is prepared, can set format, sample
376  * rate, etc.  This function is non atomic and can be called multiple times,
377  * it can refer to the runtime info.
378  */
379 static int soc_pcm_prepare(struct snd_pcm_substream *substream)
380 {
381         struct snd_soc_pcm_runtime *rtd = substream->private_data;
382         struct snd_soc_device *socdev = rtd->socdev;
383         struct snd_soc_dai_link *machine = rtd->dai;
384         struct snd_soc_platform *platform = socdev->platform;
385         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
386         struct snd_soc_dai *codec_dai = machine->codec_dai;
387         struct snd_soc_codec *codec = socdev->codec;
388         int ret = 0;
389
390         mutex_lock(&pcm_mutex);
391
392         if (machine->ops && machine->ops->prepare) {
393                 ret = machine->ops->prepare(substream);
394                 if (ret < 0) {
395                         printk(KERN_ERR "asoc: machine prepare error\n");
396                         goto out;
397                 }
398         }
399
400         if (platform->pcm_ops->prepare) {
401                 ret = platform->pcm_ops->prepare(substream);
402                 if (ret < 0) {
403                         printk(KERN_ERR "asoc: platform prepare error\n");
404                         goto out;
405                 }
406         }
407
408         if (codec_dai->ops.prepare) {
409                 ret = codec_dai->ops.prepare(substream);
410                 if (ret < 0) {
411                         printk(KERN_ERR "asoc: codec DAI prepare error\n");
412                         goto out;
413                 }
414         }
415
416         if (cpu_dai->ops.prepare) {
417                 ret = cpu_dai->ops.prepare(substream);
418                 if (ret < 0) {
419                         printk(KERN_ERR "asoc: cpu DAI prepare error\n");
420                         goto out;
421                 }
422         }
423
424         /* cancel any delayed stream shutdown that is pending */
425         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
426             codec_dai->pop_wait) {
427                 codec_dai->pop_wait = 0;
428                 cancel_delayed_work(&socdev->delayed_work);
429         }
430
431         /* do we need to power up codec */
432         if (codec->bias_level != SND_SOC_BIAS_ON) {
433                 snd_soc_dapm_set_bias_level(socdev,
434                                             SND_SOC_BIAS_PREPARE);
435
436                 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
437                         snd_soc_dapm_stream_event(codec,
438                                         codec_dai->playback.stream_name,
439                                         SND_SOC_DAPM_STREAM_START);
440                 else
441                         snd_soc_dapm_stream_event(codec,
442                                         codec_dai->capture.stream_name,
443                                         SND_SOC_DAPM_STREAM_START);
444
445                 snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
446                 snd_soc_dai_digital_mute(codec_dai, 0);
447
448         } else {
449                 /* codec already powered - power on widgets */
450                 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
451                         snd_soc_dapm_stream_event(codec,
452                                         codec_dai->playback.stream_name,
453                                         SND_SOC_DAPM_STREAM_START);
454                 else
455                         snd_soc_dapm_stream_event(codec,
456                                         codec_dai->capture.stream_name,
457                                         SND_SOC_DAPM_STREAM_START);
458
459                 snd_soc_dai_digital_mute(codec_dai, 0);
460         }
461
462 out:
463         mutex_unlock(&pcm_mutex);
464         return ret;
465 }
466
467 /*
468  * Called by ALSA when the hardware params are set by application. This
469  * function can also be called multiple times and can allocate buffers
470  * (using snd_pcm_lib_* ). It's non-atomic.
471  */
472 static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
473                                 struct snd_pcm_hw_params *params)
474 {
475         struct snd_soc_pcm_runtime *rtd = substream->private_data;
476         struct snd_soc_device *socdev = rtd->socdev;
477         struct snd_soc_dai_link *machine = rtd->dai;
478         struct snd_soc_platform *platform = socdev->platform;
479         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
480         struct snd_soc_dai *codec_dai = machine->codec_dai;
481         int ret = 0;
482
483         mutex_lock(&pcm_mutex);
484
485         if (machine->ops && machine->ops->hw_params) {
486                 ret = machine->ops->hw_params(substream, params);
487                 if (ret < 0) {
488                         printk(KERN_ERR "asoc: machine hw_params failed\n");
489                         goto out;
490                 }
491         }
492
493         if (codec_dai->ops.hw_params) {
494                 ret = codec_dai->ops.hw_params(substream, params);
495                 if (ret < 0) {
496                         printk(KERN_ERR "asoc: can't set codec %s hw params\n",
497                                 codec_dai->name);
498                         goto codec_err;
499                 }
500         }
501
502         if (cpu_dai->ops.hw_params) {
503                 ret = cpu_dai->ops.hw_params(substream, params);
504                 if (ret < 0) {
505                         printk(KERN_ERR "asoc: interface %s hw params failed\n",
506                                 cpu_dai->name);
507                         goto interface_err;
508                 }
509         }
510
511         if (platform->pcm_ops->hw_params) {
512                 ret = platform->pcm_ops->hw_params(substream, params);
513                 if (ret < 0) {
514                         printk(KERN_ERR "asoc: platform %s hw params failed\n",
515                                 platform->name);
516                         goto platform_err;
517                 }
518         }
519
520 out:
521         mutex_unlock(&pcm_mutex);
522         return ret;
523
524 platform_err:
525         if (cpu_dai->ops.hw_free)
526                 cpu_dai->ops.hw_free(substream);
527
528 interface_err:
529         if (codec_dai->ops.hw_free)
530                 codec_dai->ops.hw_free(substream);
531
532 codec_err:
533         if (machine->ops && machine->ops->hw_free)
534                 machine->ops->hw_free(substream);
535
536         mutex_unlock(&pcm_mutex);
537         return ret;
538 }
539
540 /*
541  * Free's resources allocated by hw_params, can be called multiple times
542  */
543 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
544 {
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_platform *platform = socdev->platform;
549         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
550         struct snd_soc_dai *codec_dai = machine->codec_dai;
551         struct snd_soc_codec *codec = socdev->codec;
552
553         mutex_lock(&pcm_mutex);
554
555         /* apply codec digital mute */
556         if (!codec->active)
557                 snd_soc_dai_digital_mute(codec_dai, 1);
558
559         /* free any machine hw params */
560         if (machine->ops && machine->ops->hw_free)
561                 machine->ops->hw_free(substream);
562
563         /* free any DMA resources */
564         if (platform->pcm_ops->hw_free)
565                 platform->pcm_ops->hw_free(substream);
566
567         /* now free hw params for the DAI's  */
568         if (codec_dai->ops.hw_free)
569                 codec_dai->ops.hw_free(substream);
570
571         if (cpu_dai->ops.hw_free)
572                 cpu_dai->ops.hw_free(substream);
573
574         mutex_unlock(&pcm_mutex);
575         return 0;
576 }
577
578 static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
579 {
580         struct snd_soc_pcm_runtime *rtd = substream->private_data;
581         struct snd_soc_device *socdev = rtd->socdev;
582         struct snd_soc_dai_link *machine = rtd->dai;
583         struct snd_soc_platform *platform = socdev->platform;
584         struct snd_soc_dai *cpu_dai = machine->cpu_dai;
585         struct snd_soc_dai *codec_dai = machine->codec_dai;
586         int ret;
587
588         if (codec_dai->ops.trigger) {
589                 ret = codec_dai->ops.trigger(substream, cmd);
590                 if (ret < 0)
591                         return ret;
592         }
593
594         if (platform->pcm_ops->trigger) {
595                 ret = platform->pcm_ops->trigger(substream, cmd);
596                 if (ret < 0)
597                         return ret;
598         }
599
600         if (cpu_dai->ops.trigger) {
601                 ret = cpu_dai->ops.trigger(substream, cmd);
602                 if (ret < 0)
603                         return ret;
604         }
605         return 0;
606 }
607
608 /* ASoC PCM operations */
609 static struct snd_pcm_ops soc_pcm_ops = {
610         .open           = soc_pcm_open,
611         .close          = soc_codec_close,
612         .hw_params      = soc_pcm_hw_params,
613         .hw_free        = soc_pcm_hw_free,
614         .prepare        = soc_pcm_prepare,
615         .trigger        = soc_pcm_trigger,
616 };
617
618 #ifdef CONFIG_PM
619 /* powers down audio subsystem for suspend */
620 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
621 {
622         struct snd_soc_device *socdev = platform_get_drvdata(pdev);
623         struct snd_soc_machine *machine = socdev->machine;
624         struct snd_soc_platform *platform = socdev->platform;
625         struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
626         struct snd_soc_codec *codec = socdev->codec;
627         int i;
628
629         /* Due to the resume being scheduled into a workqueue we could
630         * suspend before that's finished - wait for it to complete.
631          */
632         snd_power_lock(codec->card);
633         snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
634         snd_power_unlock(codec->card);
635
636         /* we're going to block userspace touching us until resume completes */
637         snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
638
639         /* mute any active DAC's */
640         for (i = 0; i < machine->num_links; i++) {
641                 struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
642                 if (dai->dai_ops.digital_mute && dai->playback.active)
643                         dai->dai_ops.digital_mute(dai, 1);
644         }
645
646         /* suspend all pcms */
647         for (i = 0; i < machine->num_links; i++)
648                 snd_pcm_suspend_all(machine->dai_link[i].pcm);
649
650         if (machine->suspend_pre)
651                 machine->suspend_pre(pdev, state);
652
653         for (i = 0; i < machine->num_links; i++) {
654                 struct snd_soc_dai  *cpu_dai = machine->dai_link[i].cpu_dai;
655                 if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
656                         cpu_dai->suspend(pdev, cpu_dai);
657                 if (platform->suspend)
658                         platform->suspend(pdev, cpu_dai);
659         }
660
661         /* close any waiting streams and save state */
662         run_delayed_work(&socdev->delayed_work);
663         codec->suspend_bias_level = codec->bias_level;
664
665         for (i = 0; i < codec->num_dai; i++) {
666                 char *stream = codec->dai[i].playback.stream_name;
667                 if (stream != NULL)
668                         snd_soc_dapm_stream_event(codec, stream,
669                                 SND_SOC_DAPM_STREAM_SUSPEND);
670                 stream = codec->dai[i].capture.stream_name;
671                 if (stream != NULL)
672                         snd_soc_dapm_stream_event(codec, stream,
673                                 SND_SOC_DAPM_STREAM_SUSPEND);
674         }
675
676         if (codec_dev->suspend)
677                 codec_dev->suspend(pdev, state);
678
679         for (i = 0; i < machine->num_links; i++) {
680                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
681                 if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
682                         cpu_dai->suspend(pdev, cpu_dai);
683         }
684
685         if (machine->suspend_post)
686                 machine->suspend_post(pdev, state);
687
688         return 0;
689 }
690
691 /* deferred resume work, so resume can complete before we finished
692  * setting our codec back up, which can be very slow on I2C
693  */
694 static void soc_resume_deferred(struct work_struct *work)
695 {
696         struct snd_soc_device *socdev = container_of(work,
697                                                      struct snd_soc_device,
698                                                      deferred_resume_work);
699         struct snd_soc_machine *machine = socdev->machine;
700         struct snd_soc_platform *platform = socdev->platform;
701         struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
702         struct snd_soc_codec *codec = socdev->codec;
703         struct platform_device *pdev = to_platform_device(socdev->dev);
704         int i;
705
706         /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
707          * so userspace apps are blocked from touching us
708          */
709
710         dev_info(socdev->dev, "starting resume work\n");
711
712         if (machine->resume_pre)
713                 machine->resume_pre(pdev);
714
715         for (i = 0; i < machine->num_links; i++) {
716                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
717                 if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
718                         cpu_dai->resume(pdev, cpu_dai);
719         }
720
721         if (codec_dev->resume)
722                 codec_dev->resume(pdev);
723
724         for (i = 0; i < codec->num_dai; i++) {
725                 char *stream = codec->dai[i].playback.stream_name;
726                 if (stream != NULL)
727                         snd_soc_dapm_stream_event(codec, stream,
728                                 SND_SOC_DAPM_STREAM_RESUME);
729                 stream = codec->dai[i].capture.stream_name;
730                 if (stream != NULL)
731                         snd_soc_dapm_stream_event(codec, stream,
732                                 SND_SOC_DAPM_STREAM_RESUME);
733         }
734
735         /* unmute any active DACs */
736         for (i = 0; i < machine->num_links; i++) {
737                 struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
738                 if (dai->dai_ops.digital_mute && dai->playback.active)
739                         dai->dai_ops.digital_mute(dai, 0);
740         }
741
742         for (i = 0; i < machine->num_links; i++) {
743                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
744                 if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
745                         cpu_dai->resume(pdev, cpu_dai);
746                 if (platform->resume)
747                         platform->resume(pdev, cpu_dai);
748         }
749
750         if (machine->resume_post)
751                 machine->resume_post(pdev);
752
753         dev_info(socdev->dev, "resume work completed\n");
754
755         /* userspace can access us now we are back as we were before */
756         snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
757 }
758
759 /* powers up audio subsystem after a suspend */
760 static int soc_resume(struct platform_device *pdev)
761 {
762         struct snd_soc_device *socdev = platform_get_drvdata(pdev);
763
764         dev_info(socdev->dev, "scheduling resume work\n");
765
766         if (!schedule_work(&socdev->deferred_resume_work))
767                 dev_err(socdev->dev, "work item may be lost\n");
768
769         return 0;
770 }
771
772 #else
773 #define soc_suspend     NULL
774 #define soc_resume      NULL
775 #endif
776
777 /* probes a new socdev */
778 static int soc_probe(struct platform_device *pdev)
779 {
780         int ret = 0, i;
781         struct snd_soc_device *socdev = platform_get_drvdata(pdev);
782         struct snd_soc_machine *machine = socdev->machine;
783         struct snd_soc_platform *platform = socdev->platform;
784         struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
785
786         if (machine->probe) {
787                 ret = machine->probe(pdev);
788                 if (ret < 0)
789                         return ret;
790         }
791
792         for (i = 0; i < machine->num_links; i++) {
793                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
794                 if (cpu_dai->probe) {
795                         ret = cpu_dai->probe(pdev, cpu_dai);
796                         if (ret < 0)
797                                 goto cpu_dai_err;
798                 }
799         }
800
801         if (codec_dev->probe) {
802                 ret = codec_dev->probe(pdev);
803                 if (ret < 0)
804                         goto cpu_dai_err;
805         }
806
807         if (platform->probe) {
808                 ret = platform->probe(pdev);
809                 if (ret < 0)
810                         goto platform_err;
811         }
812
813         /* DAPM stream work */
814         INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
815 #ifdef CONFIG_PM
816         /* deferred resume work */
817         INIT_WORK(&socdev->deferred_resume_work, soc_resume_deferred);
818 #endif
819
820         return 0;
821
822 platform_err:
823         if (codec_dev->remove)
824                 codec_dev->remove(pdev);
825
826 cpu_dai_err:
827         for (i--; i >= 0; i--) {
828                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
829                 if (cpu_dai->remove)
830                         cpu_dai->remove(pdev, cpu_dai);
831         }
832
833         if (machine->remove)
834                 machine->remove(pdev);
835
836         return ret;
837 }
838
839 /* removes a socdev */
840 static int soc_remove(struct platform_device *pdev)
841 {
842         int i;
843         struct snd_soc_device *socdev = platform_get_drvdata(pdev);
844         struct snd_soc_machine *machine = socdev->machine;
845         struct snd_soc_platform *platform = socdev->platform;
846         struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
847
848         run_delayed_work(&socdev->delayed_work);
849
850         if (platform->remove)
851                 platform->remove(pdev);
852
853         if (codec_dev->remove)
854                 codec_dev->remove(pdev);
855
856         for (i = 0; i < machine->num_links; i++) {
857                 struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
858                 if (cpu_dai->remove)
859                         cpu_dai->remove(pdev, cpu_dai);
860         }
861
862         if (machine->remove)
863                 machine->remove(pdev);
864
865         return 0;
866 }
867
868 /* ASoC platform driver */
869 static struct platform_driver soc_driver = {
870         .driver         = {
871                 .name           = "soc-audio",
872                 .owner          = THIS_MODULE,
873         },
874         .probe          = soc_probe,
875         .remove         = soc_remove,
876         .suspend        = soc_suspend,
877         .resume         = soc_resume,
878 };
879
880 /* create a new pcm */
881 static int soc_new_pcm(struct snd_soc_device *socdev,
882         struct snd_soc_dai_link *dai_link, int num)
883 {
884         struct snd_soc_codec *codec = socdev->codec;
885         struct snd_soc_dai *codec_dai = dai_link->codec_dai;
886         struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
887         struct snd_soc_pcm_runtime *rtd;
888         struct snd_pcm *pcm;
889         char new_name[64];
890         int ret = 0, playback = 0, capture = 0;
891
892         rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
893         if (rtd == NULL)
894                 return -ENOMEM;
895
896         rtd->dai = dai_link;
897         rtd->socdev = socdev;
898         codec_dai->codec = socdev->codec;
899
900         /* check client and interface hw capabilities */
901         sprintf(new_name, "%s %s-%s-%d", dai_link->stream_name, codec_dai->name,
902                 get_dai_name(cpu_dai->type), num);
903
904         if (codec_dai->playback.channels_min)
905                 playback = 1;
906         if (codec_dai->capture.channels_min)
907                 capture = 1;
908
909         ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
910                 capture, &pcm);
911         if (ret < 0) {
912                 printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
913                         codec->name);
914                 kfree(rtd);
915                 return ret;
916         }
917
918         dai_link->pcm = pcm;
919         pcm->private_data = rtd;
920         soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
921         soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
922         soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
923         soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
924         soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
925         soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
926         soc_pcm_ops.page = socdev->platform->pcm_ops->page;
927
928         if (playback)
929                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
930
931         if (capture)
932                 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
933
934         ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
935         if (ret < 0) {
936                 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
937                 kfree(rtd);
938                 return ret;
939         }
940
941         pcm->private_free = socdev->platform->pcm_free;
942         printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
943                 cpu_dai->name);
944         return ret;
945 }
946
947 /* codec register dump */
948 static ssize_t soc_codec_reg_show(struct snd_soc_device *devdata, char *buf)
949 {
950         struct snd_soc_codec *codec = devdata->codec;
951         int i, step = 1, count = 0;
952
953         if (!codec->reg_cache_size)
954                 return 0;
955
956         if (codec->reg_cache_step)
957                 step = codec->reg_cache_step;
958
959         count += sprintf(buf, "%s registers\n", codec->name);
960         for (i = 0; i < codec->reg_cache_size; i += step) {
961                 count += sprintf(buf + count, "%2x: ", i);
962                 if (count >= PAGE_SIZE - 1)
963                         break;
964
965                 if (codec->display_register)
966                         count += codec->display_register(codec, buf + count,
967                                                          PAGE_SIZE - count, i);
968                 else
969                         count += snprintf(buf + count, PAGE_SIZE - count,
970                                           "%4x", codec->read(codec, i));
971
972                 if (count >= PAGE_SIZE - 1)
973                         break;
974
975                 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
976                 if (count >= PAGE_SIZE - 1)
977                         break;
978         }
979
980         /* Truncate count; min() would cause a warning */
981         if (count >= PAGE_SIZE)
982                 count = PAGE_SIZE - 1;
983
984         return count;
985 }
986 static ssize_t codec_reg_show(struct device *dev,
987         struct device_attribute *attr, char *buf)
988 {
989         struct snd_soc_device *devdata = dev_get_drvdata(dev);
990         return soc_codec_reg_show(devdata, buf);
991 }
992
993 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
994
995 #ifdef CONFIG_DEBUG_FS
996 static int codec_reg_open_file(struct inode *inode, struct file *file)
997 {
998         file->private_data = inode->i_private;
999         return 0;
1000 }
1001
1002 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
1003                                size_t count, loff_t *ppos)
1004 {
1005         ssize_t ret;
1006         struct snd_soc_device *devdata = file->private_data;
1007         char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1008         if (!buf)
1009                 return -ENOMEM;
1010         ret = soc_codec_reg_show(devdata, buf);
1011         if (ret >= 0)
1012                 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1013         kfree(buf);
1014         return ret;
1015 }
1016
1017 static ssize_t codec_reg_write_file(struct file *file,
1018                 const char __user *user_buf, size_t count, loff_t *ppos)
1019 {
1020         char buf[32];
1021         int buf_size;
1022         char *start = buf;
1023         unsigned long reg, value;
1024         int step = 1;
1025         struct snd_soc_device *devdata = file->private_data;
1026         struct snd_soc_codec *codec = devdata->codec;
1027
1028         buf_size = min(count, (sizeof(buf)-1));
1029         if (copy_from_user(buf, user_buf, buf_size))
1030                 return -EFAULT;
1031         buf[buf_size] = 0;
1032
1033         if (codec->reg_cache_step)
1034                 step = codec->reg_cache_step;
1035
1036         while (*start == ' ')
1037                 start++;
1038         reg = simple_strtoul(start, &start, 16);
1039         if ((reg >= codec->reg_cache_size) || (reg % step))
1040                 return -EINVAL;
1041         while (*start == ' ')
1042                 start++;
1043         if (strict_strtoul(start, 16, &value))
1044                 return -EINVAL;
1045         codec->write(codec, reg, value);
1046         return buf_size;
1047 }
1048
1049 static const struct file_operations codec_reg_fops = {
1050         .open = codec_reg_open_file,
1051         .read = codec_reg_read_file,
1052         .write = codec_reg_write_file,
1053 };
1054
1055 static void soc_init_debugfs(struct snd_soc_device *socdev)
1056 {
1057         struct dentry *root, *file;
1058         struct snd_soc_codec *codec = socdev->codec;
1059         root = debugfs_create_dir(dev_name(socdev->dev), NULL);
1060         if (IS_ERR(root) || !root)
1061                 goto exit1;
1062
1063         file = debugfs_create_file("codec_reg", 0644,
1064                         root, socdev, &codec_reg_fops);
1065         if (!file)
1066                 goto exit2;
1067
1068         file = debugfs_create_u32("dapm_pop_time", 0744,
1069                         root, &codec->pop_time);
1070         if (!file)
1071                 goto exit2;
1072         socdev->debugfs_root = root;
1073         return;
1074 exit2:
1075         debugfs_remove_recursive(root);
1076 exit1:
1077         dev_err(socdev->dev, "debugfs is not available\n");
1078 }
1079
1080 static void soc_cleanup_debugfs(struct snd_soc_device *socdev)
1081 {
1082         debugfs_remove_recursive(socdev->debugfs_root);
1083         socdev->debugfs_root = NULL;
1084 }
1085
1086 #else
1087
1088 static inline void soc_init_debugfs(struct snd_soc_device *socdev)
1089 {
1090 }
1091
1092 static inline void soc_cleanup_debugfs(struct snd_soc_device *socdev)
1093 {
1094 }
1095 #endif
1096
1097 /**
1098  * snd_soc_new_ac97_codec - initailise AC97 device
1099  * @codec: audio codec
1100  * @ops: AC97 bus operations
1101  * @num: AC97 codec number
1102  *
1103  * Initialises AC97 codec resources for use by ad-hoc devices only.
1104  */
1105 int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1106         struct snd_ac97_bus_ops *ops, int num)
1107 {
1108         mutex_lock(&codec->mutex);
1109
1110         codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1111         if (codec->ac97 == NULL) {
1112                 mutex_unlock(&codec->mutex);
1113                 return -ENOMEM;
1114         }
1115
1116         codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1117         if (codec->ac97->bus == NULL) {
1118                 kfree(codec->ac97);
1119                 codec->ac97 = NULL;
1120                 mutex_unlock(&codec->mutex);
1121                 return -ENOMEM;
1122         }
1123
1124         codec->ac97->bus->ops = ops;
1125         codec->ac97->num = num;
1126         mutex_unlock(&codec->mutex);
1127         return 0;
1128 }
1129 EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1130
1131 /**
1132  * snd_soc_free_ac97_codec - free AC97 codec device
1133  * @codec: audio codec
1134  *
1135  * Frees AC97 codec device resources.
1136  */
1137 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1138 {
1139         mutex_lock(&codec->mutex);
1140         kfree(codec->ac97->bus);
1141         kfree(codec->ac97);
1142         codec->ac97 = NULL;
1143         mutex_unlock(&codec->mutex);
1144 }
1145 EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1146
1147 /**
1148  * snd_soc_update_bits - update codec register bits
1149  * @codec: audio codec
1150  * @reg: codec register
1151  * @mask: register mask
1152  * @value: new value
1153  *
1154  * Writes new register value.
1155  *
1156  * Returns 1 for change else 0.
1157  */
1158 int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
1159                                 unsigned short mask, unsigned short value)
1160 {
1161         int change;
1162         unsigned short old, new;
1163
1164         mutex_lock(&io_mutex);
1165         old = snd_soc_read(codec, reg);
1166         new = (old & ~mask) | value;
1167         change = old != new;
1168         if (change)
1169                 snd_soc_write(codec, reg, new);
1170
1171         mutex_unlock(&io_mutex);
1172         return change;
1173 }
1174 EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1175
1176 /**
1177  * snd_soc_test_bits - test register for change
1178  * @codec: audio codec
1179  * @reg: codec register
1180  * @mask: register mask
1181  * @value: new value
1182  *
1183  * Tests a register with a new value and checks if the new value is
1184  * different from the old value.
1185  *
1186  * Returns 1 for change else 0.
1187  */
1188 int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1189                                 unsigned short mask, unsigned short value)
1190 {
1191         int change;
1192         unsigned short old, new;
1193
1194         mutex_lock(&io_mutex);
1195         old = snd_soc_read(codec, reg);
1196         new = (old & ~mask) | value;
1197         change = old != new;
1198         mutex_unlock(&io_mutex);
1199
1200         return change;
1201 }
1202 EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1203
1204 /**
1205  * snd_soc_new_pcms - create new sound card and pcms
1206  * @socdev: the SoC audio device
1207  *
1208  * Create a new sound card based upon the codec and interface pcms.
1209  *
1210  * Returns 0 for success, else error.
1211  */
1212 int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1213 {
1214         struct snd_soc_codec *codec = socdev->codec;
1215         struct snd_soc_machine *machine = socdev->machine;
1216         int ret = 0, i;
1217
1218         mutex_lock(&codec->mutex);
1219
1220         /* register a sound card */
1221         codec->card = snd_card_new(idx, xid, codec->owner, 0);
1222         if (!codec->card) {
1223                 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1224                         codec->name);
1225                 mutex_unlock(&codec->mutex);
1226                 return -ENODEV;
1227         }
1228
1229         codec->card->dev = socdev->dev;
1230         codec->card->private_data = codec;
1231         strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1232
1233         /* create the pcms */
1234         for (i = 0; i < machine->num_links; i++) {
1235                 ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
1236                 if (ret < 0) {
1237                         printk(KERN_ERR "asoc: can't create pcm %s\n",
1238                                 machine->dai_link[i].stream_name);
1239                         mutex_unlock(&codec->mutex);
1240                         return ret;
1241                 }
1242         }
1243
1244         mutex_unlock(&codec->mutex);
1245         return ret;
1246 }
1247 EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1248
1249 /**
1250  * snd_soc_register_card - register sound card
1251  * @socdev: the SoC audio device
1252  *
1253  * Register a SoC sound card. Also registers an AC97 device if the
1254  * codec is AC97 for ad hoc devices.
1255  *
1256  * Returns 0 for success, else error.
1257  */
1258 int snd_soc_register_card(struct snd_soc_device *socdev)
1259 {
1260         struct snd_soc_codec *codec = socdev->codec;
1261         struct snd_soc_machine *machine = socdev->machine;
1262         int ret = 0, i, ac97 = 0, err = 0;
1263
1264         for (i = 0; i < machine->num_links; i++) {
1265                 if (socdev->machine->dai_link[i].init) {
1266                         err = socdev->machine->dai_link[i].init(codec);
1267                         if (err < 0) {
1268                                 printk(KERN_ERR "asoc: failed to init %s\n",
1269                                         socdev->machine->dai_link[i].stream_name);
1270                                 continue;
1271                         }
1272                 }
1273                 if (socdev->machine->dai_link[i].codec_dai->type ==
1274                         SND_SOC_DAI_AC97_BUS)
1275                         ac97 = 1;
1276         }
1277         snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1278                  "%s", machine->name);
1279         snprintf(codec->card->longname, sizeof(codec->card->longname),
1280                  "%s (%s)", machine->name, codec->name);
1281
1282         ret = snd_card_register(codec->card);
1283         if (ret < 0) {
1284                 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1285                                 codec->name);
1286                 goto out;
1287         }
1288
1289         mutex_lock(&codec->mutex);
1290 #ifdef CONFIG_SND_SOC_AC97_BUS
1291         if (ac97) {
1292                 ret = soc_ac97_dev_register(codec);
1293                 if (ret < 0) {
1294                         printk(KERN_ERR "asoc: AC97 device register failed\n");
1295                         snd_card_free(codec->card);
1296                         mutex_unlock(&codec->mutex);
1297                         goto out;
1298                 }
1299         }
1300 #endif
1301
1302         err = snd_soc_dapm_sys_add(socdev->dev);
1303         if (err < 0)
1304                 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1305
1306         err = device_create_file(socdev->dev, &dev_attr_codec_reg);
1307         if (err < 0)
1308                 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1309
1310         soc_init_debugfs(socdev);
1311         mutex_unlock(&codec->mutex);
1312
1313 out:
1314         return ret;
1315 }
1316 EXPORT_SYMBOL_GPL(snd_soc_register_card);
1317
1318 /**
1319  * snd_soc_free_pcms - free sound card and pcms
1320  * @socdev: the SoC audio device
1321  *
1322  * Frees sound card and pcms associated with the socdev.
1323  * Also unregister the codec if it is an AC97 device.
1324  */
1325 void snd_soc_free_pcms(struct snd_soc_device *socdev)
1326 {
1327         struct snd_soc_codec *codec = socdev->codec;
1328 #ifdef CONFIG_SND_SOC_AC97_BUS
1329         struct snd_soc_dai *codec_dai;
1330         int i;
1331 #endif
1332
1333         mutex_lock(&codec->mutex);
1334         soc_cleanup_debugfs(socdev);
1335 #ifdef CONFIG_SND_SOC_AC97_BUS
1336         for (i = 0; i < codec->num_dai; i++) {
1337                 codec_dai = &codec->dai[i];
1338                 if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
1339                         soc_ac97_dev_unregister(codec);
1340                         goto free_card;
1341                 }
1342         }
1343 free_card:
1344 #endif
1345
1346         if (codec->card)
1347                 snd_card_free(codec->card);
1348         device_remove_file(socdev->dev, &dev_attr_codec_reg);
1349         mutex_unlock(&codec->mutex);
1350 }
1351 EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1352
1353 /**
1354  * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1355  * @substream: the pcm substream
1356  * @hw: the hardware parameters
1357  *
1358  * Sets the substream runtime hardware parameters.
1359  */
1360 int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1361         const struct snd_pcm_hardware *hw)
1362 {
1363         struct snd_pcm_runtime *runtime = substream->runtime;
1364         runtime->hw.info = hw->info;
1365         runtime->hw.formats = hw->formats;
1366         runtime->hw.period_bytes_min = hw->period_bytes_min;
1367         runtime->hw.period_bytes_max = hw->period_bytes_max;
1368         runtime->hw.periods_min = hw->periods_min;
1369         runtime->hw.periods_max = hw->periods_max;
1370         runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1371         runtime->hw.fifo_size = hw->fifo_size;
1372         return 0;
1373 }
1374 EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1375
1376 /**
1377  * snd_soc_cnew - create new control
1378  * @_template: control template
1379  * @data: control private data
1380  * @lnng_name: control long name
1381  *
1382  * Create a new mixer control from a template control.
1383  *
1384  * Returns 0 for success, else error.
1385  */
1386 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1387         void *data, char *long_name)
1388 {
1389         struct snd_kcontrol_new template;
1390
1391         memcpy(&template, _template, sizeof(template));
1392         if (long_name)
1393                 template.name = long_name;
1394         template.index = 0;
1395
1396         return snd_ctl_new1(&template, data);
1397 }
1398 EXPORT_SYMBOL_GPL(snd_soc_cnew);
1399
1400 /**
1401  * snd_soc_info_enum_double - enumerated double mixer info callback
1402  * @kcontrol: mixer control
1403  * @uinfo: control element information
1404  *
1405  * Callback to provide information about a double enumerated
1406  * mixer control.
1407  *
1408  * Returns 0 for success.
1409  */
1410 int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1411         struct snd_ctl_elem_info *uinfo)
1412 {
1413         struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1414
1415         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1416         uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
1417         uinfo->value.enumerated.items = e->max;
1418
1419         if (uinfo->value.enumerated.item > e->max - 1)
1420                 uinfo->value.enumerated.item = e->max - 1;
1421         strcpy(uinfo->value.enumerated.name,
1422                 e->texts[uinfo->value.enumerated.item]);
1423         return 0;
1424 }
1425 EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1426
1427 /**
1428  * snd_soc_get_enum_double - enumerated double mixer get callback
1429  * @kcontrol: mixer control
1430  * @uinfo: control element information
1431  *
1432  * Callback to get the value of a double enumerated mixer.
1433  *
1434  * Returns 0 for success.
1435  */
1436 int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1437         struct snd_ctl_elem_value *ucontrol)
1438 {
1439         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1440         struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1441         unsigned short val, bitmask;
1442
1443         for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1444                 ;
1445         val = snd_soc_read(codec, e->reg);
1446         ucontrol->value.enumerated.item[0]
1447                 = (val >> e->shift_l) & (bitmask - 1);
1448         if (e->shift_l != e->shift_r)
1449                 ucontrol->value.enumerated.item[1] =
1450                         (val >> e->shift_r) & (bitmask - 1);
1451
1452         return 0;
1453 }
1454 EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1455
1456 /**
1457  * snd_soc_put_enum_double - enumerated double mixer put callback
1458  * @kcontrol: mixer control
1459  * @uinfo: control element information
1460  *
1461  * Callback to set the value of a double enumerated mixer.
1462  *
1463  * Returns 0 for success.
1464  */
1465 int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1466         struct snd_ctl_elem_value *ucontrol)
1467 {
1468         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1469         struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1470         unsigned short val;
1471         unsigned short mask, bitmask;
1472
1473         for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
1474                 ;
1475         if (ucontrol->value.enumerated.item[0] > e->max - 1)
1476                 return -EINVAL;
1477         val = ucontrol->value.enumerated.item[0] << e->shift_l;
1478         mask = (bitmask - 1) << e->shift_l;
1479         if (e->shift_l != e->shift_r) {
1480                 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1481                         return -EINVAL;
1482                 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1483                 mask |= (bitmask - 1) << e->shift_r;
1484         }
1485
1486         return snd_soc_update_bits(codec, e->reg, mask, val);
1487 }
1488 EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1489
1490 /**
1491  * snd_soc_info_enum_ext - external enumerated single mixer info callback
1492  * @kcontrol: mixer control
1493  * @uinfo: control element information
1494  *
1495  * Callback to provide information about an external enumerated
1496  * single mixer.
1497  *
1498  * Returns 0 for success.
1499  */
1500 int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1501         struct snd_ctl_elem_info *uinfo)
1502 {
1503         struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1504
1505         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1506         uinfo->count = 1;
1507         uinfo->value.enumerated.items = e->max;
1508
1509         if (uinfo->value.enumerated.item > e->max - 1)
1510                 uinfo->value.enumerated.item = e->max - 1;
1511         strcpy(uinfo->value.enumerated.name,
1512                 e->texts[uinfo->value.enumerated.item]);
1513         return 0;
1514 }
1515 EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1516
1517 /**
1518  * snd_soc_info_volsw_ext - external single mixer info callback
1519  * @kcontrol: mixer control
1520  * @uinfo: control element information
1521  *
1522  * Callback to provide information about a single external mixer control.
1523  *
1524  * Returns 0 for success.
1525  */
1526 int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1527         struct snd_ctl_elem_info *uinfo)
1528 {
1529         int max = kcontrol->private_value;
1530
1531         if (max == 1)
1532                 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1533         else
1534                 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1535
1536         uinfo->count = 1;
1537         uinfo->value.integer.min = 0;
1538         uinfo->value.integer.max = max;
1539         return 0;
1540 }
1541 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1542
1543 /**
1544  * snd_soc_info_volsw - single mixer info callback
1545  * @kcontrol: mixer control
1546  * @uinfo: control element information
1547  *
1548  * Callback to provide information about a single mixer control.
1549  *
1550  * Returns 0 for success.
1551  */
1552 int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1553         struct snd_ctl_elem_info *uinfo)
1554 {
1555         struct soc_mixer_control *mc =
1556                 (struct soc_mixer_control *)kcontrol->private_value;
1557         int max = mc->max;
1558         unsigned int shift = mc->shift;
1559         unsigned int rshift = mc->rshift;
1560
1561         if (max == 1)
1562                 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1563         else
1564                 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1565
1566         uinfo->count = shift == rshift ? 1 : 2;
1567         uinfo->value.integer.min = 0;
1568         uinfo->value.integer.max = max;
1569         return 0;
1570 }
1571 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1572
1573 /**
1574  * snd_soc_get_volsw - single mixer get callback
1575  * @kcontrol: mixer control
1576  * @uinfo: control element information
1577  *
1578  * Callback to get the value of a single mixer control.
1579  *
1580  * Returns 0 for success.
1581  */
1582 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
1583         struct snd_ctl_elem_value *ucontrol)
1584 {
1585         struct soc_mixer_control *mc =
1586                 (struct soc_mixer_control *)kcontrol->private_value;
1587         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1588         unsigned int reg = mc->reg;
1589         unsigned int shift = mc->shift;
1590         unsigned int rshift = mc->rshift;
1591         int max = mc->max;
1592         unsigned int mask = (1 << fls(max)) - 1;
1593         unsigned int invert = mc->invert;
1594
1595         ucontrol->value.integer.value[0] =
1596                 (snd_soc_read(codec, reg) >> shift) & mask;
1597         if (shift != rshift)
1598                 ucontrol->value.integer.value[1] =
1599                         (snd_soc_read(codec, reg) >> rshift) & mask;
1600         if (invert) {
1601                 ucontrol->value.integer.value[0] =
1602                         max - ucontrol->value.integer.value[0];
1603                 if (shift != rshift)
1604                         ucontrol->value.integer.value[1] =
1605                                 max - ucontrol->value.integer.value[1];
1606         }
1607
1608         return 0;
1609 }
1610 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
1611
1612 /**
1613  * snd_soc_put_volsw - single mixer put callback
1614  * @kcontrol: mixer control
1615  * @uinfo: control element information
1616  *
1617  * Callback to set the value of a single mixer control.
1618  *
1619  * Returns 0 for success.
1620  */
1621 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
1622         struct snd_ctl_elem_value *ucontrol)
1623 {
1624         struct soc_mixer_control *mc =
1625                 (struct soc_mixer_control *)kcontrol->private_value;
1626         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1627         unsigned int reg = mc->reg;
1628         unsigned int shift = mc->shift;
1629         unsigned int rshift = mc->rshift;
1630         int max = mc->max;
1631         unsigned int mask = (1 << fls(max)) - 1;
1632         unsigned int invert = mc->invert;
1633         unsigned short val, val2, val_mask;
1634
1635         val = (ucontrol->value.integer.value[0] & mask);
1636         if (invert)
1637                 val = max - val;
1638         val_mask = mask << shift;
1639         val = val << shift;
1640         if (shift != rshift) {
1641                 val2 = (ucontrol->value.integer.value[1] & mask);
1642                 if (invert)
1643                         val2 = max - val2;
1644                 val_mask |= mask << rshift;
1645                 val |= val2 << rshift;
1646         }
1647         return snd_soc_update_bits(codec, reg, val_mask, val);
1648 }
1649 EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
1650
1651 /**
1652  * snd_soc_info_volsw_2r - double mixer info callback
1653  * @kcontrol: mixer control
1654  * @uinfo: control element information
1655  *
1656  * Callback to provide information about a double mixer control that
1657  * spans 2 codec registers.
1658  *
1659  * Returns 0 for success.
1660  */
1661 int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
1662         struct snd_ctl_elem_info *uinfo)
1663 {
1664         struct soc_mixer_control *mc =
1665                 (struct soc_mixer_control *)kcontrol->private_value;
1666         int max = mc->max;
1667
1668         if (max == 1)
1669                 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1670         else
1671                 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1672
1673         uinfo->count = 2;
1674         uinfo->value.integer.min = 0;
1675         uinfo->value.integer.max = max;
1676         return 0;
1677 }
1678 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
1679
1680 /**
1681  * snd_soc_get_volsw_2r - double mixer get callback
1682  * @kcontrol: mixer control
1683  * @uinfo: control element information
1684  *
1685  * Callback to get the value of a double mixer control that spans 2 registers.
1686  *
1687  * Returns 0 for success.
1688  */
1689 int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
1690         struct snd_ctl_elem_value *ucontrol)
1691 {
1692         struct soc_mixer_control *mc =
1693                 (struct soc_mixer_control *)kcontrol->private_value;
1694         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1695         unsigned int reg = mc->reg;
1696         unsigned int reg2 = mc->rreg;
1697         unsigned int shift = mc->shift;
1698         int max = mc->max;
1699         unsigned int mask = (1<<fls(max))-1;
1700         unsigned int invert = mc->invert;
1701
1702         ucontrol->value.integer.value[0] =
1703                 (snd_soc_read(codec, reg) >> shift) & mask;
1704         ucontrol->value.integer.value[1] =
1705                 (snd_soc_read(codec, reg2) >> shift) & mask;
1706         if (invert) {
1707                 ucontrol->value.integer.value[0] =
1708                         max - ucontrol->value.integer.value[0];
1709                 ucontrol->value.integer.value[1] =
1710                         max - ucontrol->value.integer.value[1];
1711         }
1712
1713         return 0;
1714 }
1715 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
1716
1717 /**
1718  * snd_soc_put_volsw_2r - double mixer set callback
1719  * @kcontrol: mixer control
1720  * @uinfo: control element information
1721  *
1722  * Callback to set the value of a double mixer control that spans 2 registers.
1723  *
1724  * Returns 0 for success.
1725  */
1726 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
1727         struct snd_ctl_elem_value *ucontrol)
1728 {
1729         struct soc_mixer_control *mc =
1730                 (struct soc_mixer_control *)kcontrol->private_value;
1731         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1732         unsigned int reg = mc->reg;
1733         unsigned int reg2 = mc->rreg;
1734         unsigned int shift = mc->shift;
1735         int max = mc->max;
1736         unsigned int mask = (1 << fls(max)) - 1;
1737         unsigned int invert = mc->invert;
1738         int err;
1739         unsigned short val, val2, val_mask;
1740
1741         val_mask = mask << shift;
1742         val = (ucontrol->value.integer.value[0] & mask);
1743         val2 = (ucontrol->value.integer.value[1] & mask);
1744
1745         if (invert) {
1746                 val = max - val;
1747                 val2 = max - val2;
1748         }
1749
1750         val = val << shift;
1751         val2 = val2 << shift;
1752
1753         err = snd_soc_update_bits(codec, reg, val_mask, val);
1754         if (err < 0)
1755                 return err;
1756
1757         err = snd_soc_update_bits(codec, reg2, val_mask, val2);
1758         return err;
1759 }
1760 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
1761
1762 /**
1763  * snd_soc_info_volsw_s8 - signed mixer info callback
1764  * @kcontrol: mixer control
1765  * @uinfo: control element information
1766  *
1767  * Callback to provide information about a signed mixer control.
1768  *
1769  * Returns 0 for success.
1770  */
1771 int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
1772         struct snd_ctl_elem_info *uinfo)
1773 {
1774         struct soc_mixer_control *mc =
1775                 (struct soc_mixer_control *)kcontrol->private_value;
1776         int max = mc->max;
1777         int min = mc->min;
1778
1779         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1780         uinfo->count = 2;
1781         uinfo->value.integer.min = 0;
1782         uinfo->value.integer.max = max-min;
1783         return 0;
1784 }
1785 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
1786
1787 /**
1788  * snd_soc_get_volsw_s8 - signed mixer get callback
1789  * @kcontrol: mixer control
1790  * @uinfo: control element information
1791  *
1792  * Callback to get the value of a signed mixer control.
1793  *
1794  * Returns 0 for success.
1795  */
1796 int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
1797         struct snd_ctl_elem_value *ucontrol)
1798 {
1799         struct soc_mixer_control *mc =
1800                 (struct soc_mixer_control *)kcontrol->private_value;
1801         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1802         unsigned int reg = mc->reg;
1803         int min = mc->min;
1804         int val = snd_soc_read(codec, reg);
1805
1806         ucontrol->value.integer.value[0] =
1807                 ((signed char)(val & 0xff))-min;
1808         ucontrol->value.integer.value[1] =
1809                 ((signed char)((val >> 8) & 0xff))-min;
1810         return 0;
1811 }
1812 EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
1813
1814 /**
1815  * snd_soc_put_volsw_sgn - signed mixer put callback
1816  * @kcontrol: mixer control
1817  * @uinfo: control element information
1818  *
1819  * Callback to set the value of a signed mixer control.
1820  *
1821  * Returns 0 for success.
1822  */
1823 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
1824         struct snd_ctl_elem_value *ucontrol)
1825 {
1826         struct soc_mixer_control *mc =
1827                 (struct soc_mixer_control *)kcontrol->private_value;
1828         struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1829         unsigned int reg = mc->reg;
1830         int min = mc->min;
1831         unsigned short val;
1832
1833         val = (ucontrol->value.integer.value[0]+min) & 0xff;
1834         val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
1835
1836         return snd_soc_update_bits(codec, reg, 0xffff, val);
1837 }
1838 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
1839
1840 /**
1841  * snd_soc_dai_set_sysclk - configure DAI system or master clock.
1842  * @dai: DAI
1843  * @clk_id: DAI specific clock ID
1844  * @freq: new clock frequency in Hz
1845  * @dir: new clock direction - input/output.
1846  *
1847  * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
1848  */
1849 int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
1850         unsigned int freq, int dir)
1851 {
1852         if (dai->dai_ops.set_sysclk)
1853                 return dai->dai_ops.set_sysclk(dai, clk_id, freq, dir);
1854         else
1855                 return -EINVAL;
1856 }
1857 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
1858
1859 /**
1860  * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
1861  * @dai: DAI
1862  * @clk_id: DAI specific clock divider ID
1863  * @div: new clock divisor.
1864  *
1865  * Configures the clock dividers. This is used to derive the best DAI bit and
1866  * frame clocks from the system or master clock. It's best to set the DAI bit
1867  * and frame clocks as low as possible to save system power.
1868  */
1869 int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
1870         int div_id, int div)
1871 {
1872         if (dai->dai_ops.set_clkdiv)
1873                 return dai->dai_ops.set_clkdiv(dai, div_id, div);
1874         else
1875                 return -EINVAL;
1876 }
1877 EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
1878
1879 /**
1880  * snd_soc_dai_set_pll - configure DAI PLL.
1881  * @dai: DAI
1882  * @pll_id: DAI specific PLL ID
1883  * @freq_in: PLL input clock frequency in Hz
1884  * @freq_out: requested PLL output clock frequency in Hz
1885  *
1886  * Configures and enables PLL to generate output clock based on input clock.
1887  */
1888 int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
1889         int pll_id, unsigned int freq_in, unsigned int freq_out)
1890 {
1891         if (dai->dai_ops.set_pll)
1892                 return dai->dai_ops.set_pll(dai, pll_id, freq_in, freq_out);
1893         else
1894                 return -EINVAL;
1895 }
1896 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
1897
1898 /**
1899  * snd_soc_dai_set_fmt - configure DAI hardware audio format.
1900  * @dai: DAI
1901  * @clk_id: DAI specific clock ID
1902  * @fmt: SND_SOC_DAIFMT_ format value.
1903  *
1904  * Configures the DAI hardware format and clocking.
1905  */
1906 int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1907 {
1908         if (dai->dai_ops.set_fmt)
1909                 return dai->dai_ops.set_fmt(dai, fmt);
1910         else
1911                 return -EINVAL;
1912 }
1913 EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
1914
1915 /**
1916  * snd_soc_dai_set_tdm_slot - configure DAI TDM.
1917  * @dai: DAI
1918  * @mask: DAI specific mask representing used slots.
1919  * @slots: Number of slots in use.
1920  *
1921  * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
1922  * specific.
1923  */
1924 int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
1925         unsigned int mask, int slots)
1926 {
1927         if (dai->dai_ops.set_sysclk)
1928                 return dai->dai_ops.set_tdm_slot(dai, mask, slots);
1929         else
1930                 return -EINVAL;
1931 }
1932 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
1933
1934 /**
1935  * snd_soc_dai_set_tristate - configure DAI system or master clock.
1936  * @dai: DAI
1937  * @tristate: tristate enable
1938  *
1939  * Tristates the DAI so that others can use it.
1940  */
1941 int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
1942 {
1943         if (dai->dai_ops.set_sysclk)
1944                 return dai->dai_ops.set_tristate(dai, tristate);
1945         else
1946                 return -EINVAL;
1947 }
1948 EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
1949
1950 /**
1951  * snd_soc_dai_digital_mute - configure DAI system or master clock.
1952  * @dai: DAI
1953  * @mute: mute enable
1954  *
1955  * Mutes the DAI DAC.
1956  */
1957 int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
1958 {
1959         if (dai->dai_ops.digital_mute)
1960                 return dai->dai_ops.digital_mute(dai, mute);
1961         else
1962                 return -EINVAL;
1963 }
1964 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
1965
1966 static int __devinit snd_soc_init(void)
1967 {
1968         return platform_driver_register(&soc_driver);
1969 }
1970
1971 static void snd_soc_exit(void)
1972 {
1973         platform_driver_unregister(&soc_driver);
1974 }
1975
1976 module_init(snd_soc_init);
1977 module_exit(snd_soc_exit);
1978
1979 /* Module information */
1980 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
1981 MODULE_DESCRIPTION("ALSA SoC Core");
1982 MODULE_LICENSE("GPL");
1983 MODULE_ALIAS("platform:soc-audio");