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