ASoC: dapm: Notify stream event to all card components.
[deliverable/linux.git] / sound / soc / soc-core.c
CommitLineData
db2a4165
FM
1/*
2 * soc-core.c -- ALSA SoC Audio Layer
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
0664d888 5 * Copyright 2005 Openedhand Ltd.
f0fba2ad
LG
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
0664d888 8 *
d331124d 9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
0664d888
LG
10 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
db2a4165
FM
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
db2a4165
FM
18 * TODO:
19 * o Add hw rules to enforce rates, etc.
20 * o More testing with other codecs/machines.
21 * o Add more codecs and platforms to ensure good API coverage.
22 * o Support TDM on PCM and I2S
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/pm.h>
30#include <linux/bitops.h>
12ef193d 31#include <linux/debugfs.h>
db2a4165 32#include <linux/platform_device.h>
f0e8ed85 33#include <linux/ctype.h>
5a0e3ad6 34#include <linux/slab.h>
bec4fa05 35#include <linux/of.h>
474828a4 36#include <sound/ac97_codec.h>
db2a4165 37#include <sound/core.h>
3028eb8c 38#include <sound/jack.h>
db2a4165
FM
39#include <sound/pcm.h>
40#include <sound/pcm_params.h>
41#include <sound/soc.h>
db2a4165
FM
42#include <sound/initval.h>
43
a8b1d34f
MB
44#define CREATE_TRACE_POINTS
45#include <trace/events/asoc.h>
46
f0fba2ad
LG
47#define NAME_SIZE 32
48
db2a4165
FM
49static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
50
384c89e2 51#ifdef CONFIG_DEBUG_FS
8a9dab1a
MB
52struct dentry *snd_soc_debugfs_root;
53EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
384c89e2
MB
54#endif
55
c5af3a2e
MB
56static DEFINE_MUTEX(client_mutex);
57static LIST_HEAD(card_list);
9115171a 58static LIST_HEAD(dai_list);
12a48a8c 59static LIST_HEAD(platform_list);
0d0cf00a 60static LIST_HEAD(codec_list);
c5af3a2e 61
db2a4165
FM
62/*
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
66 */
67static int pmdown_time = 5000;
68module_param(pmdown_time, int, 0);
69MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
70
2bc9a81e
DP
71/* returns the minimum number of bytes needed to represent
72 * a particular given value */
73static int min_bytes_needed(unsigned long val)
74{
75 int c = 0;
76 int i;
77
78 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
79 if (val & (1UL << i))
80 break;
81 c = (sizeof val * 8) - c;
82 if (!c || (c % 8))
83 c = (c + 8) / 8;
84 else
85 c /= 8;
86 return c;
87}
88
13fd179f
DP
89/* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91static int format_register_str(struct snd_soc_codec *codec,
92 unsigned int reg, char *buf, size_t len)
93{
00b317a4
SW
94 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
95 int regsize = codec->driver->reg_word_size * 2;
13fd179f
DP
96 int ret;
97 char tmpbuf[len + 1];
98 char regbuf[regsize + 1];
99
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
102 WARN_ON(len > 63);
103
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize + regsize + 2 + 1 != len)
106 return -EINVAL;
107
25032c11 108 ret = snd_soc_read(codec, reg);
13fd179f
DP
109 if (ret < 0) {
110 memset(regbuf, 'X', regsize);
111 regbuf[regsize] = '\0';
112 } else {
113 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
114 }
115
116 /* prepare the buffer */
117 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf, tmpbuf, len);
120
121 return 0;
122}
123
2624d5fa 124/* codec register dump */
13fd179f
DP
125static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
126 size_t count, loff_t pos)
2624d5fa 127{
13fd179f 128 int i, step = 1;
2bc9a81e 129 int wordsize, regsize;
13fd179f
DP
130 int len;
131 size_t total = 0;
132 loff_t p = 0;
2bc9a81e 133
00b317a4
SW
134 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
135 regsize = codec->driver->reg_word_size * 2;
2624d5fa 136
13fd179f
DP
137 len = wordsize + regsize + 2 + 1;
138
f0fba2ad 139 if (!codec->driver->reg_cache_size)
2624d5fa
MB
140 return 0;
141
f0fba2ad
LG
142 if (codec->driver->reg_cache_step)
143 step = codec->driver->reg_cache_step;
2624d5fa 144
f0fba2ad 145 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
b92d150b 146 if (!snd_soc_codec_readable_register(codec, i))
2624d5fa 147 continue;
f0fba2ad
LG
148 if (codec->driver->display_register) {
149 count += codec->driver->display_register(codec, buf + count,
2624d5fa 150 PAGE_SIZE - count, i);
5164d74d 151 } else {
13fd179f
DP
152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
154 if (p >= pos) {
155 if (total + len >= count - 1)
156 break;
157 format_register_str(codec, i, buf + total, len);
158 total += len;
159 }
160 p += len;
5164d74d 161 }
2624d5fa
MB
162 }
163
13fd179f 164 total = min(total, count - 1);
2624d5fa 165
13fd179f 166 return total;
2624d5fa 167}
13fd179f 168
2624d5fa
MB
169static ssize_t codec_reg_show(struct device *dev,
170 struct device_attribute *attr, char *buf)
171{
36ae1a96 172 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
f0fba2ad 173
13fd179f 174 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
2624d5fa
MB
175}
176
177static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
178
dbe21408
MB
179static ssize_t pmdown_time_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
181{
36ae1a96 182 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
dbe21408 183
f0fba2ad 184 return sprintf(buf, "%ld\n", rtd->pmdown_time);
dbe21408
MB
185}
186
187static ssize_t pmdown_time_set(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
190{
36ae1a96 191 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
c593b520 192 int ret;
dbe21408 193
c593b520
MB
194 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
195 if (ret)
196 return ret;
dbe21408
MB
197
198 return count;
199}
200
201static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
202
2624d5fa
MB
203#ifdef CONFIG_DEBUG_FS
204static int codec_reg_open_file(struct inode *inode, struct file *file)
205{
206 file->private_data = inode->i_private;
207 return 0;
208}
209
210static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
13fd179f 211 size_t count, loff_t *ppos)
2624d5fa
MB
212{
213 ssize_t ret;
214 struct snd_soc_codec *codec = file->private_data;
13fd179f
DP
215 char *buf;
216
217 if (*ppos < 0 || !count)
218 return -EINVAL;
219
220 buf = kmalloc(count, GFP_KERNEL);
2624d5fa
MB
221 if (!buf)
222 return -ENOMEM;
13fd179f
DP
223
224 ret = soc_codec_reg_show(codec, buf, count, *ppos);
225 if (ret >= 0) {
226 if (copy_to_user(user_buf, buf, ret)) {
227 kfree(buf);
228 return -EFAULT;
229 }
230 *ppos += ret;
231 }
232
2624d5fa
MB
233 kfree(buf);
234 return ret;
235}
236
237static ssize_t codec_reg_write_file(struct file *file,
238 const char __user *user_buf, size_t count, loff_t *ppos)
239{
240 char buf[32];
34e268d8 241 size_t buf_size;
2624d5fa
MB
242 char *start = buf;
243 unsigned long reg, value;
2624d5fa
MB
244 struct snd_soc_codec *codec = file->private_data;
245
246 buf_size = min(count, (sizeof(buf)-1));
247 if (copy_from_user(buf, user_buf, buf_size))
248 return -EFAULT;
249 buf[buf_size] = 0;
2624d5fa
MB
250
251 while (*start == ' ')
252 start++;
253 reg = simple_strtoul(start, &start, 16);
2624d5fa
MB
254 while (*start == ' ')
255 start++;
256 if (strict_strtoul(start, 16, &value))
257 return -EINVAL;
0d51a9cb
MB
258
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER);
261
e4f078d8 262 snd_soc_write(codec, reg, value);
2624d5fa
MB
263 return buf_size;
264}
265
266static const struct file_operations codec_reg_fops = {
267 .open = codec_reg_open_file,
268 .read = codec_reg_read_file,
269 .write = codec_reg_write_file,
6038f373 270 .llseek = default_llseek,
2624d5fa
MB
271};
272
273static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
274{
d6ce4cf3
JN
275 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
276
277 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
278 debugfs_card_root);
2624d5fa
MB
279 if (!codec->debugfs_codec_root) {
280 printk(KERN_WARNING
281 "ASoC: Failed to create codec debugfs directory\n");
282 return;
283 }
284
aaee8ef1
MB
285 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
286 &codec->cache_sync);
287 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
288 &codec->cache_only);
289
2624d5fa
MB
290 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
291 codec->debugfs_codec_root,
292 codec, &codec_reg_fops);
293 if (!codec->debugfs_reg)
294 printk(KERN_WARNING
295 "ASoC: Failed to create codec register debugfs file\n");
296
8eecaf62 297 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
2624d5fa
MB
298}
299
300static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
301{
302 debugfs_remove_recursive(codec->debugfs_codec_root);
303}
304
c3c5a19a
MB
305static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
306 size_t count, loff_t *ppos)
307{
308 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 309 ssize_t len, ret = 0;
c3c5a19a
MB
310 struct snd_soc_codec *codec;
311
312 if (!buf)
313 return -ENOMEM;
314
2b194f9d
MB
315 list_for_each_entry(codec, &codec_list, list) {
316 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
317 codec->name);
318 if (len >= 0)
319 ret += len;
320 if (ret > PAGE_SIZE) {
321 ret = PAGE_SIZE;
322 break;
323 }
324 }
c3c5a19a
MB
325
326 if (ret >= 0)
327 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
328
329 kfree(buf);
330
331 return ret;
332}
333
334static const struct file_operations codec_list_fops = {
335 .read = codec_list_read_file,
336 .llseek = default_llseek,/* read accesses f_pos */
337};
338
f3208780
MB
339static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
340 size_t count, loff_t *ppos)
341{
342 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 343 ssize_t len, ret = 0;
f3208780
MB
344 struct snd_soc_dai *dai;
345
346 if (!buf)
347 return -ENOMEM;
348
2b194f9d
MB
349 list_for_each_entry(dai, &dai_list, list) {
350 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
351 if (len >= 0)
352 ret += len;
353 if (ret > PAGE_SIZE) {
354 ret = PAGE_SIZE;
355 break;
356 }
357 }
f3208780 358
2b194f9d 359 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
f3208780
MB
360
361 kfree(buf);
362
363 return ret;
364}
365
366static const struct file_operations dai_list_fops = {
367 .read = dai_list_read_file,
368 .llseek = default_llseek,/* read accesses f_pos */
369};
370
19c7ac27
MB
371static ssize_t platform_list_read_file(struct file *file,
372 char __user *user_buf,
373 size_t count, loff_t *ppos)
374{
375 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 376 ssize_t len, ret = 0;
19c7ac27
MB
377 struct snd_soc_platform *platform;
378
379 if (!buf)
380 return -ENOMEM;
381
2b194f9d
MB
382 list_for_each_entry(platform, &platform_list, list) {
383 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
384 platform->name);
385 if (len >= 0)
386 ret += len;
387 if (ret > PAGE_SIZE) {
388 ret = PAGE_SIZE;
389 break;
390 }
391 }
19c7ac27 392
2b194f9d 393 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
19c7ac27
MB
394
395 kfree(buf);
396
397 return ret;
398}
399
400static const struct file_operations platform_list_fops = {
401 .read = platform_list_read_file,
402 .llseek = default_llseek,/* read accesses f_pos */
403};
404
a6052154
JN
405static void soc_init_card_debugfs(struct snd_soc_card *card)
406{
407 card->debugfs_card_root = debugfs_create_dir(card->name,
8a9dab1a 408 snd_soc_debugfs_root);
3a45b867 409 if (!card->debugfs_card_root) {
a6052154 410 dev_warn(card->dev,
7c08be84 411 "ASoC: Failed to create card debugfs directory\n");
3a45b867
JN
412 return;
413 }
414
415 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
416 card->debugfs_card_root,
417 &card->pop_time);
418 if (!card->debugfs_pop_time)
419 dev_warn(card->dev,
420 "Failed to create pop time debugfs file\n");
a6052154
JN
421}
422
423static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
424{
425 debugfs_remove_recursive(card->debugfs_card_root);
426}
427
2624d5fa
MB
428#else
429
430static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
431{
432}
433
434static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
435{
436}
b95fccbc
AL
437
438static inline void soc_init_card_debugfs(struct snd_soc_card *card)
439{
440}
441
442static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
443{
444}
2624d5fa
MB
445#endif
446
db2a4165
FM
447#ifdef CONFIG_SND_SOC_AC97_BUS
448/* unregister ac97 codec */
449static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
450{
451 if (codec->ac97->dev.bus)
452 device_unregister(&codec->ac97->dev);
453 return 0;
454}
455
456/* stop no dev release warning */
457static void soc_ac97_device_release(struct device *dev){}
458
459/* register ac97 codec to bus */
460static int soc_ac97_dev_register(struct snd_soc_codec *codec)
461{
462 int err;
463
464 codec->ac97->dev.bus = &ac97_bus_type;
4ac5c61f 465 codec->ac97->dev.parent = codec->card->dev;
db2a4165
FM
466 codec->ac97->dev.release = soc_ac97_device_release;
467
bb072bf0 468 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
f0fba2ad 469 codec->card->snd_card->number, 0, codec->name);
db2a4165
FM
470 err = device_register(&codec->ac97->dev);
471 if (err < 0) {
472 snd_printk(KERN_ERR "Can't register ac97 bus\n");
473 codec->ac97->dev.bus = NULL;
474 return err;
475 }
476 return 0;
477}
478#endif
479
6f8ab4ac 480#ifdef CONFIG_PM_SLEEP
db2a4165 481/* powers down audio subsystem for suspend */
6f8ab4ac 482int snd_soc_suspend(struct device *dev)
db2a4165 483{
6f8ab4ac 484 struct snd_soc_card *card = dev_get_drvdata(dev);
2eea392d 485 struct snd_soc_codec *codec;
db2a4165
FM
486 int i;
487
e3509ff0
DM
488 /* If the initialization of this soc device failed, there is no codec
489 * associated with it. Just bail out in this case.
490 */
f0fba2ad 491 if (list_empty(&card->codec_dev_list))
e3509ff0
DM
492 return 0;
493
6ed25978
AG
494 /* Due to the resume being scheduled into a workqueue we could
495 * suspend before that's finished - wait for it to complete.
496 */
f0fba2ad
LG
497 snd_power_lock(card->snd_card);
498 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
499 snd_power_unlock(card->snd_card);
6ed25978
AG
500
501 /* we're going to block userspace touching us until resume completes */
f0fba2ad 502 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
6ed25978 503
a00f90f9 504 /* mute any active DACs */
f0fba2ad
LG
505 for (i = 0; i < card->num_rtd; i++) {
506 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
507 struct snd_soc_dai_driver *drv = dai->driver;
3efab7dc 508
f0fba2ad 509 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
510 continue;
511
f0fba2ad
LG
512 if (drv->ops->digital_mute && dai->playback_active)
513 drv->ops->digital_mute(dai, 1);
db2a4165
FM
514 }
515
4ccab3e7 516 /* suspend all pcms */
f0fba2ad
LG
517 for (i = 0; i < card->num_rtd; i++) {
518 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
519 continue;
520
f0fba2ad 521 snd_pcm_suspend_all(card->rtd[i].pcm);
3efab7dc 522 }
4ccab3e7 523
87506549 524 if (card->suspend_pre)
70b2ac12 525 card->suspend_pre(card);
db2a4165 526
f0fba2ad
LG
527 for (i = 0; i < card->num_rtd; i++) {
528 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
529 struct snd_soc_platform *platform = card->rtd[i].platform;
3efab7dc 530
f0fba2ad 531 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
532 continue;
533
f0fba2ad
LG
534 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
535 cpu_dai->driver->suspend(cpu_dai);
536 if (platform->driver->suspend && !platform->suspended) {
537 platform->driver->suspend(cpu_dai);
538 platform->suspended = 1;
539 }
db2a4165
FM
540 }
541
542 /* close any waiting streams and save state */
f0fba2ad 543 for (i = 0; i < card->num_rtd; i++) {
5b84ba26 544 flush_delayed_work_sync(&card->rtd[i].delayed_work);
ce6120cc 545 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
f0fba2ad 546 }
db2a4165 547
f0fba2ad
LG
548 for (i = 0; i < card->num_rtd; i++) {
549 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
3efab7dc 550
f0fba2ad 551 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
552 continue;
553
f0fba2ad
LG
554 if (driver->playback.stream_name != NULL)
555 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
db2a4165 556 SND_SOC_DAPM_STREAM_SUSPEND);
f0fba2ad
LG
557
558 if (driver->capture.stream_name != NULL)
559 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
db2a4165
FM
560 SND_SOC_DAPM_STREAM_SUSPEND);
561 }
562
f0fba2ad 563 /* suspend all CODECs */
2eea392d 564 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
f0fba2ad
LG
565 /* If there are paths active then the CODEC will be held with
566 * bias _ON and should not be suspended. */
567 if (!codec->suspended && codec->driver->suspend) {
ce6120cc 568 switch (codec->dapm.bias_level) {
f0fba2ad 569 case SND_SOC_BIAS_STANDBY:
125a25da
MB
570 /*
571 * If the CODEC is capable of idle
572 * bias off then being in STANDBY
573 * means it's doing something,
574 * otherwise fall through.
575 */
576 if (codec->dapm.idle_bias_off) {
577 dev_dbg(codec->dev,
578 "idle_bias_off CODEC on over suspend\n");
579 break;
580 }
f0fba2ad 581 case SND_SOC_BIAS_OFF:
84b315ee 582 codec->driver->suspend(codec);
f0fba2ad 583 codec->suspended = 1;
7be4ba24 584 codec->cache_sync = 1;
f0fba2ad
LG
585 break;
586 default:
587 dev_dbg(codec->dev, "CODEC is on over suspend\n");
588 break;
589 }
1547aba9
MB
590 }
591 }
db2a4165 592
f0fba2ad
LG
593 for (i = 0; i < card->num_rtd; i++) {
594 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3efab7dc 595
f0fba2ad 596 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
597 continue;
598
f0fba2ad
LG
599 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
600 cpu_dai->driver->suspend(cpu_dai);
db2a4165
FM
601 }
602
87506549 603 if (card->suspend_post)
70b2ac12 604 card->suspend_post(card);
db2a4165
FM
605
606 return 0;
607}
6f8ab4ac 608EXPORT_SYMBOL_GPL(snd_soc_suspend);
db2a4165 609
6ed25978
AG
610/* deferred resume work, so resume can complete before we finished
611 * setting our codec back up, which can be very slow on I2C
612 */
613static void soc_resume_deferred(struct work_struct *work)
db2a4165 614{
f0fba2ad
LG
615 struct snd_soc_card *card =
616 container_of(work, struct snd_soc_card, deferred_resume_work);
2eea392d 617 struct snd_soc_codec *codec;
db2a4165
FM
618 int i;
619
6ed25978
AG
620 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
621 * so userspace apps are blocked from touching us
622 */
623
f0fba2ad 624 dev_dbg(card->dev, "starting resume work\n");
6ed25978 625
9949788b 626 /* Bring us up into D2 so that DAPM starts enabling things */
f0fba2ad 627 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
9949788b 628
87506549 629 if (card->resume_pre)
70b2ac12 630 card->resume_pre(card);
db2a4165 631
f0fba2ad
LG
632 /* resume AC97 DAIs */
633 for (i = 0; i < card->num_rtd; i++) {
634 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3efab7dc 635
f0fba2ad 636 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
637 continue;
638
f0fba2ad
LG
639 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
640 cpu_dai->driver->resume(cpu_dai);
641 }
642
2eea392d 643 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
f0fba2ad
LG
644 /* If the CODEC was idle over suspend then it will have been
645 * left with bias OFF or STANDBY and suspended so we must now
646 * resume. Otherwise the suspend was suppressed.
647 */
648 if (codec->driver->resume && codec->suspended) {
ce6120cc 649 switch (codec->dapm.bias_level) {
f0fba2ad
LG
650 case SND_SOC_BIAS_STANDBY:
651 case SND_SOC_BIAS_OFF:
652 codec->driver->resume(codec);
653 codec->suspended = 0;
654 break;
655 default:
656 dev_dbg(codec->dev, "CODEC was on over suspend\n");
657 break;
658 }
1547aba9
MB
659 }
660 }
db2a4165 661
f0fba2ad
LG
662 for (i = 0; i < card->num_rtd; i++) {
663 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
3efab7dc 664
f0fba2ad 665 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
666 continue;
667
f0fba2ad
LG
668 if (driver->playback.stream_name != NULL)
669 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
db2a4165 670 SND_SOC_DAPM_STREAM_RESUME);
f0fba2ad
LG
671
672 if (driver->capture.stream_name != NULL)
673 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
db2a4165
FM
674 SND_SOC_DAPM_STREAM_RESUME);
675 }
676
3ff3f64b 677 /* unmute any active DACs */
f0fba2ad
LG
678 for (i = 0; i < card->num_rtd; i++) {
679 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
680 struct snd_soc_dai_driver *drv = dai->driver;
3efab7dc 681
f0fba2ad 682 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
683 continue;
684
f0fba2ad
LG
685 if (drv->ops->digital_mute && dai->playback_active)
686 drv->ops->digital_mute(dai, 0);
db2a4165
FM
687 }
688
f0fba2ad
LG
689 for (i = 0; i < card->num_rtd; i++) {
690 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
691 struct snd_soc_platform *platform = card->rtd[i].platform;
3efab7dc 692
f0fba2ad 693 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
694 continue;
695
f0fba2ad
LG
696 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
697 cpu_dai->driver->resume(cpu_dai);
698 if (platform->driver->resume && platform->suspended) {
699 platform->driver->resume(cpu_dai);
700 platform->suspended = 0;
701 }
db2a4165
FM
702 }
703
87506549 704 if (card->resume_post)
70b2ac12 705 card->resume_post(card);
db2a4165 706
f0fba2ad 707 dev_dbg(card->dev, "resume work completed\n");
6ed25978
AG
708
709 /* userspace can access us now we are back as we were before */
f0fba2ad 710 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
6ed25978
AG
711}
712
713/* powers up audio subsystem after a suspend */
6f8ab4ac 714int snd_soc_resume(struct device *dev)
6ed25978 715{
6f8ab4ac 716 struct snd_soc_card *card = dev_get_drvdata(dev);
82e14e8b 717 int i, ac97_control = 0;
b9dd94a8 718
5ff1ddf2
EM
719 /* If the initialization of this soc device failed, there is no codec
720 * associated with it. Just bail out in this case.
721 */
722 if (list_empty(&card->codec_dev_list))
723 return 0;
724
64ab9baa
MB
725 /* AC97 devices might have other drivers hanging off them so
726 * need to resume immediately. Other drivers don't have that
727 * problem and may take a substantial amount of time to resume
728 * due to I/O costs and anti-pop so handle them out of line.
729 */
f0fba2ad
LG
730 for (i = 0; i < card->num_rtd; i++) {
731 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
82e14e8b
SW
732 ac97_control |= cpu_dai->driver->ac97_control;
733 }
734 if (ac97_control) {
735 dev_dbg(dev, "Resuming AC97 immediately\n");
736 soc_resume_deferred(&card->deferred_resume_work);
737 } else {
738 dev_dbg(dev, "Scheduling resume work\n");
739 if (!schedule_work(&card->deferred_resume_work))
740 dev_err(dev, "resume work item may be lost\n");
64ab9baa 741 }
6ed25978 742
db2a4165
FM
743 return 0;
744}
6f8ab4ac 745EXPORT_SYMBOL_GPL(snd_soc_resume);
db2a4165 746#else
6f8ab4ac
MB
747#define snd_soc_suspend NULL
748#define snd_soc_resume NULL
db2a4165
FM
749#endif
750
85e7652d 751static const struct snd_soc_dai_ops null_dai_ops = {
02a06d30
BS
752};
753
f0fba2ad 754static int soc_bind_dai_link(struct snd_soc_card *card, int num)
db2a4165 755{
f0fba2ad
LG
756 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
757 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
fe3e78e0 758 struct snd_soc_codec *codec;
435c5e25 759 struct snd_soc_platform *platform;
f0fba2ad 760 struct snd_soc_dai *codec_dai, *cpu_dai;
848dd8be 761 const char *platform_name;
435c5e25 762
f0fba2ad
LG
763 if (rtd->complete)
764 return 1;
765 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
435c5e25 766
f0fba2ad
LG
767 /* do we already have the CPU DAI for this link ? */
768 if (rtd->cpu_dai) {
769 goto find_codec;
770 }
771 /* no, then find CPU DAI from registered DAIs*/
772 list_for_each_entry(cpu_dai, &dai_list, list) {
5a504963
SW
773 if (dai_link->cpu_dai_of_node) {
774 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
775 continue;
776 } else {
777 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
778 continue;
779 }
2610ab77
SW
780
781 rtd->cpu_dai = cpu_dai;
782 goto find_codec;
435c5e25 783 }
f0fba2ad
LG
784 dev_dbg(card->dev, "CPU DAI %s not registered\n",
785 dai_link->cpu_dai_name);
6308419a 786
f0fba2ad
LG
787find_codec:
788 /* do we already have the CODEC for this link ? */
789 if (rtd->codec) {
790 goto find_platform;
791 }
792
793 /* no, then find CODEC from registered CODECs*/
794 list_for_each_entry(codec, &codec_list, list) {
5a504963
SW
795 if (dai_link->codec_of_node) {
796 if (codec->dev->of_node != dai_link->codec_of_node)
797 continue;
798 } else {
799 if (strcmp(codec->name, dai_link->codec_name))
800 continue;
801 }
2610ab77
SW
802
803 rtd->codec = codec;
804
805 /*
806 * CODEC found, so find CODEC DAI from registered DAIs from
807 * this CODEC
808 */
809 list_for_each_entry(codec_dai, &dai_list, list) {
810 if (codec->dev == codec_dai->dev &&
811 !strcmp(codec_dai->name,
812 dai_link->codec_dai_name)) {
f0fba2ad 813
2610ab77
SW
814 rtd->codec_dai = codec_dai;
815 goto find_platform;
816 }
435c5e25 817 }
2610ab77
SW
818 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
819 dai_link->codec_dai_name);
820
821 goto find_platform;
f0fba2ad
LG
822 }
823 dev_dbg(card->dev, "CODEC %s not registered\n",
824 dai_link->codec_name);
6b05eda6 825
f0fba2ad 826find_platform:
848dd8be
MB
827 /* do we need a platform? */
828 if (rtd->platform)
f0fba2ad 829 goto out;
848dd8be
MB
830
831 /* if there's no platform we match on the empty platform */
832 platform_name = dai_link->platform_name;
5a504963 833 if (!platform_name && !dai_link->platform_of_node)
848dd8be
MB
834 platform_name = "snd-soc-dummy";
835
836 /* no, then find one from the set of registered platforms */
f0fba2ad 837 list_for_each_entry(platform, &platform_list, list) {
5a504963
SW
838 if (dai_link->platform_of_node) {
839 if (platform->dev->of_node !=
840 dai_link->platform_of_node)
841 continue;
842 } else {
843 if (strcmp(platform->name, platform_name))
844 continue;
845 }
2610ab77
SW
846
847 rtd->platform = platform;
848 goto out;
02a06d30
BS
849 }
850
f0fba2ad
LG
851 dev_dbg(card->dev, "platform %s not registered\n",
852 dai_link->platform_name);
853 return 0;
854
855out:
856 /* mark rtd as complete if we found all 4 of our client devices */
857 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
858 rtd->complete = 1;
859 card->num_rtd++;
860 }
861 return 1;
862}
863
589c3563
JN
864static void soc_remove_codec(struct snd_soc_codec *codec)
865{
866 int err;
867
868 if (codec->driver->remove) {
869 err = codec->driver->remove(codec);
870 if (err < 0)
871 dev_err(codec->dev,
872 "asoc: failed to remove %s: %d\n",
873 codec->name, err);
874 }
875
876 /* Make sure all DAPM widgets are freed */
877 snd_soc_dapm_free(&codec->dapm);
878
879 soc_cleanup_codec_debugfs(codec);
880 codec->probed = 0;
881 list_del(&codec->card_list);
882 module_put(codec->dev->driver->owner);
883}
884
0168bf0d 885static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
f0fba2ad
LG
886{
887 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
888 struct snd_soc_codec *codec = rtd->codec;
889 struct snd_soc_platform *platform = rtd->platform;
890 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
891 int err;
892
893 /* unregister the rtd device */
894 if (rtd->dev_registered) {
36ae1a96
MB
895 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
896 device_remove_file(rtd->dev, &dev_attr_codec_reg);
897 device_unregister(rtd->dev);
f0fba2ad
LG
898 rtd->dev_registered = 0;
899 }
900
901 /* remove the CODEC DAI */
0168bf0d
LG
902 if (codec_dai && codec_dai->probed &&
903 codec_dai->driver->remove_order == order) {
f0fba2ad
LG
904 if (codec_dai->driver->remove) {
905 err = codec_dai->driver->remove(codec_dai);
906 if (err < 0)
907 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
6b05eda6 908 }
f0fba2ad
LG
909 codec_dai->probed = 0;
910 list_del(&codec_dai->card_list);
911 }
6b05eda6 912
f0fba2ad 913 /* remove the platform */
0168bf0d
LG
914 if (platform && platform->probed &&
915 platform->driver->remove_order == order) {
f0fba2ad
LG
916 if (platform->driver->remove) {
917 err = platform->driver->remove(platform);
918 if (err < 0)
919 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
920 }
675c496b
LG
921
922 /* Make sure all DAPM widgets are freed */
923 snd_soc_dapm_free(&platform->dapm);
924
f0fba2ad
LG
925 platform->probed = 0;
926 list_del(&platform->card_list);
927 module_put(platform->dev->driver->owner);
928 }
435c5e25 929
f0fba2ad 930 /* remove the CODEC */
0168bf0d
LG
931 if (codec && codec->probed &&
932 codec->driver->remove_order == order)
589c3563 933 soc_remove_codec(codec);
db2a4165 934
f0fba2ad 935 /* remove the cpu_dai */
0168bf0d
LG
936 if (cpu_dai && cpu_dai->probed &&
937 cpu_dai->driver->remove_order == order) {
f0fba2ad
LG
938 if (cpu_dai->driver->remove) {
939 err = cpu_dai->driver->remove(cpu_dai);
940 if (err < 0)
941 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
db2a4165 942 }
f0fba2ad
LG
943 cpu_dai->probed = 0;
944 list_del(&cpu_dai->card_list);
945 module_put(cpu_dai->dev->driver->owner);
db2a4165 946 }
f0fba2ad 947}
db2a4165 948
0671fd8e
KM
949static void soc_remove_dai_links(struct snd_soc_card *card)
950{
0168bf0d 951 int dai, order;
0671fd8e 952
0168bf0d
LG
953 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
954 order++) {
955 for (dai = 0; dai < card->num_rtd; dai++)
956 soc_remove_dai_link(card, dai, order);
957 }
0671fd8e
KM
958 card->num_rtd = 0;
959}
960
ead9b919
JN
961static void soc_set_name_prefix(struct snd_soc_card *card,
962 struct snd_soc_codec *codec)
963{
964 int i;
965
ff819b83 966 if (card->codec_conf == NULL)
ead9b919
JN
967 return;
968
ff819b83
DP
969 for (i = 0; i < card->num_configs; i++) {
970 struct snd_soc_codec_conf *map = &card->codec_conf[i];
ead9b919
JN
971 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
972 codec->name_prefix = map->name_prefix;
973 break;
974 }
975 }
976}
977
589c3563
JN
978static int soc_probe_codec(struct snd_soc_card *card,
979 struct snd_soc_codec *codec)
980{
981 int ret = 0;
89b95ac0 982 const struct snd_soc_codec_driver *driver = codec->driver;
589c3563
JN
983
984 codec->card = card;
985 codec->dapm.card = card;
986 soc_set_name_prefix(card, codec);
987
70d29331
JN
988 if (!try_module_get(codec->dev->driver->owner))
989 return -ENODEV;
990
d5d1e0be
LPC
991 soc_init_codec_debugfs(codec);
992
77530150
LPC
993 if (driver->dapm_widgets)
994 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
995 driver->num_dapm_widgets);
996
33c5f969
MB
997 codec->dapm.idle_bias_off = driver->idle_bias_off;
998
89b95ac0
MB
999 if (driver->probe) {
1000 ret = driver->probe(codec);
589c3563
JN
1001 if (ret < 0) {
1002 dev_err(codec->dev,
1003 "asoc: failed to probe CODEC %s: %d\n",
1004 codec->name, ret);
70d29331 1005 goto err_probe;
589c3563
JN
1006 }
1007 }
1008
b7af1daf 1009 if (driver->controls)
022658be 1010 snd_soc_add_codec_controls(codec, driver->controls,
b7af1daf 1011 driver->num_controls);
89b95ac0
MB
1012 if (driver->dapm_routes)
1013 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1014 driver->num_dapm_routes);
1015
589c3563
JN
1016 /* mark codec as probed and add to card codec list */
1017 codec->probed = 1;
1018 list_add(&codec->card_list, &card->codec_dev_list);
7be31be8 1019 list_add(&codec->dapm.list, &card->dapm_list);
589c3563 1020
70d29331
JN
1021 return 0;
1022
1023err_probe:
d5d1e0be 1024 soc_cleanup_codec_debugfs(codec);
70d29331
JN
1025 module_put(codec->dev->driver->owner);
1026
589c3563
JN
1027 return ret;
1028}
1029
956245e9
LG
1030static int soc_probe_platform(struct snd_soc_card *card,
1031 struct snd_soc_platform *platform)
1032{
1033 int ret = 0;
1034 const struct snd_soc_platform_driver *driver = platform->driver;
1035
1036 platform->card = card;
b7950641 1037 platform->dapm.card = card;
956245e9
LG
1038
1039 if (!try_module_get(platform->dev->driver->owner))
1040 return -ENODEV;
1041
cb2cf612
LG
1042 if (driver->dapm_widgets)
1043 snd_soc_dapm_new_controls(&platform->dapm,
1044 driver->dapm_widgets, driver->num_dapm_widgets);
1045
956245e9
LG
1046 if (driver->probe) {
1047 ret = driver->probe(platform);
1048 if (ret < 0) {
1049 dev_err(platform->dev,
1050 "asoc: failed to probe platform %s: %d\n",
1051 platform->name, ret);
1052 goto err_probe;
1053 }
1054 }
1055
cb2cf612
LG
1056 if (driver->controls)
1057 snd_soc_add_platform_controls(platform, driver->controls,
1058 driver->num_controls);
1059 if (driver->dapm_routes)
1060 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1061 driver->num_dapm_routes);
1062
956245e9
LG
1063 /* mark platform as probed and add to card platform list */
1064 platform->probed = 1;
1065 list_add(&platform->card_list, &card->platform_dev_list);
b7950641 1066 list_add(&platform->dapm.list, &card->dapm_list);
956245e9
LG
1067
1068 return 0;
1069
1070err_probe:
1071 module_put(platform->dev->driver->owner);
1072
1073 return ret;
1074}
1075
36ae1a96
MB
1076static void rtd_release(struct device *dev)
1077{
1078 kfree(dev);
1079}
f0fba2ad 1080
589c3563
JN
1081static int soc_post_component_init(struct snd_soc_card *card,
1082 struct snd_soc_codec *codec,
1083 int num, int dailess)
1084{
1085 struct snd_soc_dai_link *dai_link = NULL;
1086 struct snd_soc_aux_dev *aux_dev = NULL;
1087 struct snd_soc_pcm_runtime *rtd;
1088 const char *temp, *name;
1089 int ret = 0;
1090
1091 if (!dailess) {
1092 dai_link = &card->dai_link[num];
1093 rtd = &card->rtd[num];
1094 name = dai_link->name;
1095 } else {
1096 aux_dev = &card->aux_dev[num];
1097 rtd = &card->rtd_aux[num];
1098 name = aux_dev->name;
1099 }
0962bb21 1100 rtd->card = card;
589c3563 1101
4b1cfcb4
MB
1102 /* Make sure all DAPM widgets are instantiated */
1103 snd_soc_dapm_new_widgets(&codec->dapm);
1104
589c3563
JN
1105 /* machine controls, routes and widgets are not prefixed */
1106 temp = codec->name_prefix;
1107 codec->name_prefix = NULL;
1108
1109 /* do machine specific initialization */
1110 if (!dailess && dai_link->init)
1111 ret = dai_link->init(rtd);
1112 else if (dailess && aux_dev->init)
1113 ret = aux_dev->init(&codec->dapm);
1114 if (ret < 0) {
1115 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1116 return ret;
1117 }
1118 codec->name_prefix = temp;
1119
589c3563
JN
1120 /* register the rtd device */
1121 rtd->codec = codec;
36ae1a96
MB
1122
1123 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1124 if (!rtd->dev)
1125 return -ENOMEM;
1126 device_initialize(rtd->dev);
1127 rtd->dev->parent = card->dev;
1128 rtd->dev->release = rtd_release;
1129 rtd->dev->init_name = name;
1130 dev_set_drvdata(rtd->dev, rtd);
b8c0dab9 1131 mutex_init(&rtd->pcm_mutex);
36ae1a96 1132 ret = device_add(rtd->dev);
589c3563
JN
1133 if (ret < 0) {
1134 dev_err(card->dev,
1135 "asoc: failed to register runtime device: %d\n", ret);
1136 return ret;
1137 }
1138 rtd->dev_registered = 1;
1139
1140 /* add DAPM sysfs entries for this codec */
36ae1a96 1141 ret = snd_soc_dapm_sys_add(rtd->dev);
589c3563
JN
1142 if (ret < 0)
1143 dev_err(codec->dev,
1144 "asoc: failed to add codec dapm sysfs entries: %d\n",
1145 ret);
1146
1147 /* add codec sysfs entries */
36ae1a96 1148 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
589c3563
JN
1149 if (ret < 0)
1150 dev_err(codec->dev,
1151 "asoc: failed to add codec sysfs files: %d\n", ret);
1152
1153 return 0;
1154}
1155
0168bf0d 1156static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
f0fba2ad
LG
1157{
1158 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1159 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1160 struct snd_soc_codec *codec = rtd->codec;
1161 struct snd_soc_platform *platform = rtd->platform;
1162 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1163 int ret;
1164
0168bf0d
LG
1165 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1166 card->name, num, order);
f0fba2ad
LG
1167
1168 /* config components */
1169 codec_dai->codec = codec;
f0fba2ad 1170 cpu_dai->platform = platform;
f0fba2ad
LG
1171 codec_dai->card = card;
1172 cpu_dai->card = card;
1173
1174 /* set default power off timeout */
1175 rtd->pmdown_time = pmdown_time;
1176
1177 /* probe the cpu_dai */
0168bf0d
LG
1178 if (!cpu_dai->probed &&
1179 cpu_dai->driver->probe_order == order) {
61b61e3c
LG
1180 if (!try_module_get(cpu_dai->dev->driver->owner))
1181 return -ENODEV;
1182
f0fba2ad
LG
1183 if (cpu_dai->driver->probe) {
1184 ret = cpu_dai->driver->probe(cpu_dai);
1185 if (ret < 0) {
1186 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1187 cpu_dai->name);
61b61e3c 1188 module_put(cpu_dai->dev->driver->owner);
f0fba2ad
LG
1189 return ret;
1190 }
1191 }
1192 cpu_dai->probed = 1;
1c8371d6 1193 /* mark cpu_dai as probed and add to card dai list */
f0fba2ad 1194 list_add(&cpu_dai->card_list, &card->dai_dev_list);
db2a4165
FM
1195 }
1196
f0fba2ad 1197 /* probe the CODEC */
0168bf0d
LG
1198 if (!codec->probed &&
1199 codec->driver->probe_order == order) {
589c3563
JN
1200 ret = soc_probe_codec(card, codec);
1201 if (ret < 0)
1202 return ret;
db2a4165
FM
1203 }
1204
f0fba2ad 1205 /* probe the platform */
0168bf0d
LG
1206 if (!platform->probed &&
1207 platform->driver->probe_order == order) {
956245e9
LG
1208 ret = soc_probe_platform(card, platform);
1209 if (ret < 0)
1210 return ret;
f0fba2ad 1211 }
6ed25978 1212
f0fba2ad 1213 /* probe the CODEC DAI */
0168bf0d 1214 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
f0fba2ad
LG
1215 if (codec_dai->driver->probe) {
1216 ret = codec_dai->driver->probe(codec_dai);
fe3e78e0 1217 if (ret < 0) {
f0fba2ad
LG
1218 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1219 codec_dai->name);
1220 return ret;
fe3e78e0
MB
1221 }
1222 }
f0fba2ad 1223
1c8371d6 1224 /* mark codec_dai as probed and add to card dai list */
f0fba2ad
LG
1225 codec_dai->probed = 1;
1226 list_add(&codec_dai->card_list, &card->dai_dev_list);
fe3e78e0
MB
1227 }
1228
0168bf0d
LG
1229 /* complete DAI probe during last probe */
1230 if (order != SND_SOC_COMP_ORDER_LAST)
1231 return 0;
1232
589c3563
JN
1233 ret = soc_post_component_init(card, codec, num, 0);
1234 if (ret)
f0fba2ad 1235 return ret;
fe3e78e0 1236
36ae1a96 1237 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
f0fba2ad
LG
1238 if (ret < 0)
1239 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1240
f0fba2ad
LG
1241 /* create the pcm */
1242 ret = soc_new_pcm(rtd, num);
1243 if (ret < 0) {
1244 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1245 return ret;
1246 }
1247
1248 /* add platform data for AC97 devices */
1249 if (rtd->codec_dai->driver->ac97_control)
1250 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1251
1252 return 0;
1253}
1254
fe3e78e0 1255#ifdef CONFIG_SND_SOC_AC97_BUS
f0fba2ad
LG
1256static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1257{
1258 int ret;
1259
fe3e78e0
MB
1260 /* Only instantiate AC97 if not already done by the adaptor
1261 * for the generic AC97 subsystem.
1262 */
f0fba2ad 1263 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
0562f788
MW
1264 /*
1265 * It is possible that the AC97 device is already registered to
1266 * the device subsystem. This happens when the device is created
1267 * via snd_ac97_mixer(). Currently only SoC codec that does so
1268 * is the generic AC97 glue but others migh emerge.
1269 *
1270 * In those cases we don't try to register the device again.
1271 */
1272 if (!rtd->codec->ac97_created)
1273 return 0;
f0fba2ad
LG
1274
1275 ret = soc_ac97_dev_register(rtd->codec);
fe3e78e0
MB
1276 if (ret < 0) {
1277 printk(KERN_ERR "asoc: AC97 device register failed\n");
f0fba2ad 1278 return ret;
fe3e78e0 1279 }
f0fba2ad
LG
1280
1281 rtd->codec->ac97_registered = 1;
fe3e78e0 1282 }
f0fba2ad
LG
1283 return 0;
1284}
1285
1286static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1287{
1288 if (codec->ac97_registered) {
1289 soc_ac97_dev_unregister(codec);
1290 codec->ac97_registered = 0;
1291 }
1292}
fe3e78e0
MB
1293#endif
1294
2eea392d
JN
1295static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1296{
1297 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
2eea392d 1298 struct snd_soc_codec *codec;
676ad98a 1299 int ret = -ENODEV;
2eea392d
JN
1300
1301 /* find CODEC from registered CODECs*/
1302 list_for_each_entry(codec, &codec_list, list) {
1303 if (!strcmp(codec->name, aux_dev->codec_name)) {
1304 if (codec->probed) {
1305 dev_err(codec->dev,
1306 "asoc: codec already probed");
1307 ret = -EBUSY;
1308 goto out;
1309 }
676ad98a 1310 goto found;
2eea392d
JN
1311 }
1312 }
676ad98a
JN
1313 /* codec not found */
1314 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1315 goto out;
2eea392d 1316
676ad98a 1317found:
589c3563 1318 ret = soc_probe_codec(card, codec);
2eea392d 1319 if (ret < 0)
589c3563 1320 return ret;
2eea392d 1321
589c3563 1322 ret = soc_post_component_init(card, codec, num, 1);
2eea392d
JN
1323
1324out:
1325 return ret;
1326}
1327
1328static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1329{
1330 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1331 struct snd_soc_codec *codec = rtd->codec;
2eea392d
JN
1332
1333 /* unregister the rtd device */
1334 if (rtd->dev_registered) {
36ae1a96
MB
1335 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1336 device_del(rtd->dev);
2eea392d
JN
1337 rtd->dev_registered = 0;
1338 }
1339
589c3563
JN
1340 if (codec && codec->probed)
1341 soc_remove_codec(codec);
2eea392d
JN
1342}
1343
fdf0f54d
DP
1344static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1345 enum snd_soc_compress_type compress_type)
1346{
1347 int ret;
1348
1349 if (codec->cache_init)
1350 return 0;
1351
1352 /* override the compress_type if necessary */
1353 if (compress_type && codec->compress_type != compress_type)
1354 codec->compress_type = compress_type;
fdf0f54d
DP
1355 ret = snd_soc_cache_init(codec);
1356 if (ret < 0) {
1357 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1358 ret);
1359 return ret;
1360 }
1361 codec->cache_init = 1;
1362 return 0;
1363}
1364
f0fba2ad
LG
1365static void snd_soc_instantiate_card(struct snd_soc_card *card)
1366{
fdf0f54d
DP
1367 struct snd_soc_codec *codec;
1368 struct snd_soc_codec_conf *codec_conf;
1369 enum snd_soc_compress_type compress_type;
75d9ac46 1370 struct snd_soc_dai_link *dai_link;
0168bf0d 1371 int ret, i, order;
fe3e78e0 1372
f0fba2ad 1373 mutex_lock(&card->mutex);
dbe21408 1374
f0fba2ad
LG
1375 if (card->instantiated) {
1376 mutex_unlock(&card->mutex);
1377 return;
1378 }
fe3e78e0 1379
f0fba2ad
LG
1380 /* bind DAIs */
1381 for (i = 0; i < card->num_links; i++)
1382 soc_bind_dai_link(card, i);
fe3e78e0 1383
f0fba2ad
LG
1384 /* bind completed ? */
1385 if (card->num_rtd != card->num_links) {
1386 mutex_unlock(&card->mutex);
1387 return;
1388 }
435c5e25 1389
fdf0f54d
DP
1390 /* initialize the register cache for each available codec */
1391 list_for_each_entry(codec, &codec_list, list) {
1392 if (codec->cache_init)
1393 continue;
861f2faf
DP
1394 /* by default we don't override the compress_type */
1395 compress_type = 0;
fdf0f54d
DP
1396 /* check to see if we need to override the compress_type */
1397 for (i = 0; i < card->num_configs; ++i) {
1398 codec_conf = &card->codec_conf[i];
1399 if (!strcmp(codec->name, codec_conf->dev_name)) {
1400 compress_type = codec_conf->compress_type;
1401 if (compress_type && compress_type
1402 != codec->compress_type)
1403 break;
1404 }
1405 }
fdf0f54d
DP
1406 ret = snd_soc_init_codec_cache(codec, compress_type);
1407 if (ret < 0) {
1408 mutex_unlock(&card->mutex);
1409 return;
1410 }
1411 }
1412
f0fba2ad
LG
1413 /* card bind complete so register a sound card */
1414 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1415 card->owner, 0, &card->snd_card);
1416 if (ret < 0) {
1417 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1418 card->name);
1419 mutex_unlock(&card->mutex);
1420 return;
1421 }
1422 card->snd_card->dev = card->dev;
1423
e37a4970
MB
1424 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1425 card->dapm.dev = card->dev;
1426 card->dapm.card = card;
1427 list_add(&card->dapm.list, &card->dapm_list);
1428
d5d1e0be
LPC
1429#ifdef CONFIG_DEBUG_FS
1430 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1431#endif
1432
88ee1c61 1433#ifdef CONFIG_PM_SLEEP
f0fba2ad
LG
1434 /* deferred resume work */
1435 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1436#endif
db2a4165 1437
9a841ebb
MB
1438 if (card->dapm_widgets)
1439 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1440 card->num_dapm_widgets);
1441
f0fba2ad
LG
1442 /* initialise the sound card only once */
1443 if (card->probe) {
e7361ec4 1444 ret = card->probe(card);
f0fba2ad
LG
1445 if (ret < 0)
1446 goto card_probe_error;
1447 }
fe3e78e0 1448
0168bf0d
LG
1449 /* early DAI link probe */
1450 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1451 order++) {
1452 for (i = 0; i < card->num_links; i++) {
1453 ret = soc_probe_dai_link(card, i, order);
1454 if (ret < 0) {
1455 pr_err("asoc: failed to instantiate card %s: %d\n",
321de0d0 1456 card->name, ret);
0168bf0d
LG
1457 goto probe_dai_err;
1458 }
f0fba2ad
LG
1459 }
1460 }
db2a4165 1461
2eea392d
JN
1462 for (i = 0; i < card->num_aux_devs; i++) {
1463 ret = soc_probe_aux_dev(card, i);
1464 if (ret < 0) {
1465 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1466 card->name, ret);
1467 goto probe_aux_dev_err;
1468 }
1469 }
1470
b7af1daf 1471 if (card->controls)
022658be 1472 snd_soc_add_card_controls(card, card->controls, card->num_controls);
b7af1daf 1473
b8ad29de
MB
1474 if (card->dapm_routes)
1475 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1476 card->num_dapm_routes);
1477
b90d2f90
MB
1478 snd_soc_dapm_new_widgets(&card->dapm);
1479
75d9ac46
MB
1480 for (i = 0; i < card->num_links; i++) {
1481 dai_link = &card->dai_link[i];
1482
1483 if (dai_link->dai_fmt) {
1484 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1485 dai_link->dai_fmt);
1486 if (ret != 0)
1487 dev_warn(card->rtd[i].codec_dai->dev,
1488 "Failed to set DAI format: %d\n",
1489 ret);
1490
1491 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1492 dai_link->dai_fmt);
1493 if (ret != 0)
1494 dev_warn(card->rtd[i].cpu_dai->dev,
1495 "Failed to set DAI format: %d\n",
1496 ret);
1497 }
1498 }
1499
f0fba2ad 1500 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
f0fba2ad 1501 "%s", card->name);
22de71ba
LG
1502 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1503 "%s", card->long_name ? card->long_name : card->name);
f0e8ed85
MB
1504 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1505 "%s", card->driver_name ? card->driver_name : card->name);
1506 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1507 switch (card->snd_card->driver[i]) {
1508 case '_':
1509 case '-':
1510 case '\0':
1511 break;
1512 default:
1513 if (!isalnum(card->snd_card->driver[i]))
1514 card->snd_card->driver[i] = '_';
1515 break;
1516 }
1517 }
f0fba2ad 1518
28e9ad92
MB
1519 if (card->late_probe) {
1520 ret = card->late_probe(card);
1521 if (ret < 0) {
1522 dev_err(card->dev, "%s late_probe() failed: %d\n",
1523 card->name, ret);
1524 goto probe_aux_dev_err;
1525 }
1526 }
1527
2dc00213
MB
1528 snd_soc_dapm_new_widgets(&card->dapm);
1529
1633281b 1530 if (card->fully_routed)
b05d8dc1 1531 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1633281b
SW
1532 snd_soc_dapm_auto_nc_codec_pins(codec);
1533
f0fba2ad
LG
1534 ret = snd_card_register(card->snd_card);
1535 if (ret < 0) {
1536 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
6b3ed785 1537 goto probe_aux_dev_err;
db2a4165
FM
1538 }
1539
f0fba2ad
LG
1540#ifdef CONFIG_SND_SOC_AC97_BUS
1541 /* register any AC97 codecs */
1542 for (i = 0; i < card->num_rtd; i++) {
6b3ed785
AL
1543 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1544 if (ret < 0) {
1545 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1546 while (--i >= 0)
7d8316df 1547 soc_unregister_ac97_dai_link(card->rtd[i].codec);
6b3ed785 1548 goto probe_aux_dev_err;
f0fba2ad 1549 }
6b3ed785 1550 }
f0fba2ad
LG
1551#endif
1552
1553 card->instantiated = 1;
4f4c0072 1554 snd_soc_dapm_sync(&card->dapm);
f0fba2ad
LG
1555 mutex_unlock(&card->mutex);
1556 return;
1557
2eea392d
JN
1558probe_aux_dev_err:
1559 for (i = 0; i < card->num_aux_devs; i++)
1560 soc_remove_aux_dev(card, i);
1561
f0fba2ad 1562probe_dai_err:
0671fd8e 1563 soc_remove_dai_links(card);
f0fba2ad
LG
1564
1565card_probe_error:
87506549 1566 if (card->remove)
e7361ec4 1567 card->remove(card);
f0fba2ad
LG
1568
1569 snd_card_free(card->snd_card);
1570
1571 mutex_unlock(&card->mutex);
435c5e25 1572}
db2a4165 1573
435c5e25 1574/*
421f91d2 1575 * Attempt to initialise any uninitialised cards. Must be called with
435c5e25
MB
1576 * client_mutex.
1577 */
1578static void snd_soc_instantiate_cards(void)
1579{
1580 struct snd_soc_card *card;
1581 list_for_each_entry(card, &card_list, list)
1582 snd_soc_instantiate_card(card);
1583}
1584
1585/* probes a new socdev */
1586static int soc_probe(struct platform_device *pdev)
1587{
f0fba2ad 1588 struct snd_soc_card *card = platform_get_drvdata(pdev);
435c5e25 1589 int ret = 0;
435c5e25 1590
70a7ca34
VK
1591 /*
1592 * no card, so machine driver should be registering card
1593 * we should not be here in that case so ret error
1594 */
1595 if (!card)
1596 return -EINVAL;
1597
435c5e25
MB
1598 /* Bodge while we unpick instantiation */
1599 card->dev = &pdev->dev;
f0fba2ad 1600
435c5e25
MB
1601 ret = snd_soc_register_card(card);
1602 if (ret != 0) {
1603 dev_err(&pdev->dev, "Failed to register card\n");
1604 return ret;
1605 }
1606
1607 return 0;
db2a4165
FM
1608}
1609
b0e26485 1610static int soc_cleanup_card_resources(struct snd_soc_card *card)
db2a4165
FM
1611{
1612 int i;
db2a4165 1613
b0e26485
VK
1614 /* make sure any delayed work runs */
1615 for (i = 0; i < card->num_rtd; i++) {
1616 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1617 flush_delayed_work_sync(&rtd->delayed_work);
1618 }
914dc182 1619
b0e26485
VK
1620 /* remove auxiliary devices */
1621 for (i = 0; i < card->num_aux_devs; i++)
1622 soc_remove_aux_dev(card, i);
db2a4165 1623
b0e26485 1624 /* remove and free each DAI */
0671fd8e 1625 soc_remove_dai_links(card);
2eea392d 1626
b0e26485 1627 soc_cleanup_card_debugfs(card);
f0fba2ad 1628
b0e26485
VK
1629 /* remove the card */
1630 if (card->remove)
e7361ec4 1631 card->remove(card);
a6052154 1632
0aaae527
LPC
1633 snd_soc_dapm_free(&card->dapm);
1634
b0e26485
VK
1635 kfree(card->rtd);
1636 snd_card_free(card->snd_card);
1637 return 0;
1638
1639}
1640
1641/* removes a socdev */
1642static int soc_remove(struct platform_device *pdev)
1643{
1644 struct snd_soc_card *card = platform_get_drvdata(pdev);
db2a4165 1645
c5af3a2e 1646 snd_soc_unregister_card(card);
db2a4165
FM
1647 return 0;
1648}
1649
6f8ab4ac 1650int snd_soc_poweroff(struct device *dev)
51737470 1651{
6f8ab4ac 1652 struct snd_soc_card *card = dev_get_drvdata(dev);
f0fba2ad 1653 int i;
51737470
MB
1654
1655 if (!card->instantiated)
416356fc 1656 return 0;
51737470
MB
1657
1658 /* Flush out pmdown_time work - we actually do want to run it
1659 * now, we're shutting down so no imminent restart. */
f0fba2ad
LG
1660 for (i = 0; i < card->num_rtd; i++) {
1661 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
5b84ba26 1662 flush_delayed_work_sync(&rtd->delayed_work);
f0fba2ad 1663 }
51737470 1664
f0fba2ad 1665 snd_soc_dapm_shutdown(card);
416356fc
MB
1666
1667 return 0;
51737470 1668}
6f8ab4ac 1669EXPORT_SYMBOL_GPL(snd_soc_poweroff);
51737470 1670
6f8ab4ac 1671const struct dev_pm_ops snd_soc_pm_ops = {
5aa44b13 1672 SET_SYSTEM_SLEEP_PM_OPS(snd_soc_suspend, snd_soc_resume)
6f8ab4ac 1673 .poweroff = snd_soc_poweroff,
416356fc 1674};
deb2607e 1675EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
416356fc 1676
db2a4165
FM
1677/* ASoC platform driver */
1678static struct platform_driver soc_driver = {
1679 .driver = {
1680 .name = "soc-audio",
8b45a209 1681 .owner = THIS_MODULE,
6f8ab4ac 1682 .pm = &snd_soc_pm_ops,
db2a4165
FM
1683 },
1684 .probe = soc_probe,
1685 .remove = soc_remove,
db2a4165
FM
1686};
1687
096e49d5
MB
1688/**
1689 * snd_soc_codec_volatile_register: Report if a register is volatile.
1690 *
1691 * @codec: CODEC to query.
1692 * @reg: Register to query.
1693 *
1694 * Boolean function indiciating if a CODEC register is volatile.
1695 */
181e055e
MB
1696int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1697 unsigned int reg)
096e49d5 1698{
1500b7b5
DP
1699 if (codec->volatile_register)
1700 return codec->volatile_register(codec, reg);
096e49d5
MB
1701 else
1702 return 0;
1703}
1704EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1705
239c9706
DP
1706/**
1707 * snd_soc_codec_readable_register: Report if a register is readable.
1708 *
1709 * @codec: CODEC to query.
1710 * @reg: Register to query.
1711 *
1712 * Boolean function indicating if a CODEC register is readable.
1713 */
1714int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1715 unsigned int reg)
1716{
1717 if (codec->readable_register)
1718 return codec->readable_register(codec, reg);
1719 else
63fa0a28 1720 return 1;
239c9706
DP
1721}
1722EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1723
1724/**
1725 * snd_soc_codec_writable_register: Report if a register is writable.
1726 *
1727 * @codec: CODEC to query.
1728 * @reg: Register to query.
1729 *
1730 * Boolean function indicating if a CODEC register is writable.
1731 */
1732int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1733 unsigned int reg)
1734{
1735 if (codec->writable_register)
1736 return codec->writable_register(codec, reg);
1737 else
63fa0a28 1738 return 1;
239c9706
DP
1739}
1740EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1741
f1442bc1
LG
1742int snd_soc_platform_read(struct snd_soc_platform *platform,
1743 unsigned int reg)
1744{
1745 unsigned int ret;
1746
1747 if (!platform->driver->read) {
1748 dev_err(platform->dev, "platform has no read back\n");
1749 return -1;
1750 }
1751
1752 ret = platform->driver->read(platform, reg);
1753 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
a82ce2ae 1754 trace_snd_soc_preg_read(platform, reg, ret);
f1442bc1
LG
1755
1756 return ret;
1757}
1758EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1759
1760int snd_soc_platform_write(struct snd_soc_platform *platform,
1761 unsigned int reg, unsigned int val)
1762{
1763 if (!platform->driver->write) {
1764 dev_err(platform->dev, "platform has no write back\n");
1765 return -1;
1766 }
1767
1768 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
a82ce2ae 1769 trace_snd_soc_preg_write(platform, reg, val);
f1442bc1
LG
1770 return platform->driver->write(platform, reg, val);
1771}
1772EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1773
db2a4165
FM
1774/**
1775 * snd_soc_new_ac97_codec - initailise AC97 device
1776 * @codec: audio codec
1777 * @ops: AC97 bus operations
1778 * @num: AC97 codec number
1779 *
1780 * Initialises AC97 codec resources for use by ad-hoc devices only.
1781 */
1782int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1783 struct snd_ac97_bus_ops *ops, int num)
1784{
1785 mutex_lock(&codec->mutex);
1786
1787 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1788 if (codec->ac97 == NULL) {
1789 mutex_unlock(&codec->mutex);
1790 return -ENOMEM;
1791 }
1792
1793 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1794 if (codec->ac97->bus == NULL) {
1795 kfree(codec->ac97);
1796 codec->ac97 = NULL;
1797 mutex_unlock(&codec->mutex);
1798 return -ENOMEM;
1799 }
1800
1801 codec->ac97->bus->ops = ops;
1802 codec->ac97->num = num;
0562f788
MW
1803
1804 /*
1805 * Mark the AC97 device to be created by us. This way we ensure that the
1806 * device will be registered with the device subsystem later on.
1807 */
1808 codec->ac97_created = 1;
1809
db2a4165
FM
1810 mutex_unlock(&codec->mutex);
1811 return 0;
1812}
1813EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1814
1815/**
1816 * snd_soc_free_ac97_codec - free AC97 codec device
1817 * @codec: audio codec
1818 *
1819 * Frees AC97 codec device resources.
1820 */
1821void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1822{
1823 mutex_lock(&codec->mutex);
f0fba2ad
LG
1824#ifdef CONFIG_SND_SOC_AC97_BUS
1825 soc_unregister_ac97_dai_link(codec);
1826#endif
db2a4165
FM
1827 kfree(codec->ac97->bus);
1828 kfree(codec->ac97);
1829 codec->ac97 = NULL;
0562f788 1830 codec->ac97_created = 0;
db2a4165
FM
1831 mutex_unlock(&codec->mutex);
1832}
1833EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1834
c3753707
MB
1835unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1836{
1837 unsigned int ret;
1838
c3acec26 1839 ret = codec->read(codec, reg);
c3753707 1840 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
a8b1d34f 1841 trace_snd_soc_reg_read(codec, reg, ret);
c3753707
MB
1842
1843 return ret;
1844}
1845EXPORT_SYMBOL_GPL(snd_soc_read);
1846
1847unsigned int snd_soc_write(struct snd_soc_codec *codec,
1848 unsigned int reg, unsigned int val)
1849{
1850 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
a8b1d34f 1851 trace_snd_soc_reg_write(codec, reg, val);
c3acec26 1852 return codec->write(codec, reg, val);
c3753707
MB
1853}
1854EXPORT_SYMBOL_GPL(snd_soc_write);
1855
5fb609d4
DP
1856unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1857 unsigned int reg, const void *data, size_t len)
1858{
1859 return codec->bulk_write_raw(codec, reg, data, len);
1860}
1861EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1862
db2a4165
FM
1863/**
1864 * snd_soc_update_bits - update codec register bits
1865 * @codec: audio codec
1866 * @reg: codec register
1867 * @mask: register mask
1868 * @value: new value
1869 *
1870 * Writes new register value.
1871 *
180c329d 1872 * Returns 1 for change, 0 for no change, or negative error code.
db2a4165
FM
1873 */
1874int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
46f5822f 1875 unsigned int mask, unsigned int value)
db2a4165 1876{
8a713da8 1877 bool change;
46f5822f 1878 unsigned int old, new;
180c329d
TT
1879 int ret;
1880
8a713da8
MB
1881 if (codec->using_regmap) {
1882 ret = regmap_update_bits_check(codec->control_data, reg,
1883 mask, value, &change);
1884 } else {
1885 ret = snd_soc_read(codec, reg);
180c329d
TT
1886 if (ret < 0)
1887 return ret;
8a713da8
MB
1888
1889 old = ret;
1890 new = (old & ~mask) | (value & mask);
1891 change = old != new;
1892 if (change)
1893 ret = snd_soc_write(codec, reg, new);
180c329d 1894 }
db2a4165 1895
8a713da8
MB
1896 if (ret < 0)
1897 return ret;
1898
db2a4165
FM
1899 return change;
1900}
1901EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1902
6c508c62
EN
1903/**
1904 * snd_soc_update_bits_locked - update codec register bits
1905 * @codec: audio codec
1906 * @reg: codec register
1907 * @mask: register mask
1908 * @value: new value
1909 *
1910 * Writes new register value, and takes the codec mutex.
1911 *
1912 * Returns 1 for change else 0.
1913 */
dd1b3d53
MB
1914int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1915 unsigned short reg, unsigned int mask,
1916 unsigned int value)
6c508c62
EN
1917{
1918 int change;
1919
1920 mutex_lock(&codec->mutex);
1921 change = snd_soc_update_bits(codec, reg, mask, value);
1922 mutex_unlock(&codec->mutex);
1923
1924 return change;
1925}
dd1b3d53 1926EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
6c508c62 1927
db2a4165
FM
1928/**
1929 * snd_soc_test_bits - test register for change
1930 * @codec: audio codec
1931 * @reg: codec register
1932 * @mask: register mask
1933 * @value: new value
1934 *
1935 * Tests a register with a new value and checks if the new value is
1936 * different from the old value.
1937 *
1938 * Returns 1 for change else 0.
1939 */
1940int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
46f5822f 1941 unsigned int mask, unsigned int value)
db2a4165
FM
1942{
1943 int change;
46f5822f 1944 unsigned int old, new;
db2a4165 1945
db2a4165
FM
1946 old = snd_soc_read(codec, reg);
1947 new = (old & ~mask) | value;
1948 change = old != new;
db2a4165
FM
1949
1950 return change;
1951}
1952EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1953
db2a4165
FM
1954/**
1955 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1956 * @substream: the pcm substream
1957 * @hw: the hardware parameters
1958 *
1959 * Sets the substream runtime hardware parameters.
1960 */
1961int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1962 const struct snd_pcm_hardware *hw)
1963{
1964 struct snd_pcm_runtime *runtime = substream->runtime;
1965 runtime->hw.info = hw->info;
1966 runtime->hw.formats = hw->formats;
1967 runtime->hw.period_bytes_min = hw->period_bytes_min;
1968 runtime->hw.period_bytes_max = hw->period_bytes_max;
1969 runtime->hw.periods_min = hw->periods_min;
1970 runtime->hw.periods_max = hw->periods_max;
1971 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1972 runtime->hw.fifo_size = hw->fifo_size;
1973 return 0;
1974}
1975EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1976
1977/**
1978 * snd_soc_cnew - create new control
1979 * @_template: control template
1980 * @data: control private data
ac11a2b3 1981 * @long_name: control long name
efb7ac3f 1982 * @prefix: control name prefix
db2a4165
FM
1983 *
1984 * Create a new mixer control from a template control.
1985 *
1986 * Returns 0 for success, else error.
1987 */
1988struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
efb7ac3f
MB
1989 void *data, char *long_name,
1990 const char *prefix)
db2a4165
FM
1991{
1992 struct snd_kcontrol_new template;
efb7ac3f
MB
1993 struct snd_kcontrol *kcontrol;
1994 char *name = NULL;
1995 int name_len;
db2a4165
FM
1996
1997 memcpy(&template, _template, sizeof(template));
db2a4165
FM
1998 template.index = 0;
1999
efb7ac3f
MB
2000 if (!long_name)
2001 long_name = template.name;
2002
2003 if (prefix) {
2004 name_len = strlen(long_name) + strlen(prefix) + 2;
57cf9d45 2005 name = kmalloc(name_len, GFP_KERNEL);
efb7ac3f
MB
2006 if (!name)
2007 return NULL;
2008
2009 snprintf(name, name_len, "%s %s", prefix, long_name);
2010
2011 template.name = name;
2012 } else {
2013 template.name = long_name;
2014 }
2015
2016 kcontrol = snd_ctl_new1(&template, data);
2017
2018 kfree(name);
2019
2020 return kcontrol;
db2a4165
FM
2021}
2022EXPORT_SYMBOL_GPL(snd_soc_cnew);
2023
022658be
LG
2024static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2025 const struct snd_kcontrol_new *controls, int num_controls,
2026 const char *prefix, void *data)
2027{
2028 int err, i;
2029
2030 for (i = 0; i < num_controls; i++) {
2031 const struct snd_kcontrol_new *control = &controls[i];
2032 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2033 control->name, prefix));
2034 if (err < 0) {
2035 dev_err(dev, "Failed to add %s: %d\n", control->name, err);
2036 return err;
2037 }
2038 }
2039
2040 return 0;
2041}
2042
3e8e1952 2043/**
022658be
LG
2044 * snd_soc_add_codec_controls - add an array of controls to a codec.
2045 * Convenience function to add a list of controls. Many codecs were
3e8e1952
IM
2046 * duplicating this code.
2047 *
2048 * @codec: codec to add controls to
2049 * @controls: array of controls to add
2050 * @num_controls: number of elements in the array
2051 *
2052 * Return 0 for success, else error.
2053 */
022658be 2054int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
3e8e1952
IM
2055 const struct snd_kcontrol_new *controls, int num_controls)
2056{
f0fba2ad 2057 struct snd_card *card = codec->card->snd_card;
3e8e1952 2058
022658be
LG
2059 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2060 codec->name_prefix, codec);
3e8e1952 2061}
022658be 2062EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
3e8e1952 2063
a491a5c8
LG
2064/**
2065 * snd_soc_add_platform_controls - add an array of controls to a platform.
022658be 2066 * Convenience function to add a list of controls.
a491a5c8
LG
2067 *
2068 * @platform: platform to add controls to
2069 * @controls: array of controls to add
2070 * @num_controls: number of elements in the array
2071 *
2072 * Return 0 for success, else error.
2073 */
2074int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2075 const struct snd_kcontrol_new *controls, int num_controls)
2076{
2077 struct snd_card *card = platform->card->snd_card;
a491a5c8 2078
022658be
LG
2079 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2080 NULL, platform);
a491a5c8
LG
2081}
2082EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2083
022658be
LG
2084/**
2085 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2086 * Convenience function to add a list of controls.
2087 *
2088 * @soc_card: SoC card to add controls to
2089 * @controls: array of controls to add
2090 * @num_controls: number of elements in the array
2091 *
2092 * Return 0 for success, else error.
2093 */
2094int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2095 const struct snd_kcontrol_new *controls, int num_controls)
2096{
2097 struct snd_card *card = soc_card->snd_card;
2098
2099 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2100 NULL, soc_card);
2101}
2102EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2103
2104/**
2105 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2106 * Convienience function to add a list of controls.
2107 *
2108 * @dai: DAI to add controls to
2109 * @controls: array of controls to add
2110 * @num_controls: number of elements in the array
2111 *
2112 * Return 0 for success, else error.
2113 */
2114int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2115 const struct snd_kcontrol_new *controls, int num_controls)
2116{
2117 struct snd_card *card = dai->card->snd_card;
2118
2119 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2120 NULL, dai);
2121}
2122EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2123
db2a4165
FM
2124/**
2125 * snd_soc_info_enum_double - enumerated double mixer info callback
2126 * @kcontrol: mixer control
2127 * @uinfo: control element information
2128 *
2129 * Callback to provide information about a double enumerated
2130 * mixer control.
2131 *
2132 * Returns 0 for success.
2133 */
2134int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2135 struct snd_ctl_elem_info *uinfo)
2136{
2137 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2138
2139 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2140 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
f8ba0b7b 2141 uinfo->value.enumerated.items = e->max;
db2a4165 2142
f8ba0b7b
JS
2143 if (uinfo->value.enumerated.item > e->max - 1)
2144 uinfo->value.enumerated.item = e->max - 1;
db2a4165
FM
2145 strcpy(uinfo->value.enumerated.name,
2146 e->texts[uinfo->value.enumerated.item]);
2147 return 0;
2148}
2149EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2150
2151/**
2152 * snd_soc_get_enum_double - enumerated double mixer get callback
2153 * @kcontrol: mixer control
ac11a2b3 2154 * @ucontrol: control element information
db2a4165
FM
2155 *
2156 * Callback to get the value of a double enumerated mixer.
2157 *
2158 * Returns 0 for success.
2159 */
2160int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2161 struct snd_ctl_elem_value *ucontrol)
2162{
2163 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2164 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f 2165 unsigned int val, bitmask;
db2a4165 2166
f8ba0b7b 2167 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
db2a4165
FM
2168 ;
2169 val = snd_soc_read(codec, e->reg);
3ff3f64b
MB
2170 ucontrol->value.enumerated.item[0]
2171 = (val >> e->shift_l) & (bitmask - 1);
db2a4165
FM
2172 if (e->shift_l != e->shift_r)
2173 ucontrol->value.enumerated.item[1] =
2174 (val >> e->shift_r) & (bitmask - 1);
2175
2176 return 0;
2177}
2178EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2179
2180/**
2181 * snd_soc_put_enum_double - enumerated double mixer put callback
2182 * @kcontrol: mixer control
ac11a2b3 2183 * @ucontrol: control element information
db2a4165
FM
2184 *
2185 * Callback to set the value of a double enumerated mixer.
2186 *
2187 * Returns 0 for success.
2188 */
2189int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2190 struct snd_ctl_elem_value *ucontrol)
2191{
2192 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2193 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f
DR
2194 unsigned int val;
2195 unsigned int mask, bitmask;
db2a4165 2196
f8ba0b7b 2197 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
db2a4165 2198 ;
f8ba0b7b 2199 if (ucontrol->value.enumerated.item[0] > e->max - 1)
db2a4165
FM
2200 return -EINVAL;
2201 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2202 mask = (bitmask - 1) << e->shift_l;
2203 if (e->shift_l != e->shift_r) {
f8ba0b7b 2204 if (ucontrol->value.enumerated.item[1] > e->max - 1)
db2a4165
FM
2205 return -EINVAL;
2206 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2207 mask |= (bitmask - 1) << e->shift_r;
2208 }
2209
6c508c62 2210 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
db2a4165
FM
2211}
2212EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2213
2e72f8e3
PU
2214/**
2215 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2216 * @kcontrol: mixer control
2217 * @ucontrol: control element information
2218 *
2219 * Callback to get the value of a double semi enumerated mixer.
2220 *
2221 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2222 * used for handling bitfield coded enumeration for example.
2223 *
2224 * Returns 0 for success.
2225 */
2226int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2227 struct snd_ctl_elem_value *ucontrol)
2228{
2229 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
74155556 2230 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f 2231 unsigned int reg_val, val, mux;
2e72f8e3
PU
2232
2233 reg_val = snd_soc_read(codec, e->reg);
2234 val = (reg_val >> e->shift_l) & e->mask;
2235 for (mux = 0; mux < e->max; mux++) {
2236 if (val == e->values[mux])
2237 break;
2238 }
2239 ucontrol->value.enumerated.item[0] = mux;
2240 if (e->shift_l != e->shift_r) {
2241 val = (reg_val >> e->shift_r) & e->mask;
2242 for (mux = 0; mux < e->max; mux++) {
2243 if (val == e->values[mux])
2244 break;
2245 }
2246 ucontrol->value.enumerated.item[1] = mux;
2247 }
2248
2249 return 0;
2250}
2251EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2252
2253/**
2254 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2255 * @kcontrol: mixer control
2256 * @ucontrol: control element information
2257 *
2258 * Callback to set the value of a double semi enumerated mixer.
2259 *
2260 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2261 * used for handling bitfield coded enumeration for example.
2262 *
2263 * Returns 0 for success.
2264 */
2265int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2266 struct snd_ctl_elem_value *ucontrol)
2267{
2268 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
74155556 2269 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f
DR
2270 unsigned int val;
2271 unsigned int mask;
2e72f8e3
PU
2272
2273 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2274 return -EINVAL;
2275 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2276 mask = e->mask << e->shift_l;
2277 if (e->shift_l != e->shift_r) {
2278 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2279 return -EINVAL;
2280 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2281 mask |= e->mask << e->shift_r;
2282 }
2283
6c508c62 2284 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2e72f8e3
PU
2285}
2286EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2287
db2a4165
FM
2288/**
2289 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2290 * @kcontrol: mixer control
2291 * @uinfo: control element information
2292 *
2293 * Callback to provide information about an external enumerated
2294 * single mixer.
2295 *
2296 * Returns 0 for success.
2297 */
2298int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2299 struct snd_ctl_elem_info *uinfo)
2300{
2301 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2302
2303 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2304 uinfo->count = 1;
f8ba0b7b 2305 uinfo->value.enumerated.items = e->max;
db2a4165 2306
f8ba0b7b
JS
2307 if (uinfo->value.enumerated.item > e->max - 1)
2308 uinfo->value.enumerated.item = e->max - 1;
db2a4165
FM
2309 strcpy(uinfo->value.enumerated.name,
2310 e->texts[uinfo->value.enumerated.item]);
2311 return 0;
2312}
2313EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2314
2315/**
2316 * snd_soc_info_volsw_ext - external single mixer info callback
2317 * @kcontrol: mixer control
2318 * @uinfo: control element information
2319 *
2320 * Callback to provide information about a single external mixer control.
2321 *
2322 * Returns 0 for success.
2323 */
2324int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2325 struct snd_ctl_elem_info *uinfo)
2326{
a7a4ac86
PZ
2327 int max = kcontrol->private_value;
2328
fd5dfad9 2329 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
a7a4ac86
PZ
2330 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2331 else
2332 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
db2a4165 2333
db2a4165
FM
2334 uinfo->count = 1;
2335 uinfo->value.integer.min = 0;
a7a4ac86 2336 uinfo->value.integer.max = max;
db2a4165
FM
2337 return 0;
2338}
2339EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2340
db2a4165
FM
2341/**
2342 * snd_soc_info_volsw - single mixer info callback
2343 * @kcontrol: mixer control
2344 * @uinfo: control element information
2345 *
e8f5a103
PU
2346 * Callback to provide information about a single mixer control, or a double
2347 * mixer control that spans 2 registers.
db2a4165
FM
2348 *
2349 * Returns 0 for success.
2350 */
2351int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2352 struct snd_ctl_elem_info *uinfo)
2353{
4eaa9819
JS
2354 struct soc_mixer_control *mc =
2355 (struct soc_mixer_control *)kcontrol->private_value;
d11bb4a9 2356 int platform_max;
db2a4165 2357
d11bb4a9
PU
2358 if (!mc->platform_max)
2359 mc->platform_max = mc->max;
2360 platform_max = mc->platform_max;
2361
2362 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
a7a4ac86
PZ
2363 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2364 else
2365 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2366
e8f5a103 2367 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
db2a4165 2368 uinfo->value.integer.min = 0;
d11bb4a9 2369 uinfo->value.integer.max = platform_max;
db2a4165
FM
2370 return 0;
2371}
2372EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2373
2374/**
2375 * snd_soc_get_volsw - single mixer get callback
2376 * @kcontrol: mixer control
ac11a2b3 2377 * @ucontrol: control element information
db2a4165 2378 *
f7915d99
PU
2379 * Callback to get the value of a single mixer control, or a double mixer
2380 * control that spans 2 registers.
db2a4165
FM
2381 *
2382 * Returns 0 for success.
2383 */
2384int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2385 struct snd_ctl_elem_value *ucontrol)
2386{
4eaa9819
JS
2387 struct soc_mixer_control *mc =
2388 (struct soc_mixer_control *)kcontrol->private_value;
db2a4165 2389 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2390 unsigned int reg = mc->reg;
f7915d99 2391 unsigned int reg2 = mc->rreg;
815ecf8d
JS
2392 unsigned int shift = mc->shift;
2393 unsigned int rshift = mc->rshift;
4eaa9819 2394 int max = mc->max;
815ecf8d
JS
2395 unsigned int mask = (1 << fls(max)) - 1;
2396 unsigned int invert = mc->invert;
db2a4165
FM
2397
2398 ucontrol->value.integer.value[0] =
2399 (snd_soc_read(codec, reg) >> shift) & mask;
f7915d99 2400 if (invert)
db2a4165 2401 ucontrol->value.integer.value[0] =
a7a4ac86 2402 max - ucontrol->value.integer.value[0];
f7915d99
PU
2403
2404 if (snd_soc_volsw_is_stereo(mc)) {
2405 if (reg == reg2)
2406 ucontrol->value.integer.value[1] =
2407 (snd_soc_read(codec, reg) >> rshift) & mask;
2408 else
2409 ucontrol->value.integer.value[1] =
2410 (snd_soc_read(codec, reg2) >> shift) & mask;
2411 if (invert)
db2a4165 2412 ucontrol->value.integer.value[1] =
a7a4ac86 2413 max - ucontrol->value.integer.value[1];
db2a4165
FM
2414 }
2415
2416 return 0;
2417}
2418EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2419
2420/**
2421 * snd_soc_put_volsw - single mixer put callback
2422 * @kcontrol: mixer control
ac11a2b3 2423 * @ucontrol: control element information
db2a4165 2424 *
974815ba
PU
2425 * Callback to set the value of a single mixer control, or a double mixer
2426 * control that spans 2 registers.
db2a4165
FM
2427 *
2428 * Returns 0 for success.
2429 */
2430int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2431 struct snd_ctl_elem_value *ucontrol)
2432{
4eaa9819
JS
2433 struct soc_mixer_control *mc =
2434 (struct soc_mixer_control *)kcontrol->private_value;
db2a4165 2435 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2436 unsigned int reg = mc->reg;
974815ba 2437 unsigned int reg2 = mc->rreg;
815ecf8d
JS
2438 unsigned int shift = mc->shift;
2439 unsigned int rshift = mc->rshift;
4eaa9819 2440 int max = mc->max;
815ecf8d
JS
2441 unsigned int mask = (1 << fls(max)) - 1;
2442 unsigned int invert = mc->invert;
974815ba
PU
2443 int err;
2444 bool type_2r = 0;
2445 unsigned int val2 = 0;
2446 unsigned int val, val_mask;
db2a4165
FM
2447
2448 val = (ucontrol->value.integer.value[0] & mask);
2449 if (invert)
a7a4ac86 2450 val = max - val;
db2a4165
FM
2451 val_mask = mask << shift;
2452 val = val << shift;
974815ba 2453 if (snd_soc_volsw_is_stereo(mc)) {
db2a4165
FM
2454 val2 = (ucontrol->value.integer.value[1] & mask);
2455 if (invert)
a7a4ac86 2456 val2 = max - val2;
974815ba
PU
2457 if (reg == reg2) {
2458 val_mask |= mask << rshift;
2459 val |= val2 << rshift;
2460 } else {
2461 val2 = val2 << shift;
2462 type_2r = 1;
2463 }
db2a4165 2464 }
6c508c62 2465 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
3ff3f64b 2466 if (err < 0)
db2a4165
FM
2467 return err;
2468
974815ba
PU
2469 if (type_2r)
2470 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2471
db2a4165
FM
2472 return err;
2473}
974815ba 2474EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
db2a4165 2475
e13ac2e9
MB
2476/**
2477 * snd_soc_info_volsw_s8 - signed mixer info callback
2478 * @kcontrol: mixer control
2479 * @uinfo: control element information
2480 *
2481 * Callback to provide information about a signed mixer control.
2482 *
2483 * Returns 0 for success.
2484 */
2485int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_info *uinfo)
2487{
4eaa9819
JS
2488 struct soc_mixer_control *mc =
2489 (struct soc_mixer_control *)kcontrol->private_value;
d11bb4a9 2490 int platform_max;
4eaa9819 2491 int min = mc->min;
e13ac2e9 2492
d11bb4a9
PU
2493 if (!mc->platform_max)
2494 mc->platform_max = mc->max;
2495 platform_max = mc->platform_max;
2496
e13ac2e9
MB
2497 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2498 uinfo->count = 2;
2499 uinfo->value.integer.min = 0;
d11bb4a9 2500 uinfo->value.integer.max = platform_max - min;
e13ac2e9
MB
2501 return 0;
2502}
2503EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2504
2505/**
2506 * snd_soc_get_volsw_s8 - signed mixer get callback
2507 * @kcontrol: mixer control
ac11a2b3 2508 * @ucontrol: control element information
e13ac2e9
MB
2509 *
2510 * Callback to get the value of a signed mixer control.
2511 *
2512 * Returns 0 for success.
2513 */
2514int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2515 struct snd_ctl_elem_value *ucontrol)
2516{
4eaa9819
JS
2517 struct soc_mixer_control *mc =
2518 (struct soc_mixer_control *)kcontrol->private_value;
e13ac2e9 2519 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2520 unsigned int reg = mc->reg;
4eaa9819 2521 int min = mc->min;
e13ac2e9
MB
2522 int val = snd_soc_read(codec, reg);
2523
2524 ucontrol->value.integer.value[0] =
2525 ((signed char)(val & 0xff))-min;
2526 ucontrol->value.integer.value[1] =
2527 ((signed char)((val >> 8) & 0xff))-min;
2528 return 0;
2529}
2530EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2531
2532/**
2533 * snd_soc_put_volsw_sgn - signed mixer put callback
2534 * @kcontrol: mixer control
ac11a2b3 2535 * @ucontrol: control element information
e13ac2e9
MB
2536 *
2537 * Callback to set the value of a signed mixer control.
2538 *
2539 * Returns 0 for success.
2540 */
2541int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2542 struct snd_ctl_elem_value *ucontrol)
2543{
4eaa9819
JS
2544 struct soc_mixer_control *mc =
2545 (struct soc_mixer_control *)kcontrol->private_value;
e13ac2e9 2546 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2547 unsigned int reg = mc->reg;
4eaa9819 2548 int min = mc->min;
46f5822f 2549 unsigned int val;
e13ac2e9
MB
2550
2551 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2552 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2553
6c508c62 2554 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
e13ac2e9
MB
2555}
2556EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2557
637d3847
PU
2558/**
2559 * snd_soc_limit_volume - Set new limit to an existing volume control.
2560 *
2561 * @codec: where to look for the control
2562 * @name: Name of the control
2563 * @max: new maximum limit
2564 *
2565 * Return 0 for success, else error.
2566 */
2567int snd_soc_limit_volume(struct snd_soc_codec *codec,
2568 const char *name, int max)
2569{
f0fba2ad 2570 struct snd_card *card = codec->card->snd_card;
637d3847
PU
2571 struct snd_kcontrol *kctl;
2572 struct soc_mixer_control *mc;
2573 int found = 0;
2574 int ret = -EINVAL;
2575
2576 /* Sanity check for name and max */
2577 if (unlikely(!name || max <= 0))
2578 return -EINVAL;
2579
2580 list_for_each_entry(kctl, &card->controls, list) {
2581 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2582 found = 1;
2583 break;
2584 }
2585 }
2586 if (found) {
2587 mc = (struct soc_mixer_control *)kctl->private_value;
2588 if (max <= mc->max) {
d11bb4a9 2589 mc->platform_max = max;
637d3847
PU
2590 ret = 0;
2591 }
2592 }
2593 return ret;
2594}
2595EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2596
b6f4bb38 2597/**
2598 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2599 * mixer info callback
2600 * @kcontrol: mixer control
2601 * @uinfo: control element information
2602 *
2603 * Returns 0 for success.
2604 */
2605int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2606 struct snd_ctl_elem_info *uinfo)
2607{
2608 struct soc_mixer_control *mc =
2609 (struct soc_mixer_control *)kcontrol->private_value;
2610 int max = mc->max;
2611 int min = mc->min;
2612
2613 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2614 uinfo->count = 2;
2615 uinfo->value.integer.min = 0;
2616 uinfo->value.integer.max = max-min;
2617
2618 return 0;
2619}
2620EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2621
2622/**
2623 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2624 * mixer get callback
2625 * @kcontrol: mixer control
2626 * @uinfo: control element information
2627 *
2628 * Returns 0 for success.
2629 */
2630int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2631 struct snd_ctl_elem_value *ucontrol)
2632{
2633 struct soc_mixer_control *mc =
2634 (struct soc_mixer_control *)kcontrol->private_value;
2635 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2636 unsigned int mask = (1<<mc->shift)-1;
2637 int min = mc->min;
2638 int val = snd_soc_read(codec, mc->reg) & mask;
2639 int valr = snd_soc_read(codec, mc->rreg) & mask;
2640
20630c7f
SL
2641 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2642 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
b6f4bb38 2643 return 0;
2644}
2645EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2646
2647/**
2648 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2649 * mixer put callback
2650 * @kcontrol: mixer control
2651 * @uinfo: control element information
2652 *
2653 * Returns 0 for success.
2654 */
2655int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2656 struct snd_ctl_elem_value *ucontrol)
2657{
2658 struct soc_mixer_control *mc =
2659 (struct soc_mixer_control *)kcontrol->private_value;
2660 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2661 unsigned int mask = (1<<mc->shift)-1;
2662 int min = mc->min;
2663 int ret;
2664 unsigned int val, valr, oval, ovalr;
2665
2666 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2667 val &= mask;
2668 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2669 valr &= mask;
2670
2671 oval = snd_soc_read(codec, mc->reg) & mask;
2672 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2673
2674 ret = 0;
2675 if (oval != val) {
2676 ret = snd_soc_write(codec, mc->reg, val);
2677 if (ret < 0)
f1df5aec 2678 return ret;
b6f4bb38 2679 }
2680 if (ovalr != valr) {
2681 ret = snd_soc_write(codec, mc->rreg, valr);
2682 if (ret < 0)
f1df5aec 2683 return ret;
b6f4bb38 2684 }
2685
2686 return 0;
2687}
2688EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2689
8c6529db
LG
2690/**
2691 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2692 * @dai: DAI
2693 * @clk_id: DAI specific clock ID
2694 * @freq: new clock frequency in Hz
2695 * @dir: new clock direction - input/output.
2696 *
2697 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2698 */
2699int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2700 unsigned int freq, int dir)
2701{
f0fba2ad
LG
2702 if (dai->driver && dai->driver->ops->set_sysclk)
2703 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
ec4ee52a 2704 else if (dai->codec && dai->codec->driver->set_sysclk)
da1c6ea6 2705 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
ec4ee52a 2706 freq, dir);
8c6529db
LG
2707 else
2708 return -EINVAL;
2709}
2710EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2711
ec4ee52a
MB
2712/**
2713 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2714 * @codec: CODEC
2715 * @clk_id: DAI specific clock ID
da1c6ea6 2716 * @source: Source for the clock
ec4ee52a
MB
2717 * @freq: new clock frequency in Hz
2718 * @dir: new clock direction - input/output.
2719 *
2720 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2721 */
2722int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
da1c6ea6 2723 int source, unsigned int freq, int dir)
ec4ee52a
MB
2724{
2725 if (codec->driver->set_sysclk)
da1c6ea6
MB
2726 return codec->driver->set_sysclk(codec, clk_id, source,
2727 freq, dir);
ec4ee52a
MB
2728 else
2729 return -EINVAL;
2730}
2731EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2732
8c6529db
LG
2733/**
2734 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2735 * @dai: DAI
ac11a2b3 2736 * @div_id: DAI specific clock divider ID
8c6529db
LG
2737 * @div: new clock divisor.
2738 *
2739 * Configures the clock dividers. This is used to derive the best DAI bit and
2740 * frame clocks from the system or master clock. It's best to set the DAI bit
2741 * and frame clocks as low as possible to save system power.
2742 */
2743int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2744 int div_id, int div)
2745{
f0fba2ad
LG
2746 if (dai->driver && dai->driver->ops->set_clkdiv)
2747 return dai->driver->ops->set_clkdiv(dai, div_id, div);
8c6529db
LG
2748 else
2749 return -EINVAL;
2750}
2751EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2752
2753/**
2754 * snd_soc_dai_set_pll - configure DAI PLL.
2755 * @dai: DAI
2756 * @pll_id: DAI specific PLL ID
85488037 2757 * @source: DAI specific source for the PLL
8c6529db
LG
2758 * @freq_in: PLL input clock frequency in Hz
2759 * @freq_out: requested PLL output clock frequency in Hz
2760 *
2761 * Configures and enables PLL to generate output clock based on input clock.
2762 */
85488037
MB
2763int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2764 unsigned int freq_in, unsigned int freq_out)
8c6529db 2765{
f0fba2ad
LG
2766 if (dai->driver && dai->driver->ops->set_pll)
2767 return dai->driver->ops->set_pll(dai, pll_id, source,
85488037 2768 freq_in, freq_out);
ec4ee52a
MB
2769 else if (dai->codec && dai->codec->driver->set_pll)
2770 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2771 freq_in, freq_out);
8c6529db
LG
2772 else
2773 return -EINVAL;
2774}
2775EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2776
ec4ee52a
MB
2777/*
2778 * snd_soc_codec_set_pll - configure codec PLL.
2779 * @codec: CODEC
2780 * @pll_id: DAI specific PLL ID
2781 * @source: DAI specific source for the PLL
2782 * @freq_in: PLL input clock frequency in Hz
2783 * @freq_out: requested PLL output clock frequency in Hz
2784 *
2785 * Configures and enables PLL to generate output clock based on input clock.
2786 */
2787int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2788 unsigned int freq_in, unsigned int freq_out)
2789{
2790 if (codec->driver->set_pll)
2791 return codec->driver->set_pll(codec, pll_id, source,
2792 freq_in, freq_out);
2793 else
2794 return -EINVAL;
2795}
2796EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2797
8c6529db
LG
2798/**
2799 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2800 * @dai: DAI
8c6529db
LG
2801 * @fmt: SND_SOC_DAIFMT_ format value.
2802 *
2803 * Configures the DAI hardware format and clocking.
2804 */
2805int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2806{
f0fba2ad
LG
2807 if (dai->driver && dai->driver->ops->set_fmt)
2808 return dai->driver->ops->set_fmt(dai, fmt);
8c6529db
LG
2809 else
2810 return -EINVAL;
2811}
2812EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2813
2814/**
2815 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2816 * @dai: DAI
a5479e38
DR
2817 * @tx_mask: bitmask representing active TX slots.
2818 * @rx_mask: bitmask representing active RX slots.
8c6529db 2819 * @slots: Number of slots in use.
a5479e38 2820 * @slot_width: Width in bits for each slot.
8c6529db
LG
2821 *
2822 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2823 * specific.
2824 */
2825int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
a5479e38 2826 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
8c6529db 2827{
f0fba2ad
LG
2828 if (dai->driver && dai->driver->ops->set_tdm_slot)
2829 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
a5479e38 2830 slots, slot_width);
8c6529db
LG
2831 else
2832 return -EINVAL;
2833}
2834EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2835
472df3cb
BS
2836/**
2837 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2838 * @dai: DAI
2839 * @tx_num: how many TX channels
2840 * @tx_slot: pointer to an array which imply the TX slot number channel
2841 * 0~num-1 uses
2842 * @rx_num: how many RX channels
2843 * @rx_slot: pointer to an array which imply the RX slot number channel
2844 * 0~num-1 uses
2845 *
2846 * configure the relationship between channel number and TDM slot number.
2847 */
2848int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2849 unsigned int tx_num, unsigned int *tx_slot,
2850 unsigned int rx_num, unsigned int *rx_slot)
2851{
f0fba2ad
LG
2852 if (dai->driver && dai->driver->ops->set_channel_map)
2853 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
472df3cb
BS
2854 rx_num, rx_slot);
2855 else
2856 return -EINVAL;
2857}
2858EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2859
8c6529db
LG
2860/**
2861 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2862 * @dai: DAI
2863 * @tristate: tristate enable
2864 *
2865 * Tristates the DAI so that others can use it.
2866 */
2867int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2868{
f0fba2ad
LG
2869 if (dai->driver && dai->driver->ops->set_tristate)
2870 return dai->driver->ops->set_tristate(dai, tristate);
8c6529db
LG
2871 else
2872 return -EINVAL;
2873}
2874EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2875
2876/**
2877 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2878 * @dai: DAI
2879 * @mute: mute enable
2880 *
2881 * Mutes the DAI DAC.
2882 */
2883int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2884{
f0fba2ad
LG
2885 if (dai->driver && dai->driver->ops->digital_mute)
2886 return dai->driver->ops->digital_mute(dai, mute);
8c6529db
LG
2887 else
2888 return -EINVAL;
2889}
2890EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2891
c5af3a2e
MB
2892/**
2893 * snd_soc_register_card - Register a card with the ASoC core
2894 *
ac11a2b3 2895 * @card: Card to register
c5af3a2e 2896 *
c5af3a2e 2897 */
70a7ca34 2898int snd_soc_register_card(struct snd_soc_card *card)
c5af3a2e 2899{
f0fba2ad
LG
2900 int i;
2901
c5af3a2e
MB
2902 if (!card->name || !card->dev)
2903 return -EINVAL;
2904
5a504963
SW
2905 for (i = 0; i < card->num_links; i++) {
2906 struct snd_soc_dai_link *link = &card->dai_link[i];
2907
2908 /*
2909 * Codec must be specified by 1 of name or OF node,
2910 * not both or neither.
2911 */
2912 if (!!link->codec_name == !!link->codec_of_node) {
2913 dev_err(card->dev,
3b09bb82
LG
2914 "Neither/both codec name/of_node are set for %s\n",
2915 link->name);
5a504963
SW
2916 return -EINVAL;
2917 }
2918
2919 /*
2920 * Platform may be specified by either name or OF node, but
2921 * can be left unspecified, and a dummy platform will be used.
2922 */
2923 if (link->platform_name && link->platform_of_node) {
2924 dev_err(card->dev,
3b09bb82 2925 "Both platform name/of_node are set for %s\n", link->name);
5a504963
SW
2926 return -EINVAL;
2927 }
2928
2929 /*
2930 * CPU DAI must be specified by 1 of name or OF node,
2931 * not both or neither.
2932 */
2933 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2934 dev_err(card->dev,
3b09bb82
LG
2935 "Neither/both cpu_dai name/of_node are set for %s\n",
2936 link->name);
5a504963
SW
2937 return -EINVAL;
2938 }
2939 }
2940
ed77cc12
MB
2941 dev_set_drvdata(card->dev, card);
2942
111c6419
SW
2943 snd_soc_initialize_card_lists(card);
2944
150dd2f8
VK
2945 soc_init_card_debugfs(card);
2946
2eea392d
JN
2947 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2948 (card->num_links + card->num_aux_devs),
2949 GFP_KERNEL);
f0fba2ad
LG
2950 if (card->rtd == NULL)
2951 return -ENOMEM;
2eea392d 2952 card->rtd_aux = &card->rtd[card->num_links];
f0fba2ad
LG
2953
2954 for (i = 0; i < card->num_links; i++)
2955 card->rtd[i].dai_link = &card->dai_link[i];
2956
c5af3a2e 2957 INIT_LIST_HEAD(&card->list);
db432b41 2958 INIT_LIST_HEAD(&card->dapm_dirty);
c5af3a2e 2959 card->instantiated = 0;
f0fba2ad 2960 mutex_init(&card->mutex);
c5af3a2e
MB
2961
2962 mutex_lock(&client_mutex);
2963 list_add(&card->list, &card_list);
435c5e25 2964 snd_soc_instantiate_cards();
c5af3a2e
MB
2965 mutex_unlock(&client_mutex);
2966
2967 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2968
2969 return 0;
2970}
70a7ca34 2971EXPORT_SYMBOL_GPL(snd_soc_register_card);
c5af3a2e
MB
2972
2973/**
2974 * snd_soc_unregister_card - Unregister a card with the ASoC core
2975 *
ac11a2b3 2976 * @card: Card to unregister
c5af3a2e 2977 *
c5af3a2e 2978 */
70a7ca34 2979int snd_soc_unregister_card(struct snd_soc_card *card)
c5af3a2e 2980{
b0e26485
VK
2981 if (card->instantiated)
2982 soc_cleanup_card_resources(card);
c5af3a2e
MB
2983 mutex_lock(&client_mutex);
2984 list_del(&card->list);
2985 mutex_unlock(&client_mutex);
c5af3a2e
MB
2986 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2987
2988 return 0;
2989}
70a7ca34 2990EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
c5af3a2e 2991
f0fba2ad
LG
2992/*
2993 * Simplify DAI link configuration by removing ".-1" from device names
2994 * and sanitizing names.
2995 */
0b9a214a 2996static char *fmt_single_name(struct device *dev, int *id)
f0fba2ad
LG
2997{
2998 char *found, name[NAME_SIZE];
2999 int id1, id2;
3000
3001 if (dev_name(dev) == NULL)
3002 return NULL;
3003
58818a77 3004 strlcpy(name, dev_name(dev), NAME_SIZE);
f0fba2ad
LG
3005
3006 /* are we a "%s.%d" name (platform and SPI components) */
3007 found = strstr(name, dev->driver->name);
3008 if (found) {
3009 /* get ID */
3010 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3011
3012 /* discard ID from name if ID == -1 */
3013 if (*id == -1)
3014 found[strlen(dev->driver->name)] = '\0';
3015 }
3016
3017 } else {
3018 /* I2C component devices are named "bus-addr" */
3019 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3020 char tmp[NAME_SIZE];
3021
3022 /* create unique ID number from I2C addr and bus */
05899446 3023 *id = ((id1 & 0xffff) << 16) + id2;
f0fba2ad
LG
3024
3025 /* sanitize component name for DAI link creation */
3026 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
58818a77 3027 strlcpy(name, tmp, NAME_SIZE);
f0fba2ad
LG
3028 } else
3029 *id = 0;
3030 }
3031
3032 return kstrdup(name, GFP_KERNEL);
3033}
3034
3035/*
3036 * Simplify DAI link naming for single devices with multiple DAIs by removing
3037 * any ".-1" and using the DAI name (instead of device name).
3038 */
3039static inline char *fmt_multiple_name(struct device *dev,
3040 struct snd_soc_dai_driver *dai_drv)
3041{
3042 if (dai_drv->name == NULL) {
3043 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
3044 dev_name(dev));
3045 return NULL;
3046 }
3047
3048 return kstrdup(dai_drv->name, GFP_KERNEL);
3049}
3050
9115171a
MB
3051/**
3052 * snd_soc_register_dai - Register a DAI with the ASoC core
3053 *
ac11a2b3 3054 * @dai: DAI to register
9115171a 3055 */
f0fba2ad
LG
3056int snd_soc_register_dai(struct device *dev,
3057 struct snd_soc_dai_driver *dai_drv)
9115171a 3058{
f0fba2ad
LG
3059 struct snd_soc_dai *dai;
3060
3061 dev_dbg(dev, "dai register %s\n", dev_name(dev));
9115171a 3062
f0fba2ad
LG
3063 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3064 if (dai == NULL)
a7393623 3065 return -ENOMEM;
9115171a 3066
f0fba2ad
LG
3067 /* create DAI component name */
3068 dai->name = fmt_single_name(dev, &dai->id);
3069 if (dai->name == NULL) {
3070 kfree(dai);
3071 return -ENOMEM;
3072 }
6335d055 3073
f0fba2ad
LG
3074 dai->dev = dev;
3075 dai->driver = dai_drv;
3076 if (!dai->driver->ops)
3077 dai->driver->ops = &null_dai_ops;
9115171a
MB
3078
3079 mutex_lock(&client_mutex);
3080 list_add(&dai->list, &dai_list);
435c5e25 3081 snd_soc_instantiate_cards();
9115171a
MB
3082 mutex_unlock(&client_mutex);
3083
3084 pr_debug("Registered DAI '%s'\n", dai->name);
3085
3086 return 0;
3087}
3088EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3089
3090/**
3091 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3092 *
ac11a2b3 3093 * @dai: DAI to unregister
9115171a 3094 */
f0fba2ad 3095void snd_soc_unregister_dai(struct device *dev)
9115171a 3096{
f0fba2ad
LG
3097 struct snd_soc_dai *dai;
3098
3099 list_for_each_entry(dai, &dai_list, list) {
3100 if (dev == dai->dev)
3101 goto found;
3102 }
3103 return;
3104
3105found:
9115171a
MB
3106 mutex_lock(&client_mutex);
3107 list_del(&dai->list);
3108 mutex_unlock(&client_mutex);
3109
3110 pr_debug("Unregistered DAI '%s'\n", dai->name);
f0fba2ad
LG
3111 kfree(dai->name);
3112 kfree(dai);
9115171a
MB
3113}
3114EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3115
3116/**
3117 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3118 *
ac11a2b3
MB
3119 * @dai: Array of DAIs to register
3120 * @count: Number of DAIs
9115171a 3121 */
f0fba2ad
LG
3122int snd_soc_register_dais(struct device *dev,
3123 struct snd_soc_dai_driver *dai_drv, size_t count)
9115171a 3124{
f0fba2ad
LG
3125 struct snd_soc_dai *dai;
3126 int i, ret = 0;
3127
720ffa4c 3128 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
9115171a
MB
3129
3130 for (i = 0; i < count; i++) {
f0fba2ad
LG
3131
3132 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
c46e0079
AL
3133 if (dai == NULL) {
3134 ret = -ENOMEM;
3135 goto err;
3136 }
f0fba2ad
LG
3137
3138 /* create DAI component name */
3139 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3140 if (dai->name == NULL) {
3141 kfree(dai);
3142 ret = -EINVAL;
9115171a 3143 goto err;
f0fba2ad
LG
3144 }
3145
3146 dai->dev = dev;
f0fba2ad 3147 dai->driver = &dai_drv[i];
0f9141c9
MB
3148 if (dai->driver->id)
3149 dai->id = dai->driver->id;
3150 else
3151 dai->id = i;
f0fba2ad
LG
3152 if (!dai->driver->ops)
3153 dai->driver->ops = &null_dai_ops;
3154
3155 mutex_lock(&client_mutex);
3156 list_add(&dai->list, &dai_list);
3157 mutex_unlock(&client_mutex);
3158
3159 pr_debug("Registered DAI '%s'\n", dai->name);
9115171a
MB
3160 }
3161
1dcb4f38 3162 mutex_lock(&client_mutex);
f0fba2ad 3163 snd_soc_instantiate_cards();
1dcb4f38 3164 mutex_unlock(&client_mutex);
9115171a
MB
3165 return 0;
3166
3167err:
3168 for (i--; i >= 0; i--)
f0fba2ad 3169 snd_soc_unregister_dai(dev);
9115171a
MB
3170
3171 return ret;
3172}
3173EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3174
3175/**
3176 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3177 *
ac11a2b3
MB
3178 * @dai: Array of DAIs to unregister
3179 * @count: Number of DAIs
9115171a 3180 */
f0fba2ad 3181void snd_soc_unregister_dais(struct device *dev, size_t count)
9115171a
MB
3182{
3183 int i;
3184
3185 for (i = 0; i < count; i++)
f0fba2ad 3186 snd_soc_unregister_dai(dev);
9115171a
MB
3187}
3188EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3189
12a48a8c
MB
3190/**
3191 * snd_soc_register_platform - Register a platform with the ASoC core
3192 *
ac11a2b3 3193 * @platform: platform to register
12a48a8c 3194 */
f0fba2ad
LG
3195int snd_soc_register_platform(struct device *dev,
3196 struct snd_soc_platform_driver *platform_drv)
12a48a8c 3197{
f0fba2ad
LG
3198 struct snd_soc_platform *platform;
3199
3200 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3201
3202 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3203 if (platform == NULL)
a7393623 3204 return -ENOMEM;
f0fba2ad
LG
3205
3206 /* create platform component name */
3207 platform->name = fmt_single_name(dev, &platform->id);
3208 if (platform->name == NULL) {
3209 kfree(platform);
3210 return -ENOMEM;
3211 }
12a48a8c 3212
f0fba2ad
LG
3213 platform->dev = dev;
3214 platform->driver = platform_drv;
b7950641
LG
3215 platform->dapm.dev = dev;
3216 platform->dapm.platform = platform;
64a648c2 3217 platform->dapm.stream_event = platform_drv->stream_event;
12a48a8c
MB
3218
3219 mutex_lock(&client_mutex);
3220 list_add(&platform->list, &platform_list);
435c5e25 3221 snd_soc_instantiate_cards();
12a48a8c
MB
3222 mutex_unlock(&client_mutex);
3223
3224 pr_debug("Registered platform '%s'\n", platform->name);
3225
3226 return 0;
3227}
3228EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3229
3230/**
3231 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3232 *
ac11a2b3 3233 * @platform: platform to unregister
12a48a8c 3234 */
f0fba2ad 3235void snd_soc_unregister_platform(struct device *dev)
12a48a8c 3236{
f0fba2ad
LG
3237 struct snd_soc_platform *platform;
3238
3239 list_for_each_entry(platform, &platform_list, list) {
3240 if (dev == platform->dev)
3241 goto found;
3242 }
3243 return;
3244
3245found:
12a48a8c
MB
3246 mutex_lock(&client_mutex);
3247 list_del(&platform->list);
3248 mutex_unlock(&client_mutex);
3249
3250 pr_debug("Unregistered platform '%s'\n", platform->name);
f0fba2ad
LG
3251 kfree(platform->name);
3252 kfree(platform);
12a48a8c
MB
3253}
3254EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3255
151ab22c
MB
3256static u64 codec_format_map[] = {
3257 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3258 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3259 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3260 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3261 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3262 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3263 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3264 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3265 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3266 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3267 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3268 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3269 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3270 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3271 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3272 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3273};
3274
3275/* Fix up the DAI formats for endianness: codecs don't actually see
3276 * the endianness of the data but we're using the CPU format
3277 * definitions which do need to include endianness so we ensure that
3278 * codec DAIs always have both big and little endian variants set.
3279 */
3280static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3281{
3282 int i;
3283
3284 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3285 if (stream->formats & codec_format_map[i])
3286 stream->formats |= codec_format_map[i];
3287}
3288
0d0cf00a
MB
3289/**
3290 * snd_soc_register_codec - Register a codec with the ASoC core
3291 *
ac11a2b3 3292 * @codec: codec to register
0d0cf00a 3293 */
f0fba2ad 3294int snd_soc_register_codec(struct device *dev,
001ae4c0
MB
3295 const struct snd_soc_codec_driver *codec_drv,
3296 struct snd_soc_dai_driver *dai_drv,
3297 int num_dai)
0d0cf00a 3298{
3335ddca 3299 size_t reg_size;
f0fba2ad
LG
3300 struct snd_soc_codec *codec;
3301 int ret, i;
151ab22c 3302
f0fba2ad
LG
3303 dev_dbg(dev, "codec register %s\n", dev_name(dev));
3304
3305 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3306 if (codec == NULL)
3307 return -ENOMEM;
0d0cf00a 3308
f0fba2ad
LG
3309 /* create CODEC component name */
3310 codec->name = fmt_single_name(dev, &codec->id);
3311 if (codec->name == NULL) {
3312 kfree(codec);
3313 return -ENOMEM;
3314 }
3315
23bbce34
DP
3316 if (codec_drv->compress_type)
3317 codec->compress_type = codec_drv->compress_type;
3318 else
3319 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3320
c3acec26
MB
3321 codec->write = codec_drv->write;
3322 codec->read = codec_drv->read;
1500b7b5
DP
3323 codec->volatile_register = codec_drv->volatile_register;
3324 codec->readable_register = codec_drv->readable_register;
8020454c 3325 codec->writable_register = codec_drv->writable_register;
5124e69e 3326 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
ce6120cc
LG
3327 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3328 codec->dapm.dev = dev;
3329 codec->dapm.codec = codec;
474b62d6 3330 codec->dapm.seq_notifier = codec_drv->seq_notifier;
64a648c2 3331 codec->dapm.stream_event = codec_drv->stream_event;
7a30a3db
DP
3332 codec->dev = dev;
3333 codec->driver = codec_drv;
3334 codec->num_dai = num_dai;
3335 mutex_init(&codec->mutex);
ce6120cc 3336
f0fba2ad
LG
3337 /* allocate CODEC register cache */
3338 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3335ddca 3339 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
aea170a0 3340 codec->reg_size = reg_size;
3335ddca
DP
3341 /* it is necessary to make a copy of the default register cache
3342 * because in the case of using a compression type that requires
3343 * the default register cache to be marked as __devinitconst the
3344 * kernel might have freed the array by the time we initialize
3345 * the cache.
3346 */
2aa86323
DP
3347 if (codec_drv->reg_cache_default) {
3348 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3349 reg_size, GFP_KERNEL);
3350 if (!codec->reg_def_copy) {
3351 ret = -ENOMEM;
3352 goto fail;
3353 }
f0fba2ad 3354 }
151ab22c
MB
3355 }
3356
1500b7b5
DP
3357 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3358 if (!codec->volatile_register)
3359 codec->volatile_register = snd_soc_default_volatile_register;
3360 if (!codec->readable_register)
3361 codec->readable_register = snd_soc_default_readable_register;
8020454c
DP
3362 if (!codec->writable_register)
3363 codec->writable_register = snd_soc_default_writable_register;
1500b7b5
DP
3364 }
3365
f0fba2ad
LG
3366 for (i = 0; i < num_dai; i++) {
3367 fixup_codec_formats(&dai_drv[i].playback);
3368 fixup_codec_formats(&dai_drv[i].capture);
3369 }
3370
26b01ccd
MB
3371 /* register any DAIs */
3372 if (num_dai) {
3373 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3374 if (ret < 0)
fdf0f54d 3375 goto fail;
26b01ccd 3376 }
f0fba2ad 3377
0d0cf00a
MB
3378 mutex_lock(&client_mutex);
3379 list_add(&codec->list, &codec_list);
3380 snd_soc_instantiate_cards();
3381 mutex_unlock(&client_mutex);
3382
3383 pr_debug("Registered codec '%s'\n", codec->name);
0d0cf00a 3384 return 0;
f0fba2ad 3385
fdf0f54d 3386fail:
3335ddca
DP
3387 kfree(codec->reg_def_copy);
3388 codec->reg_def_copy = NULL;
f0fba2ad
LG
3389 kfree(codec->name);
3390 kfree(codec);
3391 return ret;
0d0cf00a
MB
3392}
3393EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3394
3395/**
3396 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3397 *
ac11a2b3 3398 * @codec: codec to unregister
0d0cf00a 3399 */
f0fba2ad 3400void snd_soc_unregister_codec(struct device *dev)
0d0cf00a 3401{
f0fba2ad
LG
3402 struct snd_soc_codec *codec;
3403 int i;
3404
3405 list_for_each_entry(codec, &codec_list, list) {
3406 if (dev == codec->dev)
3407 goto found;
3408 }
3409 return;
3410
3411found:
26b01ccd
MB
3412 if (codec->num_dai)
3413 for (i = 0; i < codec->num_dai; i++)
3414 snd_soc_unregister_dai(dev);
f0fba2ad 3415
0d0cf00a
MB
3416 mutex_lock(&client_mutex);
3417 list_del(&codec->list);
3418 mutex_unlock(&client_mutex);
3419
3420 pr_debug("Unregistered codec '%s'\n", codec->name);
f0fba2ad 3421
7a30a3db 3422 snd_soc_cache_exit(codec);
3335ddca 3423 kfree(codec->reg_def_copy);
1aafcd4d 3424 kfree(codec->name);
f0fba2ad 3425 kfree(codec);
0d0cf00a
MB
3426}
3427EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3428
bec4fa05
SW
3429/* Retrieve a card's name from device tree */
3430int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3431 const char *propname)
3432{
3433 struct device_node *np = card->dev->of_node;
3434 int ret;
3435
3436 ret = of_property_read_string_index(np, propname, 0, &card->name);
3437 /*
3438 * EINVAL means the property does not exist. This is fine providing
3439 * card->name was previously set, which is checked later in
3440 * snd_soc_register_card.
3441 */
3442 if (ret < 0 && ret != -EINVAL) {
3443 dev_err(card->dev,
3444 "Property '%s' could not be read: %d\n",
3445 propname, ret);
3446 return ret;
3447 }
3448
3449 return 0;
3450}
3451EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3452
a4a54dd5
SW
3453int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3454 const char *propname)
3455{
3456 struct device_node *np = card->dev->of_node;
3457 int num_routes;
3458 struct snd_soc_dapm_route *routes;
3459 int i, ret;
3460
3461 num_routes = of_property_count_strings(np, propname);
3462 if (num_routes & 1) {
3463 dev_err(card->dev,
3464 "Property '%s's length is not even\n",
3465 propname);
3466 return -EINVAL;
3467 }
3468 num_routes /= 2;
3469 if (!num_routes) {
3470 dev_err(card->dev,
3471 "Property '%s's length is zero\n",
3472 propname);
3473 return -EINVAL;
3474 }
3475
3476 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3477 GFP_KERNEL);
3478 if (!routes) {
3479 dev_err(card->dev,
3480 "Could not allocate DAPM route table\n");
3481 return -EINVAL;
3482 }
3483
3484 for (i = 0; i < num_routes; i++) {
3485 ret = of_property_read_string_index(np, propname,
3486 2 * i, &routes[i].sink);
3487 if (ret) {
3488 dev_err(card->dev,
3489 "Property '%s' index %d could not be read: %d\n",
3490 propname, 2 * i, ret);
3491 return -EINVAL;
3492 }
3493 ret = of_property_read_string_index(np, propname,
3494 (2 * i) + 1, &routes[i].source);
3495 if (ret) {
3496 dev_err(card->dev,
3497 "Property '%s' index %d could not be read: %d\n",
3498 propname, (2 * i) + 1, ret);
3499 return -EINVAL;
3500 }
3501 }
3502
3503 card->num_dapm_routes = num_routes;
3504 card->dapm_routes = routes;
3505
3506 return 0;
3507}
3508EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3509
c9b3a40f 3510static int __init snd_soc_init(void)
db2a4165 3511{
384c89e2 3512#ifdef CONFIG_DEBUG_FS
8a9dab1a
MB
3513 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3514 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
384c89e2
MB
3515 printk(KERN_WARNING
3516 "ASoC: Failed to create debugfs directory\n");
8a9dab1a 3517 snd_soc_debugfs_root = NULL;
384c89e2 3518 }
c3c5a19a 3519
8a9dab1a 3520 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
c3c5a19a
MB
3521 &codec_list_fops))
3522 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3523
8a9dab1a 3524 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
f3208780
MB
3525 &dai_list_fops))
3526 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
19c7ac27 3527
8a9dab1a 3528 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
19c7ac27
MB
3529 &platform_list_fops))
3530 pr_warn("ASoC: Failed to create platform list debugfs file\n");
384c89e2
MB
3531#endif
3532
fb257897
MB
3533 snd_soc_util_init();
3534
db2a4165
FM
3535 return platform_driver_register(&soc_driver);
3536}
4abe8e16 3537module_init(snd_soc_init);
db2a4165 3538
7d8c16a6 3539static void __exit snd_soc_exit(void)
db2a4165 3540{
fb257897
MB
3541 snd_soc_util_exit();
3542
384c89e2 3543#ifdef CONFIG_DEBUG_FS
8a9dab1a 3544 debugfs_remove_recursive(snd_soc_debugfs_root);
384c89e2 3545#endif
3ff3f64b 3546 platform_driver_unregister(&soc_driver);
db2a4165 3547}
db2a4165
FM
3548module_exit(snd_soc_exit);
3549
3550/* Module information */
d331124d 3551MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
db2a4165
FM
3552MODULE_DESCRIPTION("ALSA SoC Core");
3553MODULE_LICENSE("GPL");
8b45a209 3554MODULE_ALIAS("platform:soc-audio");
This page took 0.599192 seconds and 5 git commands to generate.