Merge remote-tracking branch 'asoc/topic/arizona' into asoc-next
[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>
741a509f 33#include <linux/pinctrl/consumer.h>
f0e8ed85 34#include <linux/ctype.h>
5a0e3ad6 35#include <linux/slab.h>
bec4fa05 36#include <linux/of.h>
741a509f
MP
37#include <linux/gpio.h>
38#include <linux/of_gpio.h>
474828a4 39#include <sound/ac97_codec.h>
db2a4165 40#include <sound/core.h>
3028eb8c 41#include <sound/jack.h>
db2a4165
FM
42#include <sound/pcm.h>
43#include <sound/pcm_params.h>
44#include <sound/soc.h>
01d7584c 45#include <sound/soc-dpcm.h>
db2a4165
FM
46#include <sound/initval.h>
47
a8b1d34f
MB
48#define CREATE_TRACE_POINTS
49#include <trace/events/asoc.h>
50
f0fba2ad
LG
51#define NAME_SIZE 32
52
db2a4165
FM
53static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
54
384c89e2 55#ifdef CONFIG_DEBUG_FS
8a9dab1a
MB
56struct dentry *snd_soc_debugfs_root;
57EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
384c89e2
MB
58#endif
59
c5af3a2e 60static DEFINE_MUTEX(client_mutex);
9115171a 61static LIST_HEAD(dai_list);
12a48a8c 62static LIST_HEAD(platform_list);
0d0cf00a 63static LIST_HEAD(codec_list);
030e79f6 64static LIST_HEAD(component_list);
c5af3a2e 65
db2a4165
FM
66/*
67 * This is a timeout to do a DAPM powerdown after a stream is closed().
68 * It can be used to eliminate pops between different playback streams, e.g.
69 * between two audio tracks.
70 */
71static int pmdown_time = 5000;
72module_param(pmdown_time, int, 0);
73MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
74
741a509f
MP
75struct snd_ac97_reset_cfg {
76 struct pinctrl *pctl;
77 struct pinctrl_state *pstate_reset;
78 struct pinctrl_state *pstate_warm_reset;
79 struct pinctrl_state *pstate_run;
80 int gpio_sdata;
81 int gpio_sync;
82 int gpio_reset;
83};
84
2bc9a81e
DP
85/* returns the minimum number of bytes needed to represent
86 * a particular given value */
87static int min_bytes_needed(unsigned long val)
88{
89 int c = 0;
90 int i;
91
92 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
93 if (val & (1UL << i))
94 break;
95 c = (sizeof val * 8) - c;
96 if (!c || (c % 8))
97 c = (c + 8) / 8;
98 else
99 c /= 8;
100 return c;
101}
102
13fd179f
DP
103/* fill buf which is 'len' bytes with a formatted
104 * string of the form 'reg: value\n' */
105static int format_register_str(struct snd_soc_codec *codec,
106 unsigned int reg, char *buf, size_t len)
107{
00b317a4
SW
108 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
109 int regsize = codec->driver->reg_word_size * 2;
13fd179f
DP
110 int ret;
111 char tmpbuf[len + 1];
112 char regbuf[regsize + 1];
113
114 /* since tmpbuf is allocated on the stack, warn the callers if they
115 * try to abuse this function */
116 WARN_ON(len > 63);
117
118 /* +2 for ': ' and + 1 for '\n' */
119 if (wordsize + regsize + 2 + 1 != len)
120 return -EINVAL;
121
25032c11 122 ret = snd_soc_read(codec, reg);
13fd179f
DP
123 if (ret < 0) {
124 memset(regbuf, 'X', regsize);
125 regbuf[regsize] = '\0';
126 } else {
127 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
128 }
129
130 /* prepare the buffer */
131 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
132 /* copy it back to the caller without the '\0' */
133 memcpy(buf, tmpbuf, len);
134
135 return 0;
136}
137
2624d5fa 138/* codec register dump */
13fd179f
DP
139static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
140 size_t count, loff_t pos)
2624d5fa 141{
13fd179f 142 int i, step = 1;
2bc9a81e 143 int wordsize, regsize;
13fd179f
DP
144 int len;
145 size_t total = 0;
146 loff_t p = 0;
2bc9a81e 147
00b317a4
SW
148 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
149 regsize = codec->driver->reg_word_size * 2;
2624d5fa 150
13fd179f
DP
151 len = wordsize + regsize + 2 + 1;
152
f0fba2ad 153 if (!codec->driver->reg_cache_size)
2624d5fa
MB
154 return 0;
155
f0fba2ad
LG
156 if (codec->driver->reg_cache_step)
157 step = codec->driver->reg_cache_step;
2624d5fa 158
f0fba2ad 159 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
b92d150b 160 if (!snd_soc_codec_readable_register(codec, i))
2624d5fa 161 continue;
f0fba2ad
LG
162 if (codec->driver->display_register) {
163 count += codec->driver->display_register(codec, buf + count,
2624d5fa 164 PAGE_SIZE - count, i);
5164d74d 165 } else {
13fd179f
DP
166 /* only support larger than PAGE_SIZE bytes debugfs
167 * entries for the default case */
168 if (p >= pos) {
169 if (total + len >= count - 1)
170 break;
171 format_register_str(codec, i, buf + total, len);
172 total += len;
173 }
174 p += len;
5164d74d 175 }
2624d5fa
MB
176 }
177
13fd179f 178 total = min(total, count - 1);
2624d5fa 179
13fd179f 180 return total;
2624d5fa 181}
13fd179f 182
2624d5fa
MB
183static ssize_t codec_reg_show(struct device *dev,
184 struct device_attribute *attr, char *buf)
185{
36ae1a96 186 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
f0fba2ad 187
13fd179f 188 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
2624d5fa
MB
189}
190
191static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
192
dbe21408
MB
193static ssize_t pmdown_time_show(struct device *dev,
194 struct device_attribute *attr, char *buf)
195{
36ae1a96 196 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
dbe21408 197
f0fba2ad 198 return sprintf(buf, "%ld\n", rtd->pmdown_time);
dbe21408
MB
199}
200
201static ssize_t pmdown_time_set(struct device *dev,
202 struct device_attribute *attr,
203 const char *buf, size_t count)
204{
36ae1a96 205 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
c593b520 206 int ret;
dbe21408 207
c593b520
MB
208 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
209 if (ret)
210 return ret;
dbe21408
MB
211
212 return count;
213}
214
215static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
216
2624d5fa 217#ifdef CONFIG_DEBUG_FS
2624d5fa 218static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
13fd179f 219 size_t count, loff_t *ppos)
2624d5fa
MB
220{
221 ssize_t ret;
222 struct snd_soc_codec *codec = file->private_data;
13fd179f
DP
223 char *buf;
224
225 if (*ppos < 0 || !count)
226 return -EINVAL;
227
228 buf = kmalloc(count, GFP_KERNEL);
2624d5fa
MB
229 if (!buf)
230 return -ENOMEM;
13fd179f
DP
231
232 ret = soc_codec_reg_show(codec, buf, count, *ppos);
233 if (ret >= 0) {
234 if (copy_to_user(user_buf, buf, ret)) {
235 kfree(buf);
236 return -EFAULT;
237 }
238 *ppos += ret;
239 }
240
2624d5fa
MB
241 kfree(buf);
242 return ret;
243}
244
245static ssize_t codec_reg_write_file(struct file *file,
246 const char __user *user_buf, size_t count, loff_t *ppos)
247{
248 char buf[32];
34e268d8 249 size_t buf_size;
2624d5fa
MB
250 char *start = buf;
251 unsigned long reg, value;
2624d5fa
MB
252 struct snd_soc_codec *codec = file->private_data;
253
254 buf_size = min(count, (sizeof(buf)-1));
255 if (copy_from_user(buf, user_buf, buf_size))
256 return -EFAULT;
257 buf[buf_size] = 0;
2624d5fa
MB
258
259 while (*start == ' ')
260 start++;
261 reg = simple_strtoul(start, &start, 16);
2624d5fa
MB
262 while (*start == ' ')
263 start++;
264 if (strict_strtoul(start, 16, &value))
265 return -EINVAL;
0d51a9cb
MB
266
267 /* Userspace has been fiddling around behind the kernel's back */
373d4d09 268 add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
0d51a9cb 269
e4f078d8 270 snd_soc_write(codec, reg, value);
2624d5fa
MB
271 return buf_size;
272}
273
274static const struct file_operations codec_reg_fops = {
234e3405 275 .open = simple_open,
2624d5fa
MB
276 .read = codec_reg_read_file,
277 .write = codec_reg_write_file,
6038f373 278 .llseek = default_llseek,
2624d5fa
MB
279};
280
281static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
282{
d6ce4cf3
JN
283 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
284
285 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
286 debugfs_card_root);
2624d5fa 287 if (!codec->debugfs_codec_root) {
10e8aa9a
MM
288 dev_warn(codec->dev,
289 "ASoC: Failed to create codec debugfs directory\n");
2624d5fa
MB
290 return;
291 }
292
aaee8ef1
MB
293 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
294 &codec->cache_sync);
295 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
296 &codec->cache_only);
297
2624d5fa
MB
298 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
299 codec->debugfs_codec_root,
300 codec, &codec_reg_fops);
301 if (!codec->debugfs_reg)
10e8aa9a
MM
302 dev_warn(codec->dev,
303 "ASoC: Failed to create codec register debugfs file\n");
2624d5fa 304
8eecaf62 305 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
2624d5fa
MB
306}
307
308static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
309{
310 debugfs_remove_recursive(codec->debugfs_codec_root);
311}
312
731f1ab2
SG
313static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
314{
315 struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
316
317 platform->debugfs_platform_root = debugfs_create_dir(platform->name,
318 debugfs_card_root);
319 if (!platform->debugfs_platform_root) {
320 dev_warn(platform->dev,
f110bfc7 321 "ASoC: Failed to create platform debugfs directory\n");
731f1ab2
SG
322 return;
323 }
324
325 snd_soc_dapm_debugfs_init(&platform->dapm,
326 platform->debugfs_platform_root);
327}
328
329static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
330{
331 debugfs_remove_recursive(platform->debugfs_platform_root);
332}
333
c3c5a19a
MB
334static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
335 size_t count, loff_t *ppos)
336{
337 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 338 ssize_t len, ret = 0;
c3c5a19a
MB
339 struct snd_soc_codec *codec;
340
341 if (!buf)
342 return -ENOMEM;
343
2b194f9d
MB
344 list_for_each_entry(codec, &codec_list, list) {
345 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
346 codec->name);
347 if (len >= 0)
348 ret += len;
349 if (ret > PAGE_SIZE) {
350 ret = PAGE_SIZE;
351 break;
352 }
353 }
c3c5a19a
MB
354
355 if (ret >= 0)
356 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
357
358 kfree(buf);
359
360 return ret;
361}
362
363static const struct file_operations codec_list_fops = {
364 .read = codec_list_read_file,
365 .llseek = default_llseek,/* read accesses f_pos */
366};
367
f3208780
MB
368static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
369 size_t count, loff_t *ppos)
370{
371 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 372 ssize_t len, ret = 0;
f3208780
MB
373 struct snd_soc_dai *dai;
374
375 if (!buf)
376 return -ENOMEM;
377
2b194f9d
MB
378 list_for_each_entry(dai, &dai_list, list) {
379 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
380 if (len >= 0)
381 ret += len;
382 if (ret > PAGE_SIZE) {
383 ret = PAGE_SIZE;
384 break;
385 }
386 }
f3208780 387
2b194f9d 388 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
f3208780
MB
389
390 kfree(buf);
391
392 return ret;
393}
394
395static const struct file_operations dai_list_fops = {
396 .read = dai_list_read_file,
397 .llseek = default_llseek,/* read accesses f_pos */
398};
399
19c7ac27
MB
400static ssize_t platform_list_read_file(struct file *file,
401 char __user *user_buf,
402 size_t count, loff_t *ppos)
403{
404 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
2b194f9d 405 ssize_t len, ret = 0;
19c7ac27
MB
406 struct snd_soc_platform *platform;
407
408 if (!buf)
409 return -ENOMEM;
410
2b194f9d
MB
411 list_for_each_entry(platform, &platform_list, list) {
412 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
413 platform->name);
414 if (len >= 0)
415 ret += len;
416 if (ret > PAGE_SIZE) {
417 ret = PAGE_SIZE;
418 break;
419 }
420 }
19c7ac27 421
2b194f9d 422 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
19c7ac27
MB
423
424 kfree(buf);
425
426 return ret;
427}
428
429static const struct file_operations platform_list_fops = {
430 .read = platform_list_read_file,
431 .llseek = default_llseek,/* read accesses f_pos */
432};
433
a6052154
JN
434static void soc_init_card_debugfs(struct snd_soc_card *card)
435{
436 card->debugfs_card_root = debugfs_create_dir(card->name,
8a9dab1a 437 snd_soc_debugfs_root);
3a45b867 438 if (!card->debugfs_card_root) {
a6052154 439 dev_warn(card->dev,
7c08be84 440 "ASoC: Failed to create card debugfs directory\n");
3a45b867
JN
441 return;
442 }
443
444 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
445 card->debugfs_card_root,
446 &card->pop_time);
447 if (!card->debugfs_pop_time)
448 dev_warn(card->dev,
f110bfc7 449 "ASoC: Failed to create pop time debugfs file\n");
a6052154
JN
450}
451
452static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
453{
454 debugfs_remove_recursive(card->debugfs_card_root);
455}
456
2624d5fa
MB
457#else
458
459static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
460{
461}
462
463static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
464{
465}
b95fccbc 466
731f1ab2
SG
467static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
468{
469}
470
471static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
472{
473}
474
b95fccbc
AL
475static inline void soc_init_card_debugfs(struct snd_soc_card *card)
476{
477}
478
479static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
480{
481}
2624d5fa
MB
482#endif
483
47c88fff
LG
484struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
485 const char *dai_link, int stream)
486{
487 int i;
488
489 for (i = 0; i < card->num_links; i++) {
490 if (card->rtd[i].dai_link->no_pcm &&
491 !strcmp(card->rtd[i].dai_link->name, dai_link))
492 return card->rtd[i].pcm->streams[stream].substream;
493 }
f110bfc7 494 dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
47c88fff
LG
495 return NULL;
496}
497EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
498
499struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
500 const char *dai_link)
501{
502 int i;
503
504 for (i = 0; i < card->num_links; i++) {
505 if (!strcmp(card->rtd[i].dai_link->name, dai_link))
506 return &card->rtd[i];
507 }
f110bfc7 508 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
47c88fff
LG
509 return NULL;
510}
511EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
512
db2a4165
FM
513#ifdef CONFIG_SND_SOC_AC97_BUS
514/* unregister ac97 codec */
515static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
516{
517 if (codec->ac97->dev.bus)
518 device_unregister(&codec->ac97->dev);
519 return 0;
520}
521
522/* stop no dev release warning */
523static void soc_ac97_device_release(struct device *dev){}
524
525/* register ac97 codec to bus */
526static int soc_ac97_dev_register(struct snd_soc_codec *codec)
527{
528 int err;
529
530 codec->ac97->dev.bus = &ac97_bus_type;
4ac5c61f 531 codec->ac97->dev.parent = codec->card->dev;
db2a4165
FM
532 codec->ac97->dev.release = soc_ac97_device_release;
533
bb072bf0 534 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
f0fba2ad 535 codec->card->snd_card->number, 0, codec->name);
db2a4165
FM
536 err = device_register(&codec->ac97->dev);
537 if (err < 0) {
f110bfc7 538 dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
db2a4165
FM
539 codec->ac97->dev.bus = NULL;
540 return err;
541 }
542 return 0;
543}
544#endif
545
6f8ab4ac 546#ifdef CONFIG_PM_SLEEP
db2a4165 547/* powers down audio subsystem for suspend */
6f8ab4ac 548int snd_soc_suspend(struct device *dev)
db2a4165 549{
6f8ab4ac 550 struct snd_soc_card *card = dev_get_drvdata(dev);
2eea392d 551 struct snd_soc_codec *codec;
db2a4165
FM
552 int i;
553
e3509ff0
DM
554 /* If the initialization of this soc device failed, there is no codec
555 * associated with it. Just bail out in this case.
556 */
f0fba2ad 557 if (list_empty(&card->codec_dev_list))
e3509ff0
DM
558 return 0;
559
6ed25978
AG
560 /* Due to the resume being scheduled into a workqueue we could
561 * suspend before that's finished - wait for it to complete.
562 */
f0fba2ad
LG
563 snd_power_lock(card->snd_card);
564 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
565 snd_power_unlock(card->snd_card);
6ed25978
AG
566
567 /* we're going to block userspace touching us until resume completes */
f0fba2ad 568 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
6ed25978 569
a00f90f9 570 /* mute any active DACs */
f0fba2ad
LG
571 for (i = 0; i < card->num_rtd; i++) {
572 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
573 struct snd_soc_dai_driver *drv = dai->driver;
3efab7dc 574
f0fba2ad 575 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
576 continue;
577
f0fba2ad
LG
578 if (drv->ops->digital_mute && dai->playback_active)
579 drv->ops->digital_mute(dai, 1);
db2a4165
FM
580 }
581
4ccab3e7 582 /* suspend all pcms */
f0fba2ad
LG
583 for (i = 0; i < card->num_rtd; i++) {
584 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
585 continue;
586
f0fba2ad 587 snd_pcm_suspend_all(card->rtd[i].pcm);
3efab7dc 588 }
4ccab3e7 589
87506549 590 if (card->suspend_pre)
70b2ac12 591 card->suspend_pre(card);
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;
595 struct snd_soc_platform *platform = card->rtd[i].platform;
3efab7dc 596
f0fba2ad 597 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
598 continue;
599
f0fba2ad
LG
600 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
601 cpu_dai->driver->suspend(cpu_dai);
602 if (platform->driver->suspend && !platform->suspended) {
603 platform->driver->suspend(cpu_dai);
604 platform->suspended = 1;
605 }
db2a4165
FM
606 }
607
608 /* close any waiting streams and save state */
f0fba2ad 609 for (i = 0; i < card->num_rtd; i++) {
43829731 610 flush_delayed_work(&card->rtd[i].delayed_work);
ce6120cc 611 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
f0fba2ad 612 }
db2a4165 613
f0fba2ad 614 for (i = 0; i < card->num_rtd; i++) {
3efab7dc 615
f0fba2ad 616 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
617 continue;
618
7bd3a6f3
MB
619 snd_soc_dapm_stream_event(&card->rtd[i],
620 SNDRV_PCM_STREAM_PLAYBACK,
7bd3a6f3 621 SND_SOC_DAPM_STREAM_SUSPEND);
f0fba2ad 622
7bd3a6f3
MB
623 snd_soc_dapm_stream_event(&card->rtd[i],
624 SNDRV_PCM_STREAM_CAPTURE,
7bd3a6f3 625 SND_SOC_DAPM_STREAM_SUSPEND);
db2a4165
FM
626 }
627
e2d32ff6
MB
628 /* Recheck all analogue paths too */
629 dapm_mark_io_dirty(&card->dapm);
630 snd_soc_dapm_sync(&card->dapm);
631
f0fba2ad 632 /* suspend all CODECs */
2eea392d 633 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
f0fba2ad
LG
634 /* If there are paths active then the CODEC will be held with
635 * bias _ON and should not be suspended. */
636 if (!codec->suspended && codec->driver->suspend) {
ce6120cc 637 switch (codec->dapm.bias_level) {
f0fba2ad 638 case SND_SOC_BIAS_STANDBY:
125a25da
MB
639 /*
640 * If the CODEC is capable of idle
641 * bias off then being in STANDBY
642 * means it's doing something,
643 * otherwise fall through.
644 */
645 if (codec->dapm.idle_bias_off) {
646 dev_dbg(codec->dev,
10e8aa9a 647 "ASoC: idle_bias_off CODEC on over suspend\n");
125a25da
MB
648 break;
649 }
f0fba2ad 650 case SND_SOC_BIAS_OFF:
84b315ee 651 codec->driver->suspend(codec);
f0fba2ad 652 codec->suspended = 1;
7be4ba24 653 codec->cache_sync = 1;
da8b8e0f
MB
654 if (codec->using_regmap)
655 regcache_mark_dirty(codec->control_data);
f0fba2ad
LG
656 break;
657 default:
10e8aa9a
MM
658 dev_dbg(codec->dev,
659 "ASoC: CODEC is on over suspend\n");
f0fba2ad
LG
660 break;
661 }
1547aba9
MB
662 }
663 }
db2a4165 664
f0fba2ad
LG
665 for (i = 0; i < card->num_rtd; i++) {
666 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3efab7dc 667
f0fba2ad 668 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
669 continue;
670
f0fba2ad
LG
671 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
672 cpu_dai->driver->suspend(cpu_dai);
db2a4165
FM
673 }
674
87506549 675 if (card->suspend_post)
70b2ac12 676 card->suspend_post(card);
db2a4165
FM
677
678 return 0;
679}
6f8ab4ac 680EXPORT_SYMBOL_GPL(snd_soc_suspend);
db2a4165 681
6ed25978
AG
682/* deferred resume work, so resume can complete before we finished
683 * setting our codec back up, which can be very slow on I2C
684 */
685static void soc_resume_deferred(struct work_struct *work)
db2a4165 686{
f0fba2ad
LG
687 struct snd_soc_card *card =
688 container_of(work, struct snd_soc_card, deferred_resume_work);
2eea392d 689 struct snd_soc_codec *codec;
db2a4165
FM
690 int i;
691
6ed25978
AG
692 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
693 * so userspace apps are blocked from touching us
694 */
695
f110bfc7 696 dev_dbg(card->dev, "ASoC: starting resume work\n");
6ed25978 697
9949788b 698 /* Bring us up into D2 so that DAPM starts enabling things */
f0fba2ad 699 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
9949788b 700
87506549 701 if (card->resume_pre)
70b2ac12 702 card->resume_pre(card);
db2a4165 703
f0fba2ad
LG
704 /* resume AC97 DAIs */
705 for (i = 0; i < card->num_rtd; i++) {
706 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3efab7dc 707
f0fba2ad 708 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
709 continue;
710
f0fba2ad
LG
711 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
712 cpu_dai->driver->resume(cpu_dai);
713 }
714
2eea392d 715 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
f0fba2ad
LG
716 /* If the CODEC was idle over suspend then it will have been
717 * left with bias OFF or STANDBY and suspended so we must now
718 * resume. Otherwise the suspend was suppressed.
719 */
720 if (codec->driver->resume && codec->suspended) {
ce6120cc 721 switch (codec->dapm.bias_level) {
f0fba2ad
LG
722 case SND_SOC_BIAS_STANDBY:
723 case SND_SOC_BIAS_OFF:
724 codec->driver->resume(codec);
725 codec->suspended = 0;
726 break;
727 default:
10e8aa9a
MM
728 dev_dbg(codec->dev,
729 "ASoC: CODEC was on over suspend\n");
f0fba2ad
LG
730 break;
731 }
1547aba9
MB
732 }
733 }
db2a4165 734
f0fba2ad 735 for (i = 0; i < card->num_rtd; i++) {
3efab7dc 736
f0fba2ad 737 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
738 continue;
739
7bd3a6f3 740 snd_soc_dapm_stream_event(&card->rtd[i],
d9b0951b 741 SNDRV_PCM_STREAM_PLAYBACK,
7bd3a6f3 742 SND_SOC_DAPM_STREAM_RESUME);
f0fba2ad 743
7bd3a6f3 744 snd_soc_dapm_stream_event(&card->rtd[i],
d9b0951b 745 SNDRV_PCM_STREAM_CAPTURE,
7bd3a6f3 746 SND_SOC_DAPM_STREAM_RESUME);
db2a4165
FM
747 }
748
3ff3f64b 749 /* unmute any active DACs */
f0fba2ad
LG
750 for (i = 0; i < card->num_rtd; i++) {
751 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
752 struct snd_soc_dai_driver *drv = dai->driver;
3efab7dc 753
f0fba2ad 754 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
755 continue;
756
f0fba2ad
LG
757 if (drv->ops->digital_mute && dai->playback_active)
758 drv->ops->digital_mute(dai, 0);
db2a4165
FM
759 }
760
f0fba2ad
LG
761 for (i = 0; i < card->num_rtd; i++) {
762 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
763 struct snd_soc_platform *platform = card->rtd[i].platform;
3efab7dc 764
f0fba2ad 765 if (card->rtd[i].dai_link->ignore_suspend)
3efab7dc
MB
766 continue;
767
f0fba2ad
LG
768 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
769 cpu_dai->driver->resume(cpu_dai);
770 if (platform->driver->resume && platform->suspended) {
771 platform->driver->resume(cpu_dai);
772 platform->suspended = 0;
773 }
db2a4165
FM
774 }
775
87506549 776 if (card->resume_post)
70b2ac12 777 card->resume_post(card);
db2a4165 778
f110bfc7 779 dev_dbg(card->dev, "ASoC: resume work completed\n");
6ed25978
AG
780
781 /* userspace can access us now we are back as we were before */
f0fba2ad 782 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
e2d32ff6
MB
783
784 /* Recheck all analogue paths too */
785 dapm_mark_io_dirty(&card->dapm);
786 snd_soc_dapm_sync(&card->dapm);
6ed25978
AG
787}
788
789/* powers up audio subsystem after a suspend */
6f8ab4ac 790int snd_soc_resume(struct device *dev)
6ed25978 791{
6f8ab4ac 792 struct snd_soc_card *card = dev_get_drvdata(dev);
82e14e8b 793 int i, ac97_control = 0;
b9dd94a8 794
5ff1ddf2
EM
795 /* If the initialization of this soc device failed, there is no codec
796 * associated with it. Just bail out in this case.
797 */
798 if (list_empty(&card->codec_dev_list))
799 return 0;
800
64ab9baa
MB
801 /* AC97 devices might have other drivers hanging off them so
802 * need to resume immediately. Other drivers don't have that
803 * problem and may take a substantial amount of time to resume
804 * due to I/O costs and anti-pop so handle them out of line.
805 */
f0fba2ad
LG
806 for (i = 0; i < card->num_rtd; i++) {
807 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
82e14e8b
SW
808 ac97_control |= cpu_dai->driver->ac97_control;
809 }
810 if (ac97_control) {
f110bfc7 811 dev_dbg(dev, "ASoC: Resuming AC97 immediately\n");
82e14e8b
SW
812 soc_resume_deferred(&card->deferred_resume_work);
813 } else {
f110bfc7 814 dev_dbg(dev, "ASoC: Scheduling resume work\n");
82e14e8b 815 if (!schedule_work(&card->deferred_resume_work))
f110bfc7 816 dev_err(dev, "ASoC: resume work item may be lost\n");
64ab9baa 817 }
6ed25978 818
db2a4165
FM
819 return 0;
820}
6f8ab4ac 821EXPORT_SYMBOL_GPL(snd_soc_resume);
db2a4165 822#else
6f8ab4ac
MB
823#define snd_soc_suspend NULL
824#define snd_soc_resume NULL
db2a4165
FM
825#endif
826
85e7652d 827static const struct snd_soc_dai_ops null_dai_ops = {
02a06d30
BS
828};
829
f0fba2ad 830static int soc_bind_dai_link(struct snd_soc_card *card, int num)
db2a4165 831{
f0fba2ad
LG
832 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
833 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
fe3e78e0 834 struct snd_soc_codec *codec;
435c5e25 835 struct snd_soc_platform *platform;
f0fba2ad 836 struct snd_soc_dai *codec_dai, *cpu_dai;
848dd8be 837 const char *platform_name;
435c5e25 838
f110bfc7 839 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
435c5e25 840
b19e6e7b 841 /* Find CPU DAI from registered DAIs*/
f0fba2ad 842 list_for_each_entry(cpu_dai, &dai_list, list) {
bc92657a
SW
843 if (dai_link->cpu_of_node &&
844 (cpu_dai->dev->of_node != dai_link->cpu_of_node))
845 continue;
846 if (dai_link->cpu_name &&
847 strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name))
848 continue;
849 if (dai_link->cpu_dai_name &&
850 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
851 continue;
2610ab77
SW
852
853 rtd->cpu_dai = cpu_dai;
435c5e25 854 }
6308419a 855
b19e6e7b 856 if (!rtd->cpu_dai) {
f110bfc7 857 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
b19e6e7b
MB
858 dai_link->cpu_dai_name);
859 return -EPROBE_DEFER;
f0fba2ad
LG
860 }
861
b19e6e7b 862 /* Find CODEC from registered CODECs */
f0fba2ad 863 list_for_each_entry(codec, &codec_list, list) {
5a504963
SW
864 if (dai_link->codec_of_node) {
865 if (codec->dev->of_node != dai_link->codec_of_node)
866 continue;
867 } else {
868 if (strcmp(codec->name, dai_link->codec_name))
869 continue;
870 }
2610ab77
SW
871
872 rtd->codec = codec;
873
874 /*
875 * CODEC found, so find CODEC DAI from registered DAIs from
876 * this CODEC
877 */
878 list_for_each_entry(codec_dai, &dai_list, list) {
879 if (codec->dev == codec_dai->dev &&
880 !strcmp(codec_dai->name,
881 dai_link->codec_dai_name)) {
f0fba2ad 882
2610ab77 883 rtd->codec_dai = codec_dai;
2610ab77 884 }
435c5e25 885 }
2610ab77 886
b19e6e7b 887 if (!rtd->codec_dai) {
f110bfc7 888 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
b19e6e7b
MB
889 dai_link->codec_dai_name);
890 return -EPROBE_DEFER;
891 }
f0fba2ad 892 }
6b05eda6 893
b19e6e7b 894 if (!rtd->codec) {
f110bfc7 895 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
b19e6e7b
MB
896 dai_link->codec_name);
897 return -EPROBE_DEFER;
898 }
848dd8be
MB
899
900 /* if there's no platform we match on the empty platform */
901 platform_name = dai_link->platform_name;
5a504963 902 if (!platform_name && !dai_link->platform_of_node)
848dd8be
MB
903 platform_name = "snd-soc-dummy";
904
b19e6e7b 905 /* find one from the set of registered platforms */
f0fba2ad 906 list_for_each_entry(platform, &platform_list, list) {
5a504963
SW
907 if (dai_link->platform_of_node) {
908 if (platform->dev->of_node !=
909 dai_link->platform_of_node)
910 continue;
911 } else {
912 if (strcmp(platform->name, platform_name))
913 continue;
914 }
2610ab77
SW
915
916 rtd->platform = platform;
02a06d30 917 }
b19e6e7b 918 if (!rtd->platform) {
f110bfc7 919 dev_err(card->dev, "ASoC: platform %s not registered\n",
f0fba2ad 920 dai_link->platform_name);
b19e6e7b 921 return -EPROBE_DEFER;
f0fba2ad 922 }
b19e6e7b
MB
923
924 card->num_rtd++;
925
926 return 0;
f0fba2ad
LG
927}
928
d12cd198
SW
929static int soc_remove_platform(struct snd_soc_platform *platform)
930{
931 int ret;
932
933 if (platform->driver->remove) {
934 ret = platform->driver->remove(platform);
935 if (ret < 0)
f110bfc7
LG
936 dev_err(platform->dev, "ASoC: failed to remove %d\n",
937 ret);
d12cd198
SW
938 }
939
940 /* Make sure all DAPM widgets are freed */
941 snd_soc_dapm_free(&platform->dapm);
942
943 soc_cleanup_platform_debugfs(platform);
944 platform->probed = 0;
945 list_del(&platform->card_list);
946 module_put(platform->dev->driver->owner);
947
948 return 0;
949}
950
589c3563
JN
951static void soc_remove_codec(struct snd_soc_codec *codec)
952{
953 int err;
954
955 if (codec->driver->remove) {
956 err = codec->driver->remove(codec);
957 if (err < 0)
f110bfc7 958 dev_err(codec->dev, "ASoC: failed to remove %d\n", err);
589c3563
JN
959 }
960
961 /* Make sure all DAPM widgets are freed */
962 snd_soc_dapm_free(&codec->dapm);
963
964 soc_cleanup_codec_debugfs(codec);
965 codec->probed = 0;
966 list_del(&codec->card_list);
967 module_put(codec->dev->driver->owner);
968}
969
62ae68fa 970static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
f0fba2ad
LG
971{
972 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
f0fba2ad
LG
973 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
974 int err;
975
976 /* unregister the rtd device */
977 if (rtd->dev_registered) {
36ae1a96
MB
978 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
979 device_remove_file(rtd->dev, &dev_attr_codec_reg);
980 device_unregister(rtd->dev);
f0fba2ad
LG
981 rtd->dev_registered = 0;
982 }
983
984 /* remove the CODEC DAI */
0168bf0d
LG
985 if (codec_dai && codec_dai->probed &&
986 codec_dai->driver->remove_order == order) {
f0fba2ad
LG
987 if (codec_dai->driver->remove) {
988 err = codec_dai->driver->remove(codec_dai);
989 if (err < 0)
f110bfc7
LG
990 dev_err(codec_dai->dev,
991 "ASoC: failed to remove %s: %d\n",
992 codec_dai->name, err);
6b05eda6 993 }
f0fba2ad
LG
994 codec_dai->probed = 0;
995 list_del(&codec_dai->card_list);
996 }
6b05eda6 997
f0fba2ad 998 /* remove the cpu_dai */
0168bf0d
LG
999 if (cpu_dai && cpu_dai->probed &&
1000 cpu_dai->driver->remove_order == order) {
f0fba2ad
LG
1001 if (cpu_dai->driver->remove) {
1002 err = cpu_dai->driver->remove(cpu_dai);
1003 if (err < 0)
f110bfc7
LG
1004 dev_err(cpu_dai->dev,
1005 "ASoC: failed to remove %s: %d\n",
1006 cpu_dai->name, err);
db2a4165 1007 }
f0fba2ad
LG
1008 cpu_dai->probed = 0;
1009 list_del(&cpu_dai->card_list);
a9db7dbe 1010
18d75644
SW
1011 if (!cpu_dai->codec) {
1012 snd_soc_dapm_free(&cpu_dai->dapm);
a9db7dbe 1013 module_put(cpu_dai->dev->driver->owner);
18d75644 1014 }
db2a4165 1015 }
f0fba2ad 1016}
db2a4165 1017
62ae68fa
SW
1018static void soc_remove_link_components(struct snd_soc_card *card, int num,
1019 int order)
1020{
1021 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1022 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1023 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1024 struct snd_soc_platform *platform = rtd->platform;
1025 struct snd_soc_codec *codec;
1026
1027 /* remove the platform */
1028 if (platform && platform->probed &&
1029 platform->driver->remove_order == order) {
1030 soc_remove_platform(platform);
1031 }
1032
1033 /* remove the CODEC-side CODEC */
1034 if (codec_dai) {
1035 codec = codec_dai->codec;
1036 if (codec && codec->probed &&
1037 codec->driver->remove_order == order)
1038 soc_remove_codec(codec);
1039 }
1040
1041 /* remove any CPU-side CODEC */
1042 if (cpu_dai) {
1043 codec = cpu_dai->codec;
1044 if (codec && codec->probed &&
1045 codec->driver->remove_order == order)
1046 soc_remove_codec(codec);
1047 }
1048}
1049
0671fd8e
KM
1050static void soc_remove_dai_links(struct snd_soc_card *card)
1051{
0168bf0d 1052 int dai, order;
0671fd8e 1053
0168bf0d
LG
1054 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1055 order++) {
1056 for (dai = 0; dai < card->num_rtd; dai++)
62ae68fa
SW
1057 soc_remove_link_dais(card, dai, order);
1058 }
1059
1060 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1061 order++) {
1062 for (dai = 0; dai < card->num_rtd; dai++)
1063 soc_remove_link_components(card, dai, order);
0168bf0d 1064 }
62ae68fa 1065
0671fd8e
KM
1066 card->num_rtd = 0;
1067}
1068
ead9b919
JN
1069static void soc_set_name_prefix(struct snd_soc_card *card,
1070 struct snd_soc_codec *codec)
1071{
1072 int i;
1073
ff819b83 1074 if (card->codec_conf == NULL)
ead9b919
JN
1075 return;
1076
ff819b83
DP
1077 for (i = 0; i < card->num_configs; i++) {
1078 struct snd_soc_codec_conf *map = &card->codec_conf[i];
ead9b919
JN
1079 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1080 codec->name_prefix = map->name_prefix;
1081 break;
1082 }
1083 }
1084}
1085
589c3563
JN
1086static int soc_probe_codec(struct snd_soc_card *card,
1087 struct snd_soc_codec *codec)
1088{
1089 int ret = 0;
89b95ac0 1090 const struct snd_soc_codec_driver *driver = codec->driver;
888df395 1091 struct snd_soc_dai *dai;
589c3563
JN
1092
1093 codec->card = card;
1094 codec->dapm.card = card;
1095 soc_set_name_prefix(card, codec);
1096
70d29331
JN
1097 if (!try_module_get(codec->dev->driver->owner))
1098 return -ENODEV;
1099
d5d1e0be
LPC
1100 soc_init_codec_debugfs(codec);
1101
77530150
LPC
1102 if (driver->dapm_widgets)
1103 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
1104 driver->num_dapm_widgets);
1105
888df395
MB
1106 /* Create DAPM widgets for each DAI stream */
1107 list_for_each_entry(dai, &dai_list, list) {
1108 if (dai->dev != codec->dev)
1109 continue;
1110
1111 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
1112 }
1113
33c5f969
MB
1114 codec->dapm.idle_bias_off = driver->idle_bias_off;
1115
89b95ac0
MB
1116 if (driver->probe) {
1117 ret = driver->probe(codec);
589c3563
JN
1118 if (ret < 0) {
1119 dev_err(codec->dev,
f110bfc7 1120 "ASoC: failed to probe CODEC %d\n", ret);
70d29331 1121 goto err_probe;
589c3563 1122 }
ff541f4b
CL
1123 WARN(codec->dapm.idle_bias_off &&
1124 codec->dapm.bias_level != SND_SOC_BIAS_OFF,
10e8aa9a
MM
1125 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1126 codec->name);
589c3563
JN
1127 }
1128
38cbf959 1129 /* If the driver didn't set I/O up try regmap */
98d3088e 1130 if (!codec->write && dev_get_regmap(codec->dev, NULL))
38cbf959
MB
1131 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1132
b7af1daf 1133 if (driver->controls)
022658be 1134 snd_soc_add_codec_controls(codec, driver->controls,
b7af1daf 1135 driver->num_controls);
89b95ac0
MB
1136 if (driver->dapm_routes)
1137 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1138 driver->num_dapm_routes);
1139
589c3563
JN
1140 /* mark codec as probed and add to card codec list */
1141 codec->probed = 1;
1142 list_add(&codec->card_list, &card->codec_dev_list);
7be31be8 1143 list_add(&codec->dapm.list, &card->dapm_list);
589c3563 1144
70d29331
JN
1145 return 0;
1146
1147err_probe:
d5d1e0be 1148 soc_cleanup_codec_debugfs(codec);
70d29331
JN
1149 module_put(codec->dev->driver->owner);
1150
589c3563
JN
1151 return ret;
1152}
1153
956245e9
LG
1154static int soc_probe_platform(struct snd_soc_card *card,
1155 struct snd_soc_platform *platform)
1156{
1157 int ret = 0;
1158 const struct snd_soc_platform_driver *driver = platform->driver;
be09ad90 1159 struct snd_soc_dai *dai;
956245e9
LG
1160
1161 platform->card = card;
b7950641 1162 platform->dapm.card = card;
956245e9
LG
1163
1164 if (!try_module_get(platform->dev->driver->owner))
1165 return -ENODEV;
1166
731f1ab2
SG
1167 soc_init_platform_debugfs(platform);
1168
cb2cf612
LG
1169 if (driver->dapm_widgets)
1170 snd_soc_dapm_new_controls(&platform->dapm,
1171 driver->dapm_widgets, driver->num_dapm_widgets);
1172
be09ad90
LG
1173 /* Create DAPM widgets for each DAI stream */
1174 list_for_each_entry(dai, &dai_list, list) {
1175 if (dai->dev != platform->dev)
1176 continue;
1177
1178 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
1179 }
1180
3fec6b6d
SW
1181 platform->dapm.idle_bias_off = 1;
1182
956245e9
LG
1183 if (driver->probe) {
1184 ret = driver->probe(platform);
1185 if (ret < 0) {
1186 dev_err(platform->dev,
f110bfc7 1187 "ASoC: failed to probe platform %d\n", ret);
956245e9
LG
1188 goto err_probe;
1189 }
1190 }
1191
cb2cf612
LG
1192 if (driver->controls)
1193 snd_soc_add_platform_controls(platform, driver->controls,
1194 driver->num_controls);
1195 if (driver->dapm_routes)
1196 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1197 driver->num_dapm_routes);
1198
956245e9
LG
1199 /* mark platform as probed and add to card platform list */
1200 platform->probed = 1;
1201 list_add(&platform->card_list, &card->platform_dev_list);
b7950641 1202 list_add(&platform->dapm.list, &card->dapm_list);
956245e9
LG
1203
1204 return 0;
1205
1206err_probe:
02db1103 1207 soc_cleanup_platform_debugfs(platform);
956245e9
LG
1208 module_put(platform->dev->driver->owner);
1209
1210 return ret;
1211}
1212
36ae1a96
MB
1213static void rtd_release(struct device *dev)
1214{
1215 kfree(dev);
1216}
f0fba2ad 1217
589c3563
JN
1218static int soc_post_component_init(struct snd_soc_card *card,
1219 struct snd_soc_codec *codec,
1220 int num, int dailess)
1221{
1222 struct snd_soc_dai_link *dai_link = NULL;
1223 struct snd_soc_aux_dev *aux_dev = NULL;
1224 struct snd_soc_pcm_runtime *rtd;
1225 const char *temp, *name;
1226 int ret = 0;
1227
1228 if (!dailess) {
1229 dai_link = &card->dai_link[num];
1230 rtd = &card->rtd[num];
1231 name = dai_link->name;
1232 } else {
1233 aux_dev = &card->aux_dev[num];
1234 rtd = &card->rtd_aux[num];
1235 name = aux_dev->name;
1236 }
0962bb21 1237 rtd->card = card;
589c3563 1238
4b1cfcb4
MB
1239 /* Make sure all DAPM widgets are instantiated */
1240 snd_soc_dapm_new_widgets(&codec->dapm);
1241
589c3563
JN
1242 /* machine controls, routes and widgets are not prefixed */
1243 temp = codec->name_prefix;
1244 codec->name_prefix = NULL;
1245
1246 /* do machine specific initialization */
1247 if (!dailess && dai_link->init)
1248 ret = dai_link->init(rtd);
1249 else if (dailess && aux_dev->init)
1250 ret = aux_dev->init(&codec->dapm);
1251 if (ret < 0) {
f110bfc7 1252 dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
589c3563
JN
1253 return ret;
1254 }
1255 codec->name_prefix = temp;
1256
589c3563
JN
1257 /* register the rtd device */
1258 rtd->codec = codec;
36ae1a96
MB
1259
1260 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1261 if (!rtd->dev)
1262 return -ENOMEM;
1263 device_initialize(rtd->dev);
1264 rtd->dev->parent = card->dev;
1265 rtd->dev->release = rtd_release;
1266 rtd->dev->init_name = name;
1267 dev_set_drvdata(rtd->dev, rtd);
b8c0dab9 1268 mutex_init(&rtd->pcm_mutex);
01d7584c
LG
1269 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1270 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1271 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1272 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
36ae1a96 1273 ret = device_add(rtd->dev);
589c3563 1274 if (ret < 0) {
865df9cb
CL
1275 /* calling put_device() here to free the rtd->dev */
1276 put_device(rtd->dev);
589c3563 1277 dev_err(card->dev,
f110bfc7 1278 "ASoC: failed to register runtime device: %d\n", ret);
589c3563
JN
1279 return ret;
1280 }
1281 rtd->dev_registered = 1;
1282
1283 /* add DAPM sysfs entries for this codec */
36ae1a96 1284 ret = snd_soc_dapm_sys_add(rtd->dev);
589c3563
JN
1285 if (ret < 0)
1286 dev_err(codec->dev,
f110bfc7 1287 "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
589c3563
JN
1288
1289 /* add codec sysfs entries */
36ae1a96 1290 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
589c3563
JN
1291 if (ret < 0)
1292 dev_err(codec->dev,
f110bfc7 1293 "ASoC: failed to add codec sysfs files: %d\n", ret);
589c3563 1294
f86dcef8
LG
1295#ifdef CONFIG_DEBUG_FS
1296 /* add DPCM sysfs entries */
cd0f8911 1297 if (!dailess && !dai_link->dynamic)
f86dcef8
LG
1298 goto out;
1299
1300 ret = soc_dpcm_debugfs_add(rtd);
1301 if (ret < 0)
f110bfc7 1302 dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
f86dcef8
LG
1303
1304out:
1305#endif
589c3563
JN
1306 return 0;
1307}
1308
62ae68fa
SW
1309static int soc_probe_link_components(struct snd_soc_card *card, int num,
1310 int order)
1311{
1312 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1313 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1314 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1315 struct snd_soc_platform *platform = rtd->platform;
1316 int ret;
1317
1318 /* probe the CPU-side component, if it is a CODEC */
1319 if (cpu_dai->codec &&
1320 !cpu_dai->codec->probed &&
1321 cpu_dai->codec->driver->probe_order == order) {
1322 ret = soc_probe_codec(card, cpu_dai->codec);
1323 if (ret < 0)
1324 return ret;
1325 }
1326
1327 /* probe the CODEC-side component */
1328 if (!codec_dai->codec->probed &&
1329 codec_dai->codec->driver->probe_order == order) {
1330 ret = soc_probe_codec(card, codec_dai->codec);
1331 if (ret < 0)
1332 return ret;
1333 }
1334
1335 /* probe the platform */
1336 if (!platform->probed &&
1337 platform->driver->probe_order == order) {
1338 ret = soc_probe_platform(card, platform);
1339 if (ret < 0)
1340 return ret;
1341 }
1342
1343 return 0;
1344}
1345
1346static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
f0fba2ad
LG
1347{
1348 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1349 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1350 struct snd_soc_codec *codec = rtd->codec;
1351 struct snd_soc_platform *platform = rtd->platform;
c74184ed
MB
1352 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1353 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1354 struct snd_soc_dapm_widget *play_w, *capture_w;
f0fba2ad
LG
1355 int ret;
1356
f110bfc7 1357 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
0168bf0d 1358 card->name, num, order);
f0fba2ad
LG
1359
1360 /* config components */
f0fba2ad 1361 cpu_dai->platform = platform;
f0fba2ad
LG
1362 codec_dai->card = card;
1363 cpu_dai->card = card;
1364
1365 /* set default power off timeout */
1366 rtd->pmdown_time = pmdown_time;
1367
1368 /* probe the cpu_dai */
0168bf0d
LG
1369 if (!cpu_dai->probed &&
1370 cpu_dai->driver->probe_order == order) {
a9db7dbe
SW
1371 if (!cpu_dai->codec) {
1372 cpu_dai->dapm.card = card;
1373 if (!try_module_get(cpu_dai->dev->driver->owner))
1374 return -ENODEV;
61b61e3c 1375
18d75644 1376 list_add(&cpu_dai->dapm.list, &card->dapm_list);
a9db7dbe
SW
1377 snd_soc_dapm_new_dai_widgets(&cpu_dai->dapm, cpu_dai);
1378 }
be09ad90 1379
f0fba2ad
LG
1380 if (cpu_dai->driver->probe) {
1381 ret = cpu_dai->driver->probe(cpu_dai);
1382 if (ret < 0) {
f110bfc7
LG
1383 dev_err(cpu_dai->dev,
1384 "ASoC: failed to probe CPU DAI %s: %d\n",
1385 cpu_dai->name, ret);
61b61e3c 1386 module_put(cpu_dai->dev->driver->owner);
f0fba2ad
LG
1387 return ret;
1388 }
1389 }
1390 cpu_dai->probed = 1;
1c8371d6 1391 /* mark cpu_dai as probed and add to card dai list */
f0fba2ad 1392 list_add(&cpu_dai->card_list, &card->dai_dev_list);
db2a4165
FM
1393 }
1394
f0fba2ad 1395 /* probe the CODEC DAI */
0168bf0d 1396 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
f0fba2ad
LG
1397 if (codec_dai->driver->probe) {
1398 ret = codec_dai->driver->probe(codec_dai);
fe3e78e0 1399 if (ret < 0) {
f110bfc7
LG
1400 dev_err(codec_dai->dev,
1401 "ASoC: failed to probe CODEC DAI %s: %d\n",
1402 codec_dai->name, ret);
f0fba2ad 1403 return ret;
fe3e78e0
MB
1404 }
1405 }
f0fba2ad 1406
1c8371d6 1407 /* mark codec_dai as probed and add to card dai list */
f0fba2ad
LG
1408 codec_dai->probed = 1;
1409 list_add(&codec_dai->card_list, &card->dai_dev_list);
fe3e78e0
MB
1410 }
1411
0168bf0d
LG
1412 /* complete DAI probe during last probe */
1413 if (order != SND_SOC_COMP_ORDER_LAST)
1414 return 0;
1415
589c3563
JN
1416 ret = soc_post_component_init(card, codec, num, 0);
1417 if (ret)
f0fba2ad 1418 return ret;
fe3e78e0 1419
36ae1a96 1420 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
f0fba2ad 1421 if (ret < 0)
f110bfc7
LG
1422 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
1423 ret);
f0fba2ad 1424
1245b700
NK
1425 if (cpu_dai->driver->compress_dai) {
1426 /*create compress_device"*/
1427 ret = soc_new_compress(rtd, num);
c74184ed 1428 if (ret < 0) {
f110bfc7 1429 dev_err(card->dev, "ASoC: can't create compress %s\n",
1245b700 1430 dai_link->stream_name);
c74184ed
MB
1431 return ret;
1432 }
1433 } else {
1245b700
NK
1434
1435 if (!dai_link->params) {
1436 /* create the pcm */
1437 ret = soc_new_pcm(rtd, num);
1438 if (ret < 0) {
f110bfc7 1439 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
1245b700 1440 dai_link->stream_name, ret);
c74184ed
MB
1441 return ret;
1442 }
1245b700
NK
1443 } else {
1444 /* link the DAI widgets */
1445 play_w = codec_dai->playback_widget;
1446 capture_w = cpu_dai->capture_widget;
1447 if (play_w && capture_w) {
1448 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1449 capture_w, play_w);
1450 if (ret != 0) {
f110bfc7 1451 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1245b700
NK
1452 play_w->name, capture_w->name, ret);
1453 return ret;
1454 }
1455 }
c74184ed 1456
1245b700
NK
1457 play_w = cpu_dai->playback_widget;
1458 capture_w = codec_dai->capture_widget;
1459 if (play_w && capture_w) {
1460 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
c74184ed 1461 capture_w, play_w);
1245b700 1462 if (ret != 0) {
f110bfc7 1463 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1245b700
NK
1464 play_w->name, capture_w->name, ret);
1465 return ret;
1466 }
c74184ed
MB
1467 }
1468 }
f0fba2ad
LG
1469 }
1470
1471 /* add platform data for AC97 devices */
1472 if (rtd->codec_dai->driver->ac97_control)
1473 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1474
1475 return 0;
1476}
1477
fe3e78e0 1478#ifdef CONFIG_SND_SOC_AC97_BUS
f0fba2ad
LG
1479static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1480{
1481 int ret;
1482
fe3e78e0
MB
1483 /* Only instantiate AC97 if not already done by the adaptor
1484 * for the generic AC97 subsystem.
1485 */
f0fba2ad 1486 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
0562f788
MW
1487 /*
1488 * It is possible that the AC97 device is already registered to
1489 * the device subsystem. This happens when the device is created
1490 * via snd_ac97_mixer(). Currently only SoC codec that does so
1491 * is the generic AC97 glue but others migh emerge.
1492 *
1493 * In those cases we don't try to register the device again.
1494 */
1495 if (!rtd->codec->ac97_created)
1496 return 0;
f0fba2ad
LG
1497
1498 ret = soc_ac97_dev_register(rtd->codec);
fe3e78e0 1499 if (ret < 0) {
f110bfc7
LG
1500 dev_err(rtd->codec->dev,
1501 "ASoC: AC97 device register failed: %d\n", ret);
f0fba2ad 1502 return ret;
fe3e78e0 1503 }
f0fba2ad
LG
1504
1505 rtd->codec->ac97_registered = 1;
fe3e78e0 1506 }
f0fba2ad
LG
1507 return 0;
1508}
1509
1510static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1511{
1512 if (codec->ac97_registered) {
1513 soc_ac97_dev_unregister(codec);
1514 codec->ac97_registered = 0;
1515 }
1516}
fe3e78e0
MB
1517#endif
1518
b19e6e7b
MB
1519static int soc_check_aux_dev(struct snd_soc_card *card, int num)
1520{
1521 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1522 struct snd_soc_codec *codec;
1523
1524 /* find CODEC from registered CODECs*/
1525 list_for_each_entry(codec, &codec_list, list) {
1526 if (!strcmp(codec->name, aux_dev->codec_name))
1527 return 0;
1528 }
1529
f110bfc7 1530 dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name);
fb099cb7 1531
b19e6e7b
MB
1532 return -EPROBE_DEFER;
1533}
1534
2eea392d
JN
1535static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1536{
1537 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
2eea392d 1538 struct snd_soc_codec *codec;
676ad98a 1539 int ret = -ENODEV;
2eea392d
JN
1540
1541 /* find CODEC from registered CODECs*/
1542 list_for_each_entry(codec, &codec_list, list) {
1543 if (!strcmp(codec->name, aux_dev->codec_name)) {
1544 if (codec->probed) {
1545 dev_err(codec->dev,
f110bfc7 1546 "ASoC: codec already probed");
2eea392d
JN
1547 ret = -EBUSY;
1548 goto out;
1549 }
676ad98a 1550 goto found;
2eea392d
JN
1551 }
1552 }
676ad98a 1553 /* codec not found */
f110bfc7 1554 dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name);
b19e6e7b 1555 return -EPROBE_DEFER;
2eea392d 1556
676ad98a 1557found:
589c3563 1558 ret = soc_probe_codec(card, codec);
2eea392d 1559 if (ret < 0)
589c3563 1560 return ret;
2eea392d 1561
589c3563 1562 ret = soc_post_component_init(card, codec, num, 1);
2eea392d
JN
1563
1564out:
1565 return ret;
1566}
1567
1568static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1569{
1570 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1571 struct snd_soc_codec *codec = rtd->codec;
2eea392d
JN
1572
1573 /* unregister the rtd device */
1574 if (rtd->dev_registered) {
36ae1a96 1575 device_remove_file(rtd->dev, &dev_attr_codec_reg);
d3bf1561 1576 device_unregister(rtd->dev);
2eea392d
JN
1577 rtd->dev_registered = 0;
1578 }
1579
589c3563
JN
1580 if (codec && codec->probed)
1581 soc_remove_codec(codec);
2eea392d
JN
1582}
1583
fdf0f54d
DP
1584static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1585 enum snd_soc_compress_type compress_type)
1586{
1587 int ret;
1588
1589 if (codec->cache_init)
1590 return 0;
1591
1592 /* override the compress_type if necessary */
1593 if (compress_type && codec->compress_type != compress_type)
1594 codec->compress_type = compress_type;
fdf0f54d
DP
1595 ret = snd_soc_cache_init(codec);
1596 if (ret < 0) {
10e8aa9a
MM
1597 dev_err(codec->dev,
1598 "ASoC: Failed to set cache compression type: %d\n",
1599 ret);
fdf0f54d
DP
1600 return ret;
1601 }
1602 codec->cache_init = 1;
1603 return 0;
1604}
1605
b19e6e7b 1606static int snd_soc_instantiate_card(struct snd_soc_card *card)
f0fba2ad 1607{
fdf0f54d
DP
1608 struct snd_soc_codec *codec;
1609 struct snd_soc_codec_conf *codec_conf;
1610 enum snd_soc_compress_type compress_type;
75d9ac46 1611 struct snd_soc_dai_link *dai_link;
f04209a7 1612 int ret, i, order, dai_fmt;
fe3e78e0 1613
01b9d99a 1614 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
dbe21408 1615
f0fba2ad 1616 /* bind DAIs */
b19e6e7b
MB
1617 for (i = 0; i < card->num_links; i++) {
1618 ret = soc_bind_dai_link(card, i);
1619 if (ret != 0)
1620 goto base_error;
1621 }
fe3e78e0 1622
b19e6e7b
MB
1623 /* check aux_devs too */
1624 for (i = 0; i < card->num_aux_devs; i++) {
1625 ret = soc_check_aux_dev(card, i);
1626 if (ret != 0)
1627 goto base_error;
f0fba2ad 1628 }
435c5e25 1629
fdf0f54d
DP
1630 /* initialize the register cache for each available codec */
1631 list_for_each_entry(codec, &codec_list, list) {
1632 if (codec->cache_init)
1633 continue;
861f2faf
DP
1634 /* by default we don't override the compress_type */
1635 compress_type = 0;
fdf0f54d
DP
1636 /* check to see if we need to override the compress_type */
1637 for (i = 0; i < card->num_configs; ++i) {
1638 codec_conf = &card->codec_conf[i];
1639 if (!strcmp(codec->name, codec_conf->dev_name)) {
1640 compress_type = codec_conf->compress_type;
1641 if (compress_type && compress_type
1642 != codec->compress_type)
1643 break;
1644 }
1645 }
fdf0f54d 1646 ret = snd_soc_init_codec_cache(codec, compress_type);
b19e6e7b
MB
1647 if (ret < 0)
1648 goto base_error;
fdf0f54d
DP
1649 }
1650
f0fba2ad
LG
1651 /* card bind complete so register a sound card */
1652 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1653 card->owner, 0, &card->snd_card);
1654 if (ret < 0) {
10e8aa9a
MM
1655 dev_err(card->dev,
1656 "ASoC: can't create sound card for card %s: %d\n",
1657 card->name, ret);
b19e6e7b 1658 goto base_error;
f0fba2ad
LG
1659 }
1660 card->snd_card->dev = card->dev;
1661
e37a4970
MB
1662 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1663 card->dapm.dev = card->dev;
1664 card->dapm.card = card;
1665 list_add(&card->dapm.list, &card->dapm_list);
1666
d5d1e0be
LPC
1667#ifdef CONFIG_DEBUG_FS
1668 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1669#endif
1670
88ee1c61 1671#ifdef CONFIG_PM_SLEEP
f0fba2ad
LG
1672 /* deferred resume work */
1673 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1674#endif
db2a4165 1675
9a841ebb
MB
1676 if (card->dapm_widgets)
1677 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1678 card->num_dapm_widgets);
1679
f0fba2ad
LG
1680 /* initialise the sound card only once */
1681 if (card->probe) {
e7361ec4 1682 ret = card->probe(card);
f0fba2ad
LG
1683 if (ret < 0)
1684 goto card_probe_error;
1685 }
fe3e78e0 1686
62ae68fa 1687 /* probe all components used by DAI links on this card */
0168bf0d
LG
1688 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1689 order++) {
1690 for (i = 0; i < card->num_links; i++) {
62ae68fa 1691 ret = soc_probe_link_components(card, i, order);
0168bf0d 1692 if (ret < 0) {
f110bfc7
LG
1693 dev_err(card->dev,
1694 "ASoC: failed to instantiate card %d\n",
1695 ret);
62ae68fa
SW
1696 goto probe_dai_err;
1697 }
1698 }
1699 }
1700
1701 /* probe all DAI links on this card */
1702 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1703 order++) {
1704 for (i = 0; i < card->num_links; i++) {
1705 ret = soc_probe_link_dais(card, i, order);
1706 if (ret < 0) {
f110bfc7
LG
1707 dev_err(card->dev,
1708 "ASoC: failed to instantiate card %d\n",
1709 ret);
0168bf0d
LG
1710 goto probe_dai_err;
1711 }
f0fba2ad
LG
1712 }
1713 }
db2a4165 1714
2eea392d
JN
1715 for (i = 0; i < card->num_aux_devs; i++) {
1716 ret = soc_probe_aux_dev(card, i);
1717 if (ret < 0) {
f110bfc7
LG
1718 dev_err(card->dev,
1719 "ASoC: failed to add auxiliary devices %d\n",
1720 ret);
2eea392d
JN
1721 goto probe_aux_dev_err;
1722 }
1723 }
1724
888df395
MB
1725 snd_soc_dapm_link_dai_widgets(card);
1726
b7af1daf 1727 if (card->controls)
022658be 1728 snd_soc_add_card_controls(card, card->controls, card->num_controls);
b7af1daf 1729
b8ad29de
MB
1730 if (card->dapm_routes)
1731 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1732 card->num_dapm_routes);
1733
b90d2f90
MB
1734 snd_soc_dapm_new_widgets(&card->dapm);
1735
75d9ac46
MB
1736 for (i = 0; i < card->num_links; i++) {
1737 dai_link = &card->dai_link[i];
f04209a7 1738 dai_fmt = dai_link->dai_fmt;
75d9ac46 1739
f04209a7 1740 if (dai_fmt) {
75d9ac46 1741 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
f04209a7 1742 dai_fmt);
5e4ba569 1743 if (ret != 0 && ret != -ENOTSUPP)
75d9ac46 1744 dev_warn(card->rtd[i].codec_dai->dev,
f110bfc7 1745 "ASoC: Failed to set DAI format: %d\n",
75d9ac46 1746 ret);
f04209a7
MB
1747 }
1748
1749 /* If this is a regular CPU link there will be a platform */
fe33d4c5
SW
1750 if (dai_fmt &&
1751 (dai_link->platform_name || dai_link->platform_of_node)) {
f04209a7
MB
1752 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1753 dai_fmt);
1754 if (ret != 0 && ret != -ENOTSUPP)
1755 dev_warn(card->rtd[i].cpu_dai->dev,
f110bfc7 1756 "ASoC: Failed to set DAI format: %d\n",
f04209a7
MB
1757 ret);
1758 } else if (dai_fmt) {
1759 /* Flip the polarity for the "CPU" end */
1760 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1761 switch (dai_link->dai_fmt &
1762 SND_SOC_DAIFMT_MASTER_MASK) {
1763 case SND_SOC_DAIFMT_CBM_CFM:
1764 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1765 break;
1766 case SND_SOC_DAIFMT_CBM_CFS:
1767 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1768 break;
1769 case SND_SOC_DAIFMT_CBS_CFM:
1770 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1771 break;
1772 case SND_SOC_DAIFMT_CBS_CFS:
1773 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1774 break;
1775 }
75d9ac46
MB
1776
1777 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
f04209a7 1778 dai_fmt);
5e4ba569 1779 if (ret != 0 && ret != -ENOTSUPP)
75d9ac46 1780 dev_warn(card->rtd[i].cpu_dai->dev,
f110bfc7 1781 "ASoC: Failed to set DAI format: %d\n",
75d9ac46
MB
1782 ret);
1783 }
1784 }
1785
f0fba2ad 1786 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
f0fba2ad 1787 "%s", card->name);
22de71ba
LG
1788 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1789 "%s", card->long_name ? card->long_name : card->name);
f0e8ed85
MB
1790 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1791 "%s", card->driver_name ? card->driver_name : card->name);
1792 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1793 switch (card->snd_card->driver[i]) {
1794 case '_':
1795 case '-':
1796 case '\0':
1797 break;
1798 default:
1799 if (!isalnum(card->snd_card->driver[i]))
1800 card->snd_card->driver[i] = '_';
1801 break;
1802 }
1803 }
f0fba2ad 1804
28e9ad92
MB
1805 if (card->late_probe) {
1806 ret = card->late_probe(card);
1807 if (ret < 0) {
f110bfc7 1808 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
28e9ad92
MB
1809 card->name, ret);
1810 goto probe_aux_dev_err;
1811 }
1812 }
1813
2dc00213
MB
1814 snd_soc_dapm_new_widgets(&card->dapm);
1815
1633281b 1816 if (card->fully_routed)
b05d8dc1 1817 list_for_each_entry(codec, &card->codec_dev_list, card_list)
1633281b
SW
1818 snd_soc_dapm_auto_nc_codec_pins(codec);
1819
f0fba2ad
LG
1820 ret = snd_card_register(card->snd_card);
1821 if (ret < 0) {
f110bfc7
LG
1822 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
1823 ret);
6b3ed785 1824 goto probe_aux_dev_err;
db2a4165
FM
1825 }
1826
f0fba2ad
LG
1827#ifdef CONFIG_SND_SOC_AC97_BUS
1828 /* register any AC97 codecs */
1829 for (i = 0; i < card->num_rtd; i++) {
6b3ed785
AL
1830 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1831 if (ret < 0) {
10e8aa9a
MM
1832 dev_err(card->dev,
1833 "ASoC: failed to register AC97: %d\n", ret);
6b3ed785 1834 while (--i >= 0)
7d8316df 1835 soc_unregister_ac97_dai_link(card->rtd[i].codec);
6b3ed785 1836 goto probe_aux_dev_err;
f0fba2ad 1837 }
6b3ed785 1838 }
f0fba2ad
LG
1839#endif
1840
1841 card->instantiated = 1;
4f4c0072 1842 snd_soc_dapm_sync(&card->dapm);
f0fba2ad 1843 mutex_unlock(&card->mutex);
b19e6e7b
MB
1844
1845 return 0;
f0fba2ad 1846
2eea392d
JN
1847probe_aux_dev_err:
1848 for (i = 0; i < card->num_aux_devs; i++)
1849 soc_remove_aux_dev(card, i);
1850
f0fba2ad 1851probe_dai_err:
0671fd8e 1852 soc_remove_dai_links(card);
f0fba2ad
LG
1853
1854card_probe_error:
87506549 1855 if (card->remove)
e7361ec4 1856 card->remove(card);
f0fba2ad
LG
1857
1858 snd_card_free(card->snd_card);
1859
b19e6e7b 1860base_error:
f0fba2ad 1861 mutex_unlock(&card->mutex);
db2a4165 1862
b19e6e7b 1863 return ret;
435c5e25
MB
1864}
1865
1866/* probes a new socdev */
1867static int soc_probe(struct platform_device *pdev)
1868{
f0fba2ad 1869 struct snd_soc_card *card = platform_get_drvdata(pdev);
435c5e25 1870
70a7ca34
VK
1871 /*
1872 * no card, so machine driver should be registering card
1873 * we should not be here in that case so ret error
1874 */
1875 if (!card)
1876 return -EINVAL;
1877
fe4085e8 1878 dev_warn(&pdev->dev,
f110bfc7 1879 "ASoC: machine %s should use snd_soc_register_card()\n",
fe4085e8
MB
1880 card->name);
1881
435c5e25
MB
1882 /* Bodge while we unpick instantiation */
1883 card->dev = &pdev->dev;
f0fba2ad 1884
28d528c8 1885 return snd_soc_register_card(card);
db2a4165
FM
1886}
1887
b0e26485 1888static int soc_cleanup_card_resources(struct snd_soc_card *card)
db2a4165
FM
1889{
1890 int i;
db2a4165 1891
b0e26485
VK
1892 /* make sure any delayed work runs */
1893 for (i = 0; i < card->num_rtd; i++) {
1894 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
43829731 1895 flush_delayed_work(&rtd->delayed_work);
b0e26485 1896 }
914dc182 1897
b0e26485
VK
1898 /* remove auxiliary devices */
1899 for (i = 0; i < card->num_aux_devs; i++)
1900 soc_remove_aux_dev(card, i);
db2a4165 1901
b0e26485 1902 /* remove and free each DAI */
0671fd8e 1903 soc_remove_dai_links(card);
2eea392d 1904
b0e26485 1905 soc_cleanup_card_debugfs(card);
f0fba2ad 1906
b0e26485
VK
1907 /* remove the card */
1908 if (card->remove)
e7361ec4 1909 card->remove(card);
a6052154 1910
0aaae527
LPC
1911 snd_soc_dapm_free(&card->dapm);
1912
b0e26485
VK
1913 snd_card_free(card->snd_card);
1914 return 0;
1915
1916}
1917
1918/* removes a socdev */
1919static int soc_remove(struct platform_device *pdev)
1920{
1921 struct snd_soc_card *card = platform_get_drvdata(pdev);
db2a4165 1922
c5af3a2e 1923 snd_soc_unregister_card(card);
db2a4165
FM
1924 return 0;
1925}
1926
6f8ab4ac 1927int snd_soc_poweroff(struct device *dev)
51737470 1928{
6f8ab4ac 1929 struct snd_soc_card *card = dev_get_drvdata(dev);
f0fba2ad 1930 int i;
51737470
MB
1931
1932 if (!card->instantiated)
416356fc 1933 return 0;
51737470
MB
1934
1935 /* Flush out pmdown_time work - we actually do want to run it
1936 * now, we're shutting down so no imminent restart. */
f0fba2ad
LG
1937 for (i = 0; i < card->num_rtd; i++) {
1938 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
43829731 1939 flush_delayed_work(&rtd->delayed_work);
f0fba2ad 1940 }
51737470 1941
f0fba2ad 1942 snd_soc_dapm_shutdown(card);
416356fc
MB
1943
1944 return 0;
51737470 1945}
6f8ab4ac 1946EXPORT_SYMBOL_GPL(snd_soc_poweroff);
51737470 1947
6f8ab4ac 1948const struct dev_pm_ops snd_soc_pm_ops = {
b1dd5897
VK
1949 .suspend = snd_soc_suspend,
1950 .resume = snd_soc_resume,
1951 .freeze = snd_soc_suspend,
1952 .thaw = snd_soc_resume,
6f8ab4ac 1953 .poweroff = snd_soc_poweroff,
b1dd5897 1954 .restore = snd_soc_resume,
416356fc 1955};
deb2607e 1956EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
416356fc 1957
db2a4165
FM
1958/* ASoC platform driver */
1959static struct platform_driver soc_driver = {
1960 .driver = {
1961 .name = "soc-audio",
8b45a209 1962 .owner = THIS_MODULE,
6f8ab4ac 1963 .pm = &snd_soc_pm_ops,
db2a4165
FM
1964 },
1965 .probe = soc_probe,
1966 .remove = soc_remove,
db2a4165
FM
1967};
1968
096e49d5
MB
1969/**
1970 * snd_soc_codec_volatile_register: Report if a register is volatile.
1971 *
1972 * @codec: CODEC to query.
1973 * @reg: Register to query.
1974 *
1975 * Boolean function indiciating if a CODEC register is volatile.
1976 */
181e055e
MB
1977int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1978 unsigned int reg)
096e49d5 1979{
1500b7b5
DP
1980 if (codec->volatile_register)
1981 return codec->volatile_register(codec, reg);
096e49d5
MB
1982 else
1983 return 0;
1984}
1985EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1986
239c9706
DP
1987/**
1988 * snd_soc_codec_readable_register: Report if a register is readable.
1989 *
1990 * @codec: CODEC to query.
1991 * @reg: Register to query.
1992 *
1993 * Boolean function indicating if a CODEC register is readable.
1994 */
1995int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1996 unsigned int reg)
1997{
1998 if (codec->readable_register)
1999 return codec->readable_register(codec, reg);
2000 else
63fa0a28 2001 return 1;
239c9706
DP
2002}
2003EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
2004
2005/**
2006 * snd_soc_codec_writable_register: Report if a register is writable.
2007 *
2008 * @codec: CODEC to query.
2009 * @reg: Register to query.
2010 *
2011 * Boolean function indicating if a CODEC register is writable.
2012 */
2013int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
2014 unsigned int reg)
2015{
2016 if (codec->writable_register)
2017 return codec->writable_register(codec, reg);
2018 else
63fa0a28 2019 return 1;
239c9706
DP
2020}
2021EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
2022
f1442bc1
LG
2023int snd_soc_platform_read(struct snd_soc_platform *platform,
2024 unsigned int reg)
2025{
2026 unsigned int ret;
2027
2028 if (!platform->driver->read) {
f110bfc7 2029 dev_err(platform->dev, "ASoC: platform has no read back\n");
f1442bc1
LG
2030 return -1;
2031 }
2032
2033 ret = platform->driver->read(platform, reg);
2034 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
a82ce2ae 2035 trace_snd_soc_preg_read(platform, reg, ret);
f1442bc1
LG
2036
2037 return ret;
2038}
2039EXPORT_SYMBOL_GPL(snd_soc_platform_read);
2040
2041int snd_soc_platform_write(struct snd_soc_platform *platform,
2042 unsigned int reg, unsigned int val)
2043{
2044 if (!platform->driver->write) {
f110bfc7 2045 dev_err(platform->dev, "ASoC: platform has no write back\n");
f1442bc1
LG
2046 return -1;
2047 }
2048
2049 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
a82ce2ae 2050 trace_snd_soc_preg_write(platform, reg, val);
f1442bc1
LG
2051 return platform->driver->write(platform, reg, val);
2052}
2053EXPORT_SYMBOL_GPL(snd_soc_platform_write);
2054
db2a4165
FM
2055/**
2056 * snd_soc_new_ac97_codec - initailise AC97 device
2057 * @codec: audio codec
2058 * @ops: AC97 bus operations
2059 * @num: AC97 codec number
2060 *
2061 * Initialises AC97 codec resources for use by ad-hoc devices only.
2062 */
2063int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
2064 struct snd_ac97_bus_ops *ops, int num)
2065{
2066 mutex_lock(&codec->mutex);
2067
2068 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
2069 if (codec->ac97 == NULL) {
2070 mutex_unlock(&codec->mutex);
2071 return -ENOMEM;
2072 }
2073
2074 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
2075 if (codec->ac97->bus == NULL) {
2076 kfree(codec->ac97);
2077 codec->ac97 = NULL;
2078 mutex_unlock(&codec->mutex);
2079 return -ENOMEM;
2080 }
2081
2082 codec->ac97->bus->ops = ops;
2083 codec->ac97->num = num;
0562f788
MW
2084
2085 /*
2086 * Mark the AC97 device to be created by us. This way we ensure that the
2087 * device will be registered with the device subsystem later on.
2088 */
2089 codec->ac97_created = 1;
2090
db2a4165
FM
2091 mutex_unlock(&codec->mutex);
2092 return 0;
2093}
2094EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
2095
741a509f
MP
2096static struct snd_ac97_reset_cfg snd_ac97_rst_cfg;
2097
2098static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97)
2099{
2100 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
2101
2102 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset);
2103
2104 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1);
2105
2106 udelay(10);
2107
2108 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
2109
2110 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2111 msleep(2);
2112}
2113
2114static void snd_soc_ac97_reset(struct snd_ac97 *ac97)
2115{
2116 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
2117
2118 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset);
2119
2120 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
2121 gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0);
2122 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0);
2123
2124 udelay(10);
2125
2126 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1);
2127
2128 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2129 msleep(2);
2130}
2131
2132static int snd_soc_ac97_parse_pinctl(struct device *dev,
2133 struct snd_ac97_reset_cfg *cfg)
2134{
2135 struct pinctrl *p;
2136 struct pinctrl_state *state;
2137 int gpio;
2138 int ret;
2139
2140 p = devm_pinctrl_get(dev);
2141 if (IS_ERR(p)) {
2142 dev_err(dev, "Failed to get pinctrl\n");
2143 return PTR_RET(p);
2144 }
2145 cfg->pctl = p;
2146
2147 state = pinctrl_lookup_state(p, "ac97-reset");
2148 if (IS_ERR(state)) {
2149 dev_err(dev, "Can't find pinctrl state ac97-reset\n");
2150 return PTR_RET(state);
2151 }
2152 cfg->pstate_reset = state;
2153
2154 state = pinctrl_lookup_state(p, "ac97-warm-reset");
2155 if (IS_ERR(state)) {
2156 dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n");
2157 return PTR_RET(state);
2158 }
2159 cfg->pstate_warm_reset = state;
2160
2161 state = pinctrl_lookup_state(p, "ac97-running");
2162 if (IS_ERR(state)) {
2163 dev_err(dev, "Can't find pinctrl state ac97-running\n");
2164 return PTR_RET(state);
2165 }
2166 cfg->pstate_run = state;
2167
2168 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0);
2169 if (gpio < 0) {
2170 dev_err(dev, "Can't find ac97-sync gpio\n");
2171 return gpio;
2172 }
2173 ret = devm_gpio_request(dev, gpio, "AC97 link sync");
2174 if (ret) {
2175 dev_err(dev, "Failed requesting ac97-sync gpio\n");
2176 return ret;
2177 }
2178 cfg->gpio_sync = gpio;
2179
2180 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1);
2181 if (gpio < 0) {
2182 dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio);
2183 return gpio;
2184 }
2185 ret = devm_gpio_request(dev, gpio, "AC97 link sdata");
2186 if (ret) {
2187 dev_err(dev, "Failed requesting ac97-sdata gpio\n");
2188 return ret;
2189 }
2190 cfg->gpio_sdata = gpio;
2191
2192 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2);
2193 if (gpio < 0) {
2194 dev_err(dev, "Can't find ac97-reset gpio\n");
2195 return gpio;
2196 }
2197 ret = devm_gpio_request(dev, gpio, "AC97 link reset");
2198 if (ret) {
2199 dev_err(dev, "Failed requesting ac97-reset gpio\n");
2200 return ret;
2201 }
2202 cfg->gpio_reset = gpio;
2203
2204 return 0;
2205}
2206
b047e1cc 2207struct snd_ac97_bus_ops *soc_ac97_ops;
f74b5e25 2208EXPORT_SYMBOL_GPL(soc_ac97_ops);
b047e1cc
MB
2209
2210int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
2211{
2212 if (ops == soc_ac97_ops)
2213 return 0;
2214
2215 if (soc_ac97_ops && ops)
2216 return -EBUSY;
2217
2218 soc_ac97_ops = ops;
2219
2220 return 0;
2221}
2222EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops);
2223
741a509f
MP
2224/**
2225 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
2226 *
2227 * This function sets the reset and warm_reset properties of ops and parses
2228 * the device node of pdev to get pinctrl states and gpio numbers to use.
2229 */
2230int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
2231 struct platform_device *pdev)
2232{
2233 struct device *dev = &pdev->dev;
2234 struct snd_ac97_reset_cfg cfg;
2235 int ret;
2236
2237 ret = snd_soc_ac97_parse_pinctl(dev, &cfg);
2238 if (ret)
2239 return ret;
2240
2241 ret = snd_soc_set_ac97_ops(ops);
2242 if (ret)
2243 return ret;
2244
2245 ops->warm_reset = snd_soc_ac97_warm_reset;
2246 ops->reset = snd_soc_ac97_reset;
2247
2248 snd_ac97_rst_cfg = cfg;
2249 return 0;
2250}
2251EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
2252
db2a4165
FM
2253/**
2254 * snd_soc_free_ac97_codec - free AC97 codec device
2255 * @codec: audio codec
2256 *
2257 * Frees AC97 codec device resources.
2258 */
2259void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
2260{
2261 mutex_lock(&codec->mutex);
f0fba2ad
LG
2262#ifdef CONFIG_SND_SOC_AC97_BUS
2263 soc_unregister_ac97_dai_link(codec);
2264#endif
db2a4165
FM
2265 kfree(codec->ac97->bus);
2266 kfree(codec->ac97);
2267 codec->ac97 = NULL;
0562f788 2268 codec->ac97_created = 0;
db2a4165
FM
2269 mutex_unlock(&codec->mutex);
2270}
2271EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
2272
c3753707
MB
2273unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
2274{
2275 unsigned int ret;
2276
c3acec26 2277 ret = codec->read(codec, reg);
c3753707 2278 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
a8b1d34f 2279 trace_snd_soc_reg_read(codec, reg, ret);
c3753707
MB
2280
2281 return ret;
2282}
2283EXPORT_SYMBOL_GPL(snd_soc_read);
2284
2285unsigned int snd_soc_write(struct snd_soc_codec *codec,
2286 unsigned int reg, unsigned int val)
2287{
2288 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
a8b1d34f 2289 trace_snd_soc_reg_write(codec, reg, val);
c3acec26 2290 return codec->write(codec, reg, val);
c3753707
MB
2291}
2292EXPORT_SYMBOL_GPL(snd_soc_write);
2293
5fb609d4
DP
2294unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
2295 unsigned int reg, const void *data, size_t len)
2296{
2297 return codec->bulk_write_raw(codec, reg, data, len);
2298}
2299EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
2300
db2a4165
FM
2301/**
2302 * snd_soc_update_bits - update codec register bits
2303 * @codec: audio codec
2304 * @reg: codec register
2305 * @mask: register mask
2306 * @value: new value
2307 *
2308 * Writes new register value.
2309 *
180c329d 2310 * Returns 1 for change, 0 for no change, or negative error code.
db2a4165
FM
2311 */
2312int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
46f5822f 2313 unsigned int mask, unsigned int value)
db2a4165 2314{
8a713da8 2315 bool change;
46f5822f 2316 unsigned int old, new;
180c329d
TT
2317 int ret;
2318
8a713da8
MB
2319 if (codec->using_regmap) {
2320 ret = regmap_update_bits_check(codec->control_data, reg,
2321 mask, value, &change);
2322 } else {
2323 ret = snd_soc_read(codec, reg);
180c329d
TT
2324 if (ret < 0)
2325 return ret;
8a713da8
MB
2326
2327 old = ret;
2328 new = (old & ~mask) | (value & mask);
2329 change = old != new;
2330 if (change)
2331 ret = snd_soc_write(codec, reg, new);
180c329d 2332 }
db2a4165 2333
8a713da8
MB
2334 if (ret < 0)
2335 return ret;
2336
db2a4165
FM
2337 return change;
2338}
2339EXPORT_SYMBOL_GPL(snd_soc_update_bits);
2340
6c508c62
EN
2341/**
2342 * snd_soc_update_bits_locked - update codec register bits
2343 * @codec: audio codec
2344 * @reg: codec register
2345 * @mask: register mask
2346 * @value: new value
2347 *
2348 * Writes new register value, and takes the codec mutex.
2349 *
2350 * Returns 1 for change else 0.
2351 */
dd1b3d53
MB
2352int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
2353 unsigned short reg, unsigned int mask,
2354 unsigned int value)
6c508c62
EN
2355{
2356 int change;
2357
2358 mutex_lock(&codec->mutex);
2359 change = snd_soc_update_bits(codec, reg, mask, value);
2360 mutex_unlock(&codec->mutex);
2361
2362 return change;
2363}
dd1b3d53 2364EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
6c508c62 2365
db2a4165
FM
2366/**
2367 * snd_soc_test_bits - test register for change
2368 * @codec: audio codec
2369 * @reg: codec register
2370 * @mask: register mask
2371 * @value: new value
2372 *
2373 * Tests a register with a new value and checks if the new value is
2374 * different from the old value.
2375 *
2376 * Returns 1 for change else 0.
2377 */
2378int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
46f5822f 2379 unsigned int mask, unsigned int value)
db2a4165
FM
2380{
2381 int change;
46f5822f 2382 unsigned int old, new;
db2a4165 2383
db2a4165
FM
2384 old = snd_soc_read(codec, reg);
2385 new = (old & ~mask) | value;
2386 change = old != new;
db2a4165
FM
2387
2388 return change;
2389}
2390EXPORT_SYMBOL_GPL(snd_soc_test_bits);
2391
db2a4165
FM
2392/**
2393 * snd_soc_cnew - create new control
2394 * @_template: control template
2395 * @data: control private data
ac11a2b3 2396 * @long_name: control long name
efb7ac3f 2397 * @prefix: control name prefix
db2a4165
FM
2398 *
2399 * Create a new mixer control from a template control.
2400 *
2401 * Returns 0 for success, else error.
2402 */
2403struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
3056557f 2404 void *data, const char *long_name,
efb7ac3f 2405 const char *prefix)
db2a4165
FM
2406{
2407 struct snd_kcontrol_new template;
efb7ac3f
MB
2408 struct snd_kcontrol *kcontrol;
2409 char *name = NULL;
db2a4165
FM
2410
2411 memcpy(&template, _template, sizeof(template));
db2a4165
FM
2412 template.index = 0;
2413
efb7ac3f
MB
2414 if (!long_name)
2415 long_name = template.name;
2416
2417 if (prefix) {
2b581074 2418 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
efb7ac3f
MB
2419 if (!name)
2420 return NULL;
2421
efb7ac3f
MB
2422 template.name = name;
2423 } else {
2424 template.name = long_name;
2425 }
2426
2427 kcontrol = snd_ctl_new1(&template, data);
2428
2429 kfree(name);
2430
2431 return kcontrol;
db2a4165
FM
2432}
2433EXPORT_SYMBOL_GPL(snd_soc_cnew);
2434
022658be
LG
2435static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2436 const struct snd_kcontrol_new *controls, int num_controls,
2437 const char *prefix, void *data)
2438{
2439 int err, i;
2440
2441 for (i = 0; i < num_controls; i++) {
2442 const struct snd_kcontrol_new *control = &controls[i];
2443 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2444 control->name, prefix));
2445 if (err < 0) {
f110bfc7
LG
2446 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2447 control->name, err);
022658be
LG
2448 return err;
2449 }
2450 }
2451
2452 return 0;
2453}
2454
4fefd698
DP
2455struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2456 const char *name)
2457{
2458 struct snd_card *card = soc_card->snd_card;
2459 struct snd_kcontrol *kctl;
2460
2461 if (unlikely(!name))
2462 return NULL;
2463
2464 list_for_each_entry(kctl, &card->controls, list)
2465 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2466 return kctl;
2467 return NULL;
2468}
2469EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2470
3e8e1952 2471/**
022658be
LG
2472 * snd_soc_add_codec_controls - add an array of controls to a codec.
2473 * Convenience function to add a list of controls. Many codecs were
3e8e1952
IM
2474 * duplicating this code.
2475 *
2476 * @codec: codec to add controls to
2477 * @controls: array of controls to add
2478 * @num_controls: number of elements in the array
2479 *
2480 * Return 0 for success, else error.
2481 */
022658be 2482int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
3e8e1952
IM
2483 const struct snd_kcontrol_new *controls, int num_controls)
2484{
f0fba2ad 2485 struct snd_card *card = codec->card->snd_card;
3e8e1952 2486
022658be
LG
2487 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2488 codec->name_prefix, codec);
3e8e1952 2489}
022658be 2490EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
3e8e1952 2491
a491a5c8
LG
2492/**
2493 * snd_soc_add_platform_controls - add an array of controls to a platform.
022658be 2494 * Convenience function to add a list of controls.
a491a5c8
LG
2495 *
2496 * @platform: platform to add controls to
2497 * @controls: array of controls to add
2498 * @num_controls: number of elements in the array
2499 *
2500 * Return 0 for success, else error.
2501 */
2502int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2503 const struct snd_kcontrol_new *controls, int num_controls)
2504{
2505 struct snd_card *card = platform->card->snd_card;
a491a5c8 2506
022658be
LG
2507 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2508 NULL, platform);
a491a5c8
LG
2509}
2510EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2511
022658be
LG
2512/**
2513 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2514 * Convenience function to add a list of controls.
2515 *
2516 * @soc_card: SoC card to add controls to
2517 * @controls: array of controls to add
2518 * @num_controls: number of elements in the array
2519 *
2520 * Return 0 for success, else error.
2521 */
2522int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2523 const struct snd_kcontrol_new *controls, int num_controls)
2524{
2525 struct snd_card *card = soc_card->snd_card;
2526
2527 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2528 NULL, soc_card);
2529}
2530EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2531
2532/**
2533 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2534 * Convienience function to add a list of controls.
2535 *
2536 * @dai: DAI to add controls to
2537 * @controls: array of controls to add
2538 * @num_controls: number of elements in the array
2539 *
2540 * Return 0 for success, else error.
2541 */
2542int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2543 const struct snd_kcontrol_new *controls, int num_controls)
2544{
2545 struct snd_card *card = dai->card->snd_card;
2546
2547 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2548 NULL, dai);
2549}
2550EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2551
db2a4165
FM
2552/**
2553 * snd_soc_info_enum_double - enumerated double mixer info callback
2554 * @kcontrol: mixer control
2555 * @uinfo: control element information
2556 *
2557 * Callback to provide information about a double enumerated
2558 * mixer control.
2559 *
2560 * Returns 0 for success.
2561 */
2562int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2563 struct snd_ctl_elem_info *uinfo)
2564{
2565 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2566
2567 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2568 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
f8ba0b7b 2569 uinfo->value.enumerated.items = e->max;
db2a4165 2570
f8ba0b7b
JS
2571 if (uinfo->value.enumerated.item > e->max - 1)
2572 uinfo->value.enumerated.item = e->max - 1;
db2a4165
FM
2573 strcpy(uinfo->value.enumerated.name,
2574 e->texts[uinfo->value.enumerated.item]);
2575 return 0;
2576}
2577EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2578
2579/**
2580 * snd_soc_get_enum_double - enumerated double mixer get callback
2581 * @kcontrol: mixer control
ac11a2b3 2582 * @ucontrol: control element information
db2a4165
FM
2583 *
2584 * Callback to get the value of a double enumerated mixer.
2585 *
2586 * Returns 0 for success.
2587 */
2588int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2589 struct snd_ctl_elem_value *ucontrol)
2590{
2591 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2592 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
86767b7d 2593 unsigned int val;
db2a4165 2594
db2a4165 2595 val = snd_soc_read(codec, e->reg);
3ff3f64b 2596 ucontrol->value.enumerated.item[0]
86767b7d 2597 = (val >> e->shift_l) & e->mask;
db2a4165
FM
2598 if (e->shift_l != e->shift_r)
2599 ucontrol->value.enumerated.item[1] =
86767b7d 2600 (val >> e->shift_r) & e->mask;
db2a4165
FM
2601
2602 return 0;
2603}
2604EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2605
2606/**
2607 * snd_soc_put_enum_double - enumerated double mixer put callback
2608 * @kcontrol: mixer control
ac11a2b3 2609 * @ucontrol: control element information
db2a4165
FM
2610 *
2611 * Callback to set the value of a double enumerated mixer.
2612 *
2613 * Returns 0 for success.
2614 */
2615int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2616 struct snd_ctl_elem_value *ucontrol)
2617{
2618 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2619 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f 2620 unsigned int val;
86767b7d 2621 unsigned int mask;
db2a4165 2622
f8ba0b7b 2623 if (ucontrol->value.enumerated.item[0] > e->max - 1)
db2a4165
FM
2624 return -EINVAL;
2625 val = ucontrol->value.enumerated.item[0] << e->shift_l;
86767b7d 2626 mask = e->mask << e->shift_l;
db2a4165 2627 if (e->shift_l != e->shift_r) {
f8ba0b7b 2628 if (ucontrol->value.enumerated.item[1] > e->max - 1)
db2a4165
FM
2629 return -EINVAL;
2630 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
86767b7d 2631 mask |= e->mask << e->shift_r;
db2a4165
FM
2632 }
2633
6c508c62 2634 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
db2a4165
FM
2635}
2636EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2637
2e72f8e3
PU
2638/**
2639 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2640 * @kcontrol: mixer control
2641 * @ucontrol: control element information
2642 *
2643 * Callback to get the value of a double semi enumerated mixer.
2644 *
2645 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2646 * used for handling bitfield coded enumeration for example.
2647 *
2648 * Returns 0 for success.
2649 */
2650int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2651 struct snd_ctl_elem_value *ucontrol)
2652{
2653 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
74155556 2654 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f 2655 unsigned int reg_val, val, mux;
2e72f8e3
PU
2656
2657 reg_val = snd_soc_read(codec, e->reg);
2658 val = (reg_val >> e->shift_l) & e->mask;
2659 for (mux = 0; mux < e->max; mux++) {
2660 if (val == e->values[mux])
2661 break;
2662 }
2663 ucontrol->value.enumerated.item[0] = mux;
2664 if (e->shift_l != e->shift_r) {
2665 val = (reg_val >> e->shift_r) & e->mask;
2666 for (mux = 0; mux < e->max; mux++) {
2667 if (val == e->values[mux])
2668 break;
2669 }
2670 ucontrol->value.enumerated.item[1] = mux;
2671 }
2672
2673 return 0;
2674}
2675EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2676
2677/**
2678 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2679 * @kcontrol: mixer control
2680 * @ucontrol: control element information
2681 *
2682 * Callback to set the value of a double semi enumerated mixer.
2683 *
2684 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2685 * used for handling bitfield coded enumeration for example.
2686 *
2687 * Returns 0 for success.
2688 */
2689int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2690 struct snd_ctl_elem_value *ucontrol)
2691{
2692 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
74155556 2693 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
46f5822f
DR
2694 unsigned int val;
2695 unsigned int mask;
2e72f8e3
PU
2696
2697 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2698 return -EINVAL;
2699 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2700 mask = e->mask << e->shift_l;
2701 if (e->shift_l != e->shift_r) {
2702 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2703 return -EINVAL;
2704 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2705 mask |= e->mask << e->shift_r;
2706 }
2707
6c508c62 2708 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
2e72f8e3
PU
2709}
2710EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2711
db2a4165
FM
2712/**
2713 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2714 * @kcontrol: mixer control
2715 * @uinfo: control element information
2716 *
2717 * Callback to provide information about an external enumerated
2718 * single mixer.
2719 *
2720 * Returns 0 for success.
2721 */
2722int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2723 struct snd_ctl_elem_info *uinfo)
2724{
2725 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2726
2727 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2728 uinfo->count = 1;
f8ba0b7b 2729 uinfo->value.enumerated.items = e->max;
db2a4165 2730
f8ba0b7b
JS
2731 if (uinfo->value.enumerated.item > e->max - 1)
2732 uinfo->value.enumerated.item = e->max - 1;
db2a4165
FM
2733 strcpy(uinfo->value.enumerated.name,
2734 e->texts[uinfo->value.enumerated.item]);
2735 return 0;
2736}
2737EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2738
2739/**
2740 * snd_soc_info_volsw_ext - external single mixer info callback
2741 * @kcontrol: mixer control
2742 * @uinfo: control element information
2743 *
2744 * Callback to provide information about a single external mixer control.
2745 *
2746 * Returns 0 for success.
2747 */
2748int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2749 struct snd_ctl_elem_info *uinfo)
2750{
a7a4ac86
PZ
2751 int max = kcontrol->private_value;
2752
fd5dfad9 2753 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
a7a4ac86
PZ
2754 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2755 else
2756 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
db2a4165 2757
db2a4165
FM
2758 uinfo->count = 1;
2759 uinfo->value.integer.min = 0;
a7a4ac86 2760 uinfo->value.integer.max = max;
db2a4165
FM
2761 return 0;
2762}
2763EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2764
db2a4165
FM
2765/**
2766 * snd_soc_info_volsw - single mixer info callback
2767 * @kcontrol: mixer control
2768 * @uinfo: control element information
2769 *
e8f5a103
PU
2770 * Callback to provide information about a single mixer control, or a double
2771 * mixer control that spans 2 registers.
db2a4165
FM
2772 *
2773 * Returns 0 for success.
2774 */
2775int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2776 struct snd_ctl_elem_info *uinfo)
2777{
4eaa9819
JS
2778 struct soc_mixer_control *mc =
2779 (struct soc_mixer_control *)kcontrol->private_value;
d11bb4a9 2780 int platform_max;
db2a4165 2781
d11bb4a9
PU
2782 if (!mc->platform_max)
2783 mc->platform_max = mc->max;
2784 platform_max = mc->platform_max;
2785
2786 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
a7a4ac86
PZ
2787 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2788 else
2789 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2790
e8f5a103 2791 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
db2a4165 2792 uinfo->value.integer.min = 0;
d11bb4a9 2793 uinfo->value.integer.max = platform_max;
db2a4165
FM
2794 return 0;
2795}
2796EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2797
2798/**
2799 * snd_soc_get_volsw - single mixer get callback
2800 * @kcontrol: mixer control
ac11a2b3 2801 * @ucontrol: control element information
db2a4165 2802 *
f7915d99
PU
2803 * Callback to get the value of a single mixer control, or a double mixer
2804 * control that spans 2 registers.
db2a4165
FM
2805 *
2806 * Returns 0 for success.
2807 */
2808int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2809 struct snd_ctl_elem_value *ucontrol)
2810{
4eaa9819
JS
2811 struct soc_mixer_control *mc =
2812 (struct soc_mixer_control *)kcontrol->private_value;
db2a4165 2813 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2814 unsigned int reg = mc->reg;
f7915d99 2815 unsigned int reg2 = mc->rreg;
815ecf8d
JS
2816 unsigned int shift = mc->shift;
2817 unsigned int rshift = mc->rshift;
4eaa9819 2818 int max = mc->max;
815ecf8d
JS
2819 unsigned int mask = (1 << fls(max)) - 1;
2820 unsigned int invert = mc->invert;
db2a4165
FM
2821
2822 ucontrol->value.integer.value[0] =
2823 (snd_soc_read(codec, reg) >> shift) & mask;
f7915d99 2824 if (invert)
db2a4165 2825 ucontrol->value.integer.value[0] =
a7a4ac86 2826 max - ucontrol->value.integer.value[0];
f7915d99
PU
2827
2828 if (snd_soc_volsw_is_stereo(mc)) {
2829 if (reg == reg2)
2830 ucontrol->value.integer.value[1] =
2831 (snd_soc_read(codec, reg) >> rshift) & mask;
2832 else
2833 ucontrol->value.integer.value[1] =
2834 (snd_soc_read(codec, reg2) >> shift) & mask;
2835 if (invert)
db2a4165 2836 ucontrol->value.integer.value[1] =
a7a4ac86 2837 max - ucontrol->value.integer.value[1];
db2a4165
FM
2838 }
2839
2840 return 0;
2841}
2842EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2843
2844/**
2845 * snd_soc_put_volsw - single mixer put callback
2846 * @kcontrol: mixer control
ac11a2b3 2847 * @ucontrol: control element information
db2a4165 2848 *
974815ba
PU
2849 * Callback to set the value of a single mixer control, or a double mixer
2850 * control that spans 2 registers.
db2a4165
FM
2851 *
2852 * Returns 0 for success.
2853 */
2854int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2855 struct snd_ctl_elem_value *ucontrol)
2856{
4eaa9819
JS
2857 struct soc_mixer_control *mc =
2858 (struct soc_mixer_control *)kcontrol->private_value;
db2a4165 2859 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 2860 unsigned int reg = mc->reg;
974815ba 2861 unsigned int reg2 = mc->rreg;
815ecf8d
JS
2862 unsigned int shift = mc->shift;
2863 unsigned int rshift = mc->rshift;
4eaa9819 2864 int max = mc->max;
815ecf8d
JS
2865 unsigned int mask = (1 << fls(max)) - 1;
2866 unsigned int invert = mc->invert;
974815ba
PU
2867 int err;
2868 bool type_2r = 0;
2869 unsigned int val2 = 0;
2870 unsigned int val, val_mask;
db2a4165
FM
2871
2872 val = (ucontrol->value.integer.value[0] & mask);
2873 if (invert)
a7a4ac86 2874 val = max - val;
db2a4165
FM
2875 val_mask = mask << shift;
2876 val = val << shift;
974815ba 2877 if (snd_soc_volsw_is_stereo(mc)) {
db2a4165
FM
2878 val2 = (ucontrol->value.integer.value[1] & mask);
2879 if (invert)
a7a4ac86 2880 val2 = max - val2;
974815ba
PU
2881 if (reg == reg2) {
2882 val_mask |= mask << rshift;
2883 val |= val2 << rshift;
2884 } else {
2885 val2 = val2 << shift;
2886 type_2r = 1;
2887 }
db2a4165 2888 }
6c508c62 2889 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
3ff3f64b 2890 if (err < 0)
db2a4165
FM
2891 return err;
2892
974815ba
PU
2893 if (type_2r)
2894 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2895
db2a4165
FM
2896 return err;
2897}
974815ba 2898EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
db2a4165 2899
1d99f243
BA
2900/**
2901 * snd_soc_get_volsw_sx - single mixer get callback
2902 * @kcontrol: mixer control
2903 * @ucontrol: control element information
2904 *
2905 * Callback to get the value of a single mixer control, or a double mixer
2906 * control that spans 2 registers.
2907 *
2908 * Returns 0 for success.
2909 */
2910int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2911 struct snd_ctl_elem_value *ucontrol)
2912{
2913 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2914 struct soc_mixer_control *mc =
2915 (struct soc_mixer_control *)kcontrol->private_value;
2916
2917 unsigned int reg = mc->reg;
2918 unsigned int reg2 = mc->rreg;
2919 unsigned int shift = mc->shift;
2920 unsigned int rshift = mc->rshift;
2921 int max = mc->max;
2922 int min = mc->min;
2923 int mask = (1 << (fls(min + max) - 1)) - 1;
2924
2925 ucontrol->value.integer.value[0] =
2926 ((snd_soc_read(codec, reg) >> shift) - min) & mask;
2927
2928 if (snd_soc_volsw_is_stereo(mc))
2929 ucontrol->value.integer.value[1] =
2930 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
2931
2932 return 0;
2933}
2934EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2935
2936/**
2937 * snd_soc_put_volsw_sx - double mixer set callback
2938 * @kcontrol: mixer control
2939 * @uinfo: control element information
2940 *
2941 * Callback to set the value of a double mixer control that spans 2 registers.
2942 *
2943 * Returns 0 for success.
2944 */
2945int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2946 struct snd_ctl_elem_value *ucontrol)
2947{
2948 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2949 struct soc_mixer_control *mc =
2950 (struct soc_mixer_control *)kcontrol->private_value;
2951
2952 unsigned int reg = mc->reg;
2953 unsigned int reg2 = mc->rreg;
2954 unsigned int shift = mc->shift;
2955 unsigned int rshift = mc->rshift;
2956 int max = mc->max;
2957 int min = mc->min;
2958 int mask = (1 << (fls(min + max) - 1)) - 1;
27f1d759 2959 int err = 0;
1d99f243
BA
2960 unsigned short val, val_mask, val2 = 0;
2961
2962 val_mask = mask << shift;
2963 val = (ucontrol->value.integer.value[0] + min) & mask;
2964 val = val << shift;
2965
d055852e
MN
2966 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2967 if (err < 0)
2968 return err;
1d99f243
BA
2969
2970 if (snd_soc_volsw_is_stereo(mc)) {
2971 val_mask = mask << rshift;
2972 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2973 val2 = val2 << rshift;
2974
2975 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
2976 return err;
2977 }
2978 return 0;
2979}
2980EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2981
e13ac2e9
MB
2982/**
2983 * snd_soc_info_volsw_s8 - signed mixer info callback
2984 * @kcontrol: mixer control
2985 * @uinfo: control element information
2986 *
2987 * Callback to provide information about a signed mixer control.
2988 *
2989 * Returns 0 for success.
2990 */
2991int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2992 struct snd_ctl_elem_info *uinfo)
2993{
4eaa9819
JS
2994 struct soc_mixer_control *mc =
2995 (struct soc_mixer_control *)kcontrol->private_value;
d11bb4a9 2996 int platform_max;
4eaa9819 2997 int min = mc->min;
e13ac2e9 2998
d11bb4a9
PU
2999 if (!mc->platform_max)
3000 mc->platform_max = mc->max;
3001 platform_max = mc->platform_max;
3002
e13ac2e9
MB
3003 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3004 uinfo->count = 2;
3005 uinfo->value.integer.min = 0;
d11bb4a9 3006 uinfo->value.integer.max = platform_max - min;
e13ac2e9
MB
3007 return 0;
3008}
3009EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
3010
3011/**
3012 * snd_soc_get_volsw_s8 - signed mixer get callback
3013 * @kcontrol: mixer control
ac11a2b3 3014 * @ucontrol: control element information
e13ac2e9
MB
3015 *
3016 * Callback to get the value of a signed mixer control.
3017 *
3018 * Returns 0 for success.
3019 */
3020int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
3021 struct snd_ctl_elem_value *ucontrol)
3022{
4eaa9819
JS
3023 struct soc_mixer_control *mc =
3024 (struct soc_mixer_control *)kcontrol->private_value;
e13ac2e9 3025 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 3026 unsigned int reg = mc->reg;
4eaa9819 3027 int min = mc->min;
e13ac2e9
MB
3028 int val = snd_soc_read(codec, reg);
3029
3030 ucontrol->value.integer.value[0] =
3031 ((signed char)(val & 0xff))-min;
3032 ucontrol->value.integer.value[1] =
3033 ((signed char)((val >> 8) & 0xff))-min;
3034 return 0;
3035}
3036EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
3037
3038/**
3039 * snd_soc_put_volsw_sgn - signed mixer put callback
3040 * @kcontrol: mixer control
ac11a2b3 3041 * @ucontrol: control element information
e13ac2e9
MB
3042 *
3043 * Callback to set the value of a signed mixer control.
3044 *
3045 * Returns 0 for success.
3046 */
3047int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
3048 struct snd_ctl_elem_value *ucontrol)
3049{
4eaa9819
JS
3050 struct soc_mixer_control *mc =
3051 (struct soc_mixer_control *)kcontrol->private_value;
e13ac2e9 3052 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
815ecf8d 3053 unsigned int reg = mc->reg;
4eaa9819 3054 int min = mc->min;
46f5822f 3055 unsigned int val;
e13ac2e9
MB
3056
3057 val = (ucontrol->value.integer.value[0]+min) & 0xff;
3058 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
3059
6c508c62 3060 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
e13ac2e9
MB
3061}
3062EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
3063
6c9d8cf6
AT
3064/**
3065 * snd_soc_info_volsw_range - single mixer info callback with range.
3066 * @kcontrol: mixer control
3067 * @uinfo: control element information
3068 *
3069 * Callback to provide information, within a range, about a single
3070 * mixer control.
3071 *
3072 * returns 0 for success.
3073 */
3074int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
3075 struct snd_ctl_elem_info *uinfo)
3076{
3077 struct soc_mixer_control *mc =
3078 (struct soc_mixer_control *)kcontrol->private_value;
3079 int platform_max;
3080 int min = mc->min;
3081
3082 if (!mc->platform_max)
3083 mc->platform_max = mc->max;
3084 platform_max = mc->platform_max;
3085
3086 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
9bde4f0b 3087 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
6c9d8cf6
AT
3088 uinfo->value.integer.min = 0;
3089 uinfo->value.integer.max = platform_max - min;
3090
3091 return 0;
3092}
3093EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
3094
3095/**
3096 * snd_soc_put_volsw_range - single mixer put value callback with range.
3097 * @kcontrol: mixer control
3098 * @ucontrol: control element information
3099 *
3100 * Callback to set the value, within a range, for a single mixer control.
3101 *
3102 * Returns 0 for success.
3103 */
3104int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
3105 struct snd_ctl_elem_value *ucontrol)
3106{
3107 struct soc_mixer_control *mc =
3108 (struct soc_mixer_control *)kcontrol->private_value;
3109 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3110 unsigned int reg = mc->reg;
9bde4f0b 3111 unsigned int rreg = mc->rreg;
6c9d8cf6
AT
3112 unsigned int shift = mc->shift;
3113 int min = mc->min;
3114 int max = mc->max;
3115 unsigned int mask = (1 << fls(max)) - 1;
3116 unsigned int invert = mc->invert;
3117 unsigned int val, val_mask;
9bde4f0b 3118 int ret;
6c9d8cf6
AT
3119
3120 val = ((ucontrol->value.integer.value[0] + min) & mask);
3121 if (invert)
3122 val = max - val;
3123 val_mask = mask << shift;
3124 val = val << shift;
3125
9bde4f0b 3126 ret = snd_soc_update_bits_locked(codec, reg, val_mask, val);
0eaa6cca 3127 if (ret < 0)
9bde4f0b
MB
3128 return ret;
3129
3130 if (snd_soc_volsw_is_stereo(mc)) {
3131 val = ((ucontrol->value.integer.value[1] + min) & mask);
3132 if (invert)
3133 val = max - val;
3134 val_mask = mask << shift;
3135 val = val << shift;
3136
3137 ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val);
3138 }
3139
3140 return ret;
6c9d8cf6
AT
3141}
3142EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
3143
3144/**
3145 * snd_soc_get_volsw_range - single mixer get callback with range
3146 * @kcontrol: mixer control
3147 * @ucontrol: control element information
3148 *
3149 * Callback to get the value, within a range, of a single mixer control.
3150 *
3151 * Returns 0 for success.
3152 */
3153int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
3154 struct snd_ctl_elem_value *ucontrol)
3155{
3156 struct soc_mixer_control *mc =
3157 (struct soc_mixer_control *)kcontrol->private_value;
3158 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3159 unsigned int reg = mc->reg;
9bde4f0b 3160 unsigned int rreg = mc->rreg;
6c9d8cf6
AT
3161 unsigned int shift = mc->shift;
3162 int min = mc->min;
3163 int max = mc->max;
3164 unsigned int mask = (1 << fls(max)) - 1;
3165 unsigned int invert = mc->invert;
3166
3167 ucontrol->value.integer.value[0] =
3168 (snd_soc_read(codec, reg) >> shift) & mask;
3169 if (invert)
3170 ucontrol->value.integer.value[0] =
3171 max - ucontrol->value.integer.value[0];
3172 ucontrol->value.integer.value[0] =
3173 ucontrol->value.integer.value[0] - min;
3174
9bde4f0b
MB
3175 if (snd_soc_volsw_is_stereo(mc)) {
3176 ucontrol->value.integer.value[1] =
3177 (snd_soc_read(codec, rreg) >> shift) & mask;
3178 if (invert)
3179 ucontrol->value.integer.value[1] =
3180 max - ucontrol->value.integer.value[1];
3181 ucontrol->value.integer.value[1] =
3182 ucontrol->value.integer.value[1] - min;
3183 }
3184
6c9d8cf6
AT
3185 return 0;
3186}
3187EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
3188
637d3847
PU
3189/**
3190 * snd_soc_limit_volume - Set new limit to an existing volume control.
3191 *
3192 * @codec: where to look for the control
3193 * @name: Name of the control
3194 * @max: new maximum limit
3195 *
3196 * Return 0 for success, else error.
3197 */
3198int snd_soc_limit_volume(struct snd_soc_codec *codec,
3199 const char *name, int max)
3200{
f0fba2ad 3201 struct snd_card *card = codec->card->snd_card;
637d3847
PU
3202 struct snd_kcontrol *kctl;
3203 struct soc_mixer_control *mc;
3204 int found = 0;
3205 int ret = -EINVAL;
3206
3207 /* Sanity check for name and max */
3208 if (unlikely(!name || max <= 0))
3209 return -EINVAL;
3210
3211 list_for_each_entry(kctl, &card->controls, list) {
3212 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
3213 found = 1;
3214 break;
3215 }
3216 }
3217 if (found) {
3218 mc = (struct soc_mixer_control *)kctl->private_value;
3219 if (max <= mc->max) {
d11bb4a9 3220 mc->platform_max = max;
637d3847
PU
3221 ret = 0;
3222 }
3223 }
3224 return ret;
3225}
3226EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
3227
71d08516
MB
3228int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
3229 struct snd_ctl_elem_info *uinfo)
3230{
3231 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3232 struct soc_bytes *params = (void *)kcontrol->private_value;
3233
3234 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3235 uinfo->count = params->num_regs * codec->val_bytes;
3236
3237 return 0;
3238}
3239EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3240
3241int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3242 struct snd_ctl_elem_value *ucontrol)
3243{
3244 struct soc_bytes *params = (void *)kcontrol->private_value;
3245 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3246 int ret;
3247
3248 if (codec->using_regmap)
3249 ret = regmap_raw_read(codec->control_data, params->base,
3250 ucontrol->value.bytes.data,
3251 params->num_regs * codec->val_bytes);
3252 else
3253 ret = -EINVAL;
3254
f831b055
MB
3255 /* Hide any masked bytes to ensure consistent data reporting */
3256 if (ret == 0 && params->mask) {
3257 switch (codec->val_bytes) {
3258 case 1:
3259 ucontrol->value.bytes.data[0] &= ~params->mask;
3260 break;
3261 case 2:
3262 ((u16 *)(&ucontrol->value.bytes.data))[0]
3263 &= ~params->mask;
3264 break;
3265 case 4:
3266 ((u32 *)(&ucontrol->value.bytes.data))[0]
3267 &= ~params->mask;
3268 break;
3269 default:
3270 return -EINVAL;
3271 }
3272 }
3273
71d08516
MB
3274 return ret;
3275}
3276EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3277
3278int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3279 struct snd_ctl_elem_value *ucontrol)
3280{
3281 struct soc_bytes *params = (void *)kcontrol->private_value;
3282 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
f831b055
MB
3283 int ret, len;
3284 unsigned int val;
3285 void *data;
71d08516 3286
f831b055
MB
3287 if (!codec->using_regmap)
3288 return -EINVAL;
3289
f831b055
MB
3290 len = params->num_regs * codec->val_bytes;
3291
b5a8fe43
MB
3292 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3293 if (!data)
3294 return -ENOMEM;
3295
f831b055
MB
3296 /*
3297 * If we've got a mask then we need to preserve the register
3298 * bits. We shouldn't modify the incoming data so take a
3299 * copy.
3300 */
3301 if (params->mask) {
3302 ret = regmap_read(codec->control_data, params->base, &val);
3303 if (ret != 0)
e8b18add 3304 goto out;
f831b055
MB
3305
3306 val &= params->mask;
3307
f831b055
MB
3308 switch (codec->val_bytes) {
3309 case 1:
3310 ((u8 *)data)[0] &= ~params->mask;
3311 ((u8 *)data)[0] |= val;
3312 break;
3313 case 2:
3314 ((u16 *)data)[0] &= cpu_to_be16(~params->mask);
3315 ((u16 *)data)[0] |= cpu_to_be16(val);
3316 break;
3317 case 4:
3318 ((u32 *)data)[0] &= cpu_to_be32(~params->mask);
3319 ((u32 *)data)[0] |= cpu_to_be32(val);
3320 break;
3321 default:
e8b18add
WY
3322 ret = -EINVAL;
3323 goto out;
f831b055
MB
3324 }
3325 }
3326
3327 ret = regmap_raw_write(codec->control_data, params->base,
3328 data, len);
3329
e8b18add 3330out:
b5a8fe43 3331 kfree(data);
71d08516
MB
3332
3333 return ret;
3334}
3335EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
3336
4183eed2
KK
3337/**
3338 * snd_soc_info_xr_sx - signed multi register info callback
3339 * @kcontrol: mreg control
3340 * @uinfo: control element information
3341 *
3342 * Callback to provide information of a control that can
3343 * span multiple codec registers which together
3344 * forms a single signed value in a MSB/LSB manner.
3345 *
3346 * Returns 0 for success.
3347 */
3348int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
3349 struct snd_ctl_elem_info *uinfo)
3350{
3351 struct soc_mreg_control *mc =
3352 (struct soc_mreg_control *)kcontrol->private_value;
3353 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3354 uinfo->count = 1;
3355 uinfo->value.integer.min = mc->min;
3356 uinfo->value.integer.max = mc->max;
3357
3358 return 0;
3359}
3360EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3361
3362/**
3363 * snd_soc_get_xr_sx - signed multi register get callback
3364 * @kcontrol: mreg control
3365 * @ucontrol: control element information
3366 *
3367 * Callback to get the value of a control that can span
3368 * multiple codec registers which together forms a single
3369 * signed value in a MSB/LSB manner. The control supports
3370 * specifying total no of bits used to allow for bitfields
3371 * across the multiple codec registers.
3372 *
3373 * Returns 0 for success.
3374 */
3375int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3376 struct snd_ctl_elem_value *ucontrol)
3377{
3378 struct soc_mreg_control *mc =
3379 (struct soc_mreg_control *)kcontrol->private_value;
3380 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3381 unsigned int regbase = mc->regbase;
3382 unsigned int regcount = mc->regcount;
3383 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3384 unsigned int regwmask = (1<<regwshift)-1;
3385 unsigned int invert = mc->invert;
3386 unsigned long mask = (1UL<<mc->nbits)-1;
3387 long min = mc->min;
3388 long max = mc->max;
3389 long val = 0;
3390 unsigned long regval;
3391 unsigned int i;
3392
3393 for (i = 0; i < regcount; i++) {
3394 regval = snd_soc_read(codec, regbase+i) & regwmask;
3395 val |= regval << (regwshift*(regcount-i-1));
3396 }
3397 val &= mask;
3398 if (min < 0 && val > max)
3399 val |= ~mask;
3400 if (invert)
3401 val = max - val;
3402 ucontrol->value.integer.value[0] = val;
3403
3404 return 0;
3405}
3406EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3407
3408/**
3409 * snd_soc_put_xr_sx - signed multi register get callback
3410 * @kcontrol: mreg control
3411 * @ucontrol: control element information
3412 *
3413 * Callback to set the value of a control that can span
3414 * multiple codec registers which together forms a single
3415 * signed value in a MSB/LSB manner. The control supports
3416 * specifying total no of bits used to allow for bitfields
3417 * across the multiple codec registers.
3418 *
3419 * Returns 0 for success.
3420 */
3421int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3422 struct snd_ctl_elem_value *ucontrol)
3423{
3424 struct soc_mreg_control *mc =
3425 (struct soc_mreg_control *)kcontrol->private_value;
3426 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3427 unsigned int regbase = mc->regbase;
3428 unsigned int regcount = mc->regcount;
3429 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3430 unsigned int regwmask = (1<<regwshift)-1;
3431 unsigned int invert = mc->invert;
3432 unsigned long mask = (1UL<<mc->nbits)-1;
4183eed2
KK
3433 long max = mc->max;
3434 long val = ucontrol->value.integer.value[0];
3435 unsigned int i, regval, regmask;
3436 int err;
3437
3438 if (invert)
3439 val = max - val;
3440 val &= mask;
3441 for (i = 0; i < regcount; i++) {
3442 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3443 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3444 err = snd_soc_update_bits_locked(codec, regbase+i,
3445 regmask, regval);
3446 if (err < 0)
3447 return err;
3448 }
3449
3450 return 0;
3451}
3452EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3453
dd7b10b3
KK
3454/**
3455 * snd_soc_get_strobe - strobe get callback
3456 * @kcontrol: mixer control
3457 * @ucontrol: control element information
3458 *
3459 * Callback get the value of a strobe mixer control.
3460 *
3461 * Returns 0 for success.
3462 */
3463int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3464 struct snd_ctl_elem_value *ucontrol)
3465{
3466 struct soc_mixer_control *mc =
3467 (struct soc_mixer_control *)kcontrol->private_value;
3468 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3469 unsigned int reg = mc->reg;
3470 unsigned int shift = mc->shift;
3471 unsigned int mask = 1 << shift;
3472 unsigned int invert = mc->invert != 0;
3473 unsigned int val = snd_soc_read(codec, reg) & mask;
3474
3475 if (shift != 0 && val != 0)
3476 val = val >> shift;
3477 ucontrol->value.enumerated.item[0] = val ^ invert;
3478
3479 return 0;
3480}
3481EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3482
3483/**
3484 * snd_soc_put_strobe - strobe put callback
3485 * @kcontrol: mixer control
3486 * @ucontrol: control element information
3487 *
3488 * Callback strobe a register bit to high then low (or the inverse)
3489 * in one pass of a single mixer enum control.
3490 *
3491 * Returns 1 for success.
3492 */
3493int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3494 struct snd_ctl_elem_value *ucontrol)
3495{
3496 struct soc_mixer_control *mc =
3497 (struct soc_mixer_control *)kcontrol->private_value;
3498 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3499 unsigned int reg = mc->reg;
3500 unsigned int shift = mc->shift;
3501 unsigned int mask = 1 << shift;
3502 unsigned int invert = mc->invert != 0;
3503 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3504 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3505 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3506 int err;
3507
3508 err = snd_soc_update_bits_locked(codec, reg, mask, val1);
3509 if (err < 0)
3510 return err;
3511
3512 err = snd_soc_update_bits_locked(codec, reg, mask, val2);
3513 return err;
3514}
3515EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3516
8c6529db
LG
3517/**
3518 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3519 * @dai: DAI
3520 * @clk_id: DAI specific clock ID
3521 * @freq: new clock frequency in Hz
3522 * @dir: new clock direction - input/output.
3523 *
3524 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3525 */
3526int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
3527 unsigned int freq, int dir)
3528{
f0fba2ad
LG
3529 if (dai->driver && dai->driver->ops->set_sysclk)
3530 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
ec4ee52a 3531 else if (dai->codec && dai->codec->driver->set_sysclk)
da1c6ea6 3532 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
ec4ee52a 3533 freq, dir);
8c6529db
LG
3534 else
3535 return -EINVAL;
3536}
3537EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
3538
ec4ee52a
MB
3539/**
3540 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3541 * @codec: CODEC
3542 * @clk_id: DAI specific clock ID
da1c6ea6 3543 * @source: Source for the clock
ec4ee52a
MB
3544 * @freq: new clock frequency in Hz
3545 * @dir: new clock direction - input/output.
3546 *
3547 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3548 */
3549int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
da1c6ea6 3550 int source, unsigned int freq, int dir)
ec4ee52a
MB
3551{
3552 if (codec->driver->set_sysclk)
da1c6ea6
MB
3553 return codec->driver->set_sysclk(codec, clk_id, source,
3554 freq, dir);
ec4ee52a
MB
3555 else
3556 return -EINVAL;
3557}
3558EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
3559
8c6529db
LG
3560/**
3561 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3562 * @dai: DAI
ac11a2b3 3563 * @div_id: DAI specific clock divider ID
8c6529db
LG
3564 * @div: new clock divisor.
3565 *
3566 * Configures the clock dividers. This is used to derive the best DAI bit and
3567 * frame clocks from the system or master clock. It's best to set the DAI bit
3568 * and frame clocks as low as possible to save system power.
3569 */
3570int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
3571 int div_id, int div)
3572{
f0fba2ad
LG
3573 if (dai->driver && dai->driver->ops->set_clkdiv)
3574 return dai->driver->ops->set_clkdiv(dai, div_id, div);
8c6529db
LG
3575 else
3576 return -EINVAL;
3577}
3578EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
3579
3580/**
3581 * snd_soc_dai_set_pll - configure DAI PLL.
3582 * @dai: DAI
3583 * @pll_id: DAI specific PLL ID
85488037 3584 * @source: DAI specific source for the PLL
8c6529db
LG
3585 * @freq_in: PLL input clock frequency in Hz
3586 * @freq_out: requested PLL output clock frequency in Hz
3587 *
3588 * Configures and enables PLL to generate output clock based on input clock.
3589 */
85488037
MB
3590int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
3591 unsigned int freq_in, unsigned int freq_out)
8c6529db 3592{
f0fba2ad
LG
3593 if (dai->driver && dai->driver->ops->set_pll)
3594 return dai->driver->ops->set_pll(dai, pll_id, source,
85488037 3595 freq_in, freq_out);
ec4ee52a
MB
3596 else if (dai->codec && dai->codec->driver->set_pll)
3597 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
3598 freq_in, freq_out);
8c6529db
LG
3599 else
3600 return -EINVAL;
3601}
3602EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
3603
ec4ee52a
MB
3604/*
3605 * snd_soc_codec_set_pll - configure codec PLL.
3606 * @codec: CODEC
3607 * @pll_id: DAI specific PLL ID
3608 * @source: DAI specific source for the PLL
3609 * @freq_in: PLL input clock frequency in Hz
3610 * @freq_out: requested PLL output clock frequency in Hz
3611 *
3612 * Configures and enables PLL to generate output clock based on input clock.
3613 */
3614int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
3615 unsigned int freq_in, unsigned int freq_out)
3616{
3617 if (codec->driver->set_pll)
3618 return codec->driver->set_pll(codec, pll_id, source,
3619 freq_in, freq_out);
3620 else
3621 return -EINVAL;
3622}
3623EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
3624
8c6529db
LG
3625/**
3626 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3627 * @dai: DAI
8c6529db
LG
3628 * @fmt: SND_SOC_DAIFMT_ format value.
3629 *
3630 * Configures the DAI hardware format and clocking.
3631 */
3632int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3633{
5e4ba569 3634 if (dai->driver == NULL)
8c6529db 3635 return -EINVAL;
5e4ba569
SG
3636 if (dai->driver->ops->set_fmt == NULL)
3637 return -ENOTSUPP;
3638 return dai->driver->ops->set_fmt(dai, fmt);
8c6529db
LG
3639}
3640EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3641
3642/**
3643 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3644 * @dai: DAI
a5479e38
DR
3645 * @tx_mask: bitmask representing active TX slots.
3646 * @rx_mask: bitmask representing active RX slots.
8c6529db 3647 * @slots: Number of slots in use.
a5479e38 3648 * @slot_width: Width in bits for each slot.
8c6529db
LG
3649 *
3650 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3651 * specific.
3652 */
3653int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
a5479e38 3654 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
8c6529db 3655{
f0fba2ad
LG
3656 if (dai->driver && dai->driver->ops->set_tdm_slot)
3657 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
a5479e38 3658 slots, slot_width);
8c6529db
LG
3659 else
3660 return -EINVAL;
3661}
3662EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
3663
472df3cb
BS
3664/**
3665 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3666 * @dai: DAI
3667 * @tx_num: how many TX channels
3668 * @tx_slot: pointer to an array which imply the TX slot number channel
3669 * 0~num-1 uses
3670 * @rx_num: how many RX channels
3671 * @rx_slot: pointer to an array which imply the RX slot number channel
3672 * 0~num-1 uses
3673 *
3674 * configure the relationship between channel number and TDM slot number.
3675 */
3676int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
3677 unsigned int tx_num, unsigned int *tx_slot,
3678 unsigned int rx_num, unsigned int *rx_slot)
3679{
f0fba2ad
LG
3680 if (dai->driver && dai->driver->ops->set_channel_map)
3681 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
472df3cb
BS
3682 rx_num, rx_slot);
3683 else
3684 return -EINVAL;
3685}
3686EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
3687
8c6529db
LG
3688/**
3689 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3690 * @dai: DAI
3691 * @tristate: tristate enable
3692 *
3693 * Tristates the DAI so that others can use it.
3694 */
3695int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
3696{
f0fba2ad
LG
3697 if (dai->driver && dai->driver->ops->set_tristate)
3698 return dai->driver->ops->set_tristate(dai, tristate);
8c6529db
LG
3699 else
3700 return -EINVAL;
3701}
3702EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
3703
3704/**
3705 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3706 * @dai: DAI
3707 * @mute: mute enable
da18396f 3708 * @direction: stream to mute
8c6529db
LG
3709 *
3710 * Mutes the DAI DAC.
3711 */
da18396f
MB
3712int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
3713 int direction)
8c6529db 3714{
da18396f
MB
3715 if (!dai->driver)
3716 return -ENOTSUPP;
3717
3718 if (dai->driver->ops->mute_stream)
3719 return dai->driver->ops->mute_stream(dai, mute, direction);
3720 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
3721 dai->driver->ops->digital_mute)
f0fba2ad 3722 return dai->driver->ops->digital_mute(dai, mute);
8c6529db 3723 else
04570c62 3724 return -ENOTSUPP;
8c6529db
LG
3725}
3726EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3727
c5af3a2e
MB
3728/**
3729 * snd_soc_register_card - Register a card with the ASoC core
3730 *
ac11a2b3 3731 * @card: Card to register
c5af3a2e 3732 *
c5af3a2e 3733 */
70a7ca34 3734int snd_soc_register_card(struct snd_soc_card *card)
c5af3a2e 3735{
b19e6e7b 3736 int i, ret;
f0fba2ad 3737
c5af3a2e
MB
3738 if (!card->name || !card->dev)
3739 return -EINVAL;
3740
5a504963
SW
3741 for (i = 0; i < card->num_links; i++) {
3742 struct snd_soc_dai_link *link = &card->dai_link[i];
3743
3744 /*
3745 * Codec must be specified by 1 of name or OF node,
3746 * not both or neither.
3747 */
3748 if (!!link->codec_name == !!link->codec_of_node) {
10e8aa9a
MM
3749 dev_err(card->dev,
3750 "ASoC: Neither/both codec name/of_node are set for %s\n",
3751 link->name);
5a504963
SW
3752 return -EINVAL;
3753 }
bc92657a
SW
3754 /* Codec DAI name must be specified */
3755 if (!link->codec_dai_name) {
10e8aa9a
MM
3756 dev_err(card->dev,
3757 "ASoC: codec_dai_name not set for %s\n",
3758 link->name);
bc92657a
SW
3759 return -EINVAL;
3760 }
5a504963
SW
3761
3762 /*
3763 * Platform may be specified by either name or OF node, but
3764 * can be left unspecified, and a dummy platform will be used.
3765 */
3766 if (link->platform_name && link->platform_of_node) {
10e8aa9a
MM
3767 dev_err(card->dev,
3768 "ASoC: Both platform name/of_node are set for %s\n",
3769 link->name);
5a504963
SW
3770 return -EINVAL;
3771 }
3772
3773 /*
bc92657a
SW
3774 * CPU device may be specified by either name or OF node, but
3775 * can be left unspecified, and will be matched based on DAI
3776 * name alone..
3777 */
3778 if (link->cpu_name && link->cpu_of_node) {
10e8aa9a
MM
3779 dev_err(card->dev,
3780 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3781 link->name);
bc92657a
SW
3782 return -EINVAL;
3783 }
3784 /*
3785 * At least one of CPU DAI name or CPU device name/node must be
3786 * specified
5a504963 3787 */
bc92657a
SW
3788 if (!link->cpu_dai_name &&
3789 !(link->cpu_name || link->cpu_of_node)) {
10e8aa9a
MM
3790 dev_err(card->dev,
3791 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3792 link->name);
5a504963
SW
3793 return -EINVAL;
3794 }
3795 }
3796
ed77cc12
MB
3797 dev_set_drvdata(card->dev, card);
3798
111c6419
SW
3799 snd_soc_initialize_card_lists(card);
3800
150dd2f8
VK
3801 soc_init_card_debugfs(card);
3802
181a6892
MB
3803 card->rtd = devm_kzalloc(card->dev,
3804 sizeof(struct snd_soc_pcm_runtime) *
3805 (card->num_links + card->num_aux_devs),
3806 GFP_KERNEL);
f0fba2ad
LG
3807 if (card->rtd == NULL)
3808 return -ENOMEM;
a7dbb603 3809 card->num_rtd = 0;
2eea392d 3810 card->rtd_aux = &card->rtd[card->num_links];
f0fba2ad
LG
3811
3812 for (i = 0; i < card->num_links; i++)
3813 card->rtd[i].dai_link = &card->dai_link[i];
3814
c5af3a2e 3815 INIT_LIST_HEAD(&card->list);
db432b41 3816 INIT_LIST_HEAD(&card->dapm_dirty);
c5af3a2e 3817 card->instantiated = 0;
f0fba2ad 3818 mutex_init(&card->mutex);
a73fb2df 3819 mutex_init(&card->dapm_mutex);
c5af3a2e 3820
b19e6e7b
MB
3821 ret = snd_soc_instantiate_card(card);
3822 if (ret != 0)
3823 soc_cleanup_card_debugfs(card);
c5af3a2e 3824
b19e6e7b 3825 return ret;
c5af3a2e 3826}
70a7ca34 3827EXPORT_SYMBOL_GPL(snd_soc_register_card);
c5af3a2e
MB
3828
3829/**
3830 * snd_soc_unregister_card - Unregister a card with the ASoC core
3831 *
ac11a2b3 3832 * @card: Card to unregister
c5af3a2e 3833 *
c5af3a2e 3834 */
70a7ca34 3835int snd_soc_unregister_card(struct snd_soc_card *card)
c5af3a2e 3836{
b0e26485
VK
3837 if (card->instantiated)
3838 soc_cleanup_card_resources(card);
f110bfc7 3839 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
c5af3a2e
MB
3840
3841 return 0;
3842}
70a7ca34 3843EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
c5af3a2e 3844
f0fba2ad
LG
3845/*
3846 * Simplify DAI link configuration by removing ".-1" from device names
3847 * and sanitizing names.
3848 */
0b9a214a 3849static char *fmt_single_name(struct device *dev, int *id)
f0fba2ad
LG
3850{
3851 char *found, name[NAME_SIZE];
3852 int id1, id2;
3853
3854 if (dev_name(dev) == NULL)
3855 return NULL;
3856
58818a77 3857 strlcpy(name, dev_name(dev), NAME_SIZE);
f0fba2ad
LG
3858
3859 /* are we a "%s.%d" name (platform and SPI components) */
3860 found = strstr(name, dev->driver->name);
3861 if (found) {
3862 /* get ID */
3863 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3864
3865 /* discard ID from name if ID == -1 */
3866 if (*id == -1)
3867 found[strlen(dev->driver->name)] = '\0';
3868 }
3869
3870 } else {
3871 /* I2C component devices are named "bus-addr" */
3872 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3873 char tmp[NAME_SIZE];
3874
3875 /* create unique ID number from I2C addr and bus */
05899446 3876 *id = ((id1 & 0xffff) << 16) + id2;
f0fba2ad
LG
3877
3878 /* sanitize component name for DAI link creation */
3879 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
58818a77 3880 strlcpy(name, tmp, NAME_SIZE);
f0fba2ad
LG
3881 } else
3882 *id = 0;
3883 }
3884
3885 return kstrdup(name, GFP_KERNEL);
3886}
3887
3888/*
3889 * Simplify DAI link naming for single devices with multiple DAIs by removing
3890 * any ".-1" and using the DAI name (instead of device name).
3891 */
3892static inline char *fmt_multiple_name(struct device *dev,
3893 struct snd_soc_dai_driver *dai_drv)
3894{
3895 if (dai_drv->name == NULL) {
10e8aa9a
MM
3896 dev_err(dev,
3897 "ASoC: error - multiple DAI %s registered with no name\n",
3898 dev_name(dev));
f0fba2ad
LG
3899 return NULL;
3900 }
3901
3902 return kstrdup(dai_drv->name, GFP_KERNEL);
3903}
3904
9115171a
MB
3905/**
3906 * snd_soc_register_dai - Register a DAI with the ASoC core
3907 *
ac11a2b3 3908 * @dai: DAI to register
9115171a 3909 */
f53179c0 3910static int snd_soc_register_dai(struct device *dev,
f0fba2ad 3911 struct snd_soc_dai_driver *dai_drv)
9115171a 3912{
054880fe 3913 struct snd_soc_codec *codec;
f0fba2ad
LG
3914 struct snd_soc_dai *dai;
3915
f110bfc7 3916 dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
9115171a 3917
f0fba2ad
LG
3918 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3919 if (dai == NULL)
a7393623 3920 return -ENOMEM;
9115171a 3921
f0fba2ad
LG
3922 /* create DAI component name */
3923 dai->name = fmt_single_name(dev, &dai->id);
3924 if (dai->name == NULL) {
3925 kfree(dai);
3926 return -ENOMEM;
3927 }
6335d055 3928
f0fba2ad
LG
3929 dai->dev = dev;
3930 dai->driver = dai_drv;
be09ad90 3931 dai->dapm.dev = dev;
f0fba2ad
LG
3932 if (!dai->driver->ops)
3933 dai->driver->ops = &null_dai_ops;
9115171a
MB
3934
3935 mutex_lock(&client_mutex);
054880fe
MB
3936
3937 list_for_each_entry(codec, &codec_list, list) {
3938 if (codec->dev == dev) {
f110bfc7 3939 dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
054880fe
MB
3940 dai->name, codec->name);
3941 dai->codec = codec;
3942 break;
3943 }
3944 }
3945
5f800080
PU
3946 if (!dai->codec)
3947 dai->dapm.idle_bias_off = 1;
3948
9115171a 3949 list_add(&dai->list, &dai_list);
054880fe 3950
9115171a
MB
3951 mutex_unlock(&client_mutex);
3952
f110bfc7 3953 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
9115171a
MB
3954
3955 return 0;
3956}
9115171a
MB
3957
3958/**
3959 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3960 *
ac11a2b3 3961 * @dai: DAI to unregister
9115171a 3962 */
f53179c0 3963static void snd_soc_unregister_dai(struct device *dev)
9115171a 3964{
f0fba2ad
LG
3965 struct snd_soc_dai *dai;
3966
3967 list_for_each_entry(dai, &dai_list, list) {
3968 if (dev == dai->dev)
3969 goto found;
3970 }
3971 return;
3972
3973found:
9115171a
MB
3974 mutex_lock(&client_mutex);
3975 list_del(&dai->list);
3976 mutex_unlock(&client_mutex);
3977
f110bfc7 3978 dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
f0fba2ad
LG
3979 kfree(dai->name);
3980 kfree(dai);
9115171a 3981}
9115171a
MB
3982
3983/**
3984 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3985 *
ac11a2b3
MB
3986 * @dai: Array of DAIs to register
3987 * @count: Number of DAIs
9115171a 3988 */
f53179c0 3989static int snd_soc_register_dais(struct device *dev,
f0fba2ad 3990 struct snd_soc_dai_driver *dai_drv, size_t count)
9115171a 3991{
054880fe 3992 struct snd_soc_codec *codec;
f0fba2ad
LG
3993 struct snd_soc_dai *dai;
3994 int i, ret = 0;
3995
f110bfc7 3996 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
9115171a
MB
3997
3998 for (i = 0; i < count; i++) {
f0fba2ad
LG
3999
4000 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
c46e0079
AL
4001 if (dai == NULL) {
4002 ret = -ENOMEM;
4003 goto err;
4004 }
f0fba2ad
LG
4005
4006 /* create DAI component name */
4007 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
4008 if (dai->name == NULL) {
4009 kfree(dai);
4010 ret = -EINVAL;
9115171a 4011 goto err;
f0fba2ad
LG
4012 }
4013
4014 dai->dev = dev;
f0fba2ad 4015 dai->driver = &dai_drv[i];
0f9141c9
MB
4016 if (dai->driver->id)
4017 dai->id = dai->driver->id;
4018 else
4019 dai->id = i;
be09ad90 4020 dai->dapm.dev = dev;
f0fba2ad
LG
4021 if (!dai->driver->ops)
4022 dai->driver->ops = &null_dai_ops;
4023
4024 mutex_lock(&client_mutex);
054880fe
MB
4025
4026 list_for_each_entry(codec, &codec_list, list) {
4027 if (codec->dev == dev) {
10e8aa9a
MM
4028 dev_dbg(dev,
4029 "ASoC: Mapped DAI %s to CODEC %s\n",
4030 dai->name, codec->name);
054880fe
MB
4031 dai->codec = codec;
4032 break;
4033 }
4034 }
4035
5f800080
PU
4036 if (!dai->codec)
4037 dai->dapm.idle_bias_off = 1;
4038
f0fba2ad 4039 list_add(&dai->list, &dai_list);
054880fe 4040
f0fba2ad
LG
4041 mutex_unlock(&client_mutex);
4042
f110bfc7 4043 dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name);
9115171a
MB
4044 }
4045
4046 return 0;
4047
4048err:
4049 for (i--; i >= 0; i--)
f0fba2ad 4050 snd_soc_unregister_dai(dev);
9115171a
MB
4051
4052 return ret;
4053}
9115171a
MB
4054
4055/**
4056 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
4057 *
ac11a2b3
MB
4058 * @dai: Array of DAIs to unregister
4059 * @count: Number of DAIs
9115171a 4060 */
f53179c0 4061static void snd_soc_unregister_dais(struct device *dev, size_t count)
9115171a
MB
4062{
4063 int i;
4064
4065 for (i = 0; i < count; i++)
f0fba2ad 4066 snd_soc_unregister_dai(dev);
9115171a 4067}
9115171a 4068
12a48a8c 4069/**
71a45cda
LPC
4070 * snd_soc_add_platform - Add a platform to the ASoC core
4071 * @dev: The parent device for the platform
4072 * @platform: The platform to add
4073 * @platform_driver: The driver for the platform
12a48a8c 4074 */
71a45cda 4075int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
d79e57db 4076 const struct snd_soc_platform_driver *platform_drv)
12a48a8c 4077{
f0fba2ad
LG
4078 /* create platform component name */
4079 platform->name = fmt_single_name(dev, &platform->id);
b5c745fb 4080 if (platform->name == NULL)
f0fba2ad 4081 return -ENOMEM;
12a48a8c 4082
f0fba2ad
LG
4083 platform->dev = dev;
4084 platform->driver = platform_drv;
b7950641
LG
4085 platform->dapm.dev = dev;
4086 platform->dapm.platform = platform;
64a648c2 4087 platform->dapm.stream_event = platform_drv->stream_event;
cc22d37e 4088 mutex_init(&platform->mutex);
12a48a8c
MB
4089
4090 mutex_lock(&client_mutex);
4091 list_add(&platform->list, &platform_list);
4092 mutex_unlock(&client_mutex);
4093
f110bfc7 4094 dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name);
12a48a8c
MB
4095
4096 return 0;
4097}
71a45cda 4098EXPORT_SYMBOL_GPL(snd_soc_add_platform);
12a48a8c
MB
4099
4100/**
71a45cda 4101 * snd_soc_register_platform - Register a platform with the ASoC core
12a48a8c 4102 *
71a45cda 4103 * @platform: platform to register
12a48a8c 4104 */
71a45cda
LPC
4105int snd_soc_register_platform(struct device *dev,
4106 const struct snd_soc_platform_driver *platform_drv)
12a48a8c 4107{
f0fba2ad 4108 struct snd_soc_platform *platform;
71a45cda 4109 int ret;
f0fba2ad 4110
71a45cda 4111 dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
f0fba2ad 4112
71a45cda
LPC
4113 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
4114 if (platform == NULL)
4115 return -ENOMEM;
4116
4117 ret = snd_soc_add_platform(dev, platform, platform_drv);
4118 if (ret)
4119 kfree(platform);
4120
4121 return ret;
4122}
4123EXPORT_SYMBOL_GPL(snd_soc_register_platform);
4124
4125/**
4126 * snd_soc_remove_platform - Remove a platform from the ASoC core
4127 * @platform: the platform to remove
4128 */
4129void snd_soc_remove_platform(struct snd_soc_platform *platform)
4130{
12a48a8c
MB
4131 mutex_lock(&client_mutex);
4132 list_del(&platform->list);
4133 mutex_unlock(&client_mutex);
4134
71a45cda
LPC
4135 dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
4136 platform->name);
f0fba2ad 4137 kfree(platform->name);
71a45cda
LPC
4138}
4139EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
4140
4141struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
4142{
4143 struct snd_soc_platform *platform;
4144
4145 list_for_each_entry(platform, &platform_list, list) {
4146 if (dev == platform->dev)
4147 return platform;
4148 }
4149
4150 return NULL;
4151}
4152EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
4153
4154/**
4155 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
4156 *
4157 * @platform: platform to unregister
4158 */
4159void snd_soc_unregister_platform(struct device *dev)
4160{
4161 struct snd_soc_platform *platform;
4162
4163 platform = snd_soc_lookup_platform(dev);
4164 if (!platform)
4165 return;
4166
4167 snd_soc_remove_platform(platform);
f0fba2ad 4168 kfree(platform);
12a48a8c
MB
4169}
4170EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
4171
151ab22c
MB
4172static u64 codec_format_map[] = {
4173 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
4174 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
4175 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
4176 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
4177 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
4178 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
4179 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
4180 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
4181 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
4182 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
4183 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
4184 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
4185 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
4186 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
4187 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
4188 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
4189};
4190
4191/* Fix up the DAI formats for endianness: codecs don't actually see
4192 * the endianness of the data but we're using the CPU format
4193 * definitions which do need to include endianness so we ensure that
4194 * codec DAIs always have both big and little endian variants set.
4195 */
4196static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
4197{
4198 int i;
4199
4200 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
4201 if (stream->formats & codec_format_map[i])
4202 stream->formats |= codec_format_map[i];
4203}
4204
0d0cf00a
MB
4205/**
4206 * snd_soc_register_codec - Register a codec with the ASoC core
4207 *
ac11a2b3 4208 * @codec: codec to register
0d0cf00a 4209 */
f0fba2ad 4210int snd_soc_register_codec(struct device *dev,
001ae4c0
MB
4211 const struct snd_soc_codec_driver *codec_drv,
4212 struct snd_soc_dai_driver *dai_drv,
4213 int num_dai)
0d0cf00a 4214{
3335ddca 4215 size_t reg_size;
f0fba2ad
LG
4216 struct snd_soc_codec *codec;
4217 int ret, i;
151ab22c 4218
f0fba2ad
LG
4219 dev_dbg(dev, "codec register %s\n", dev_name(dev));
4220
4221 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
4222 if (codec == NULL)
4223 return -ENOMEM;
0d0cf00a 4224
f0fba2ad
LG
4225 /* create CODEC component name */
4226 codec->name = fmt_single_name(dev, &codec->id);
4227 if (codec->name == NULL) {
f790b94d
KM
4228 ret = -ENOMEM;
4229 goto fail_codec;
f0fba2ad
LG
4230 }
4231
23bbce34
DP
4232 if (codec_drv->compress_type)
4233 codec->compress_type = codec_drv->compress_type;
4234 else
4235 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
4236
c3acec26
MB
4237 codec->write = codec_drv->write;
4238 codec->read = codec_drv->read;
1500b7b5
DP
4239 codec->volatile_register = codec_drv->volatile_register;
4240 codec->readable_register = codec_drv->readable_register;
8020454c 4241 codec->writable_register = codec_drv->writable_register;
5124e69e 4242 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
ce6120cc
LG
4243 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
4244 codec->dapm.dev = dev;
4245 codec->dapm.codec = codec;
474b62d6 4246 codec->dapm.seq_notifier = codec_drv->seq_notifier;
64a648c2 4247 codec->dapm.stream_event = codec_drv->stream_event;
7a30a3db
DP
4248 codec->dev = dev;
4249 codec->driver = codec_drv;
4250 codec->num_dai = num_dai;
4251 mutex_init(&codec->mutex);
ce6120cc 4252
f0fba2ad
LG
4253 /* allocate CODEC register cache */
4254 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
3335ddca 4255 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
aea170a0 4256 codec->reg_size = reg_size;
3335ddca
DP
4257 /* it is necessary to make a copy of the default register cache
4258 * because in the case of using a compression type that requires
f6e65744 4259 * the default register cache to be marked as the
3335ddca
DP
4260 * kernel might have freed the array by the time we initialize
4261 * the cache.
4262 */
2aa86323
DP
4263 if (codec_drv->reg_cache_default) {
4264 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
4265 reg_size, GFP_KERNEL);
4266 if (!codec->reg_def_copy) {
4267 ret = -ENOMEM;
f790b94d 4268 goto fail_codec_name;
2aa86323 4269 }
f0fba2ad 4270 }
151ab22c
MB
4271 }
4272
1500b7b5
DP
4273 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
4274 if (!codec->volatile_register)
4275 codec->volatile_register = snd_soc_default_volatile_register;
4276 if (!codec->readable_register)
4277 codec->readable_register = snd_soc_default_readable_register;
8020454c
DP
4278 if (!codec->writable_register)
4279 codec->writable_register = snd_soc_default_writable_register;
1500b7b5
DP
4280 }
4281
f0fba2ad
LG
4282 for (i = 0; i < num_dai; i++) {
4283 fixup_codec_formats(&dai_drv[i].playback);
4284 fixup_codec_formats(&dai_drv[i].capture);
4285 }
4286
054880fe
MB
4287 mutex_lock(&client_mutex);
4288 list_add(&codec->list, &codec_list);
4289 mutex_unlock(&client_mutex);
4290
26b01ccd 4291 /* register any DAIs */
5acd7dfb
KM
4292 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4293 if (ret < 0) {
4294 dev_err(codec->dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4295 goto fail_codec_name;
26b01ccd 4296 }
f0fba2ad 4297
f110bfc7 4298 dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name);
0d0cf00a 4299 return 0;
f0fba2ad 4300
f790b94d 4301fail_codec_name:
e1328a83
KM
4302 mutex_lock(&client_mutex);
4303 list_del(&codec->list);
4304 mutex_unlock(&client_mutex);
4305
f0fba2ad 4306 kfree(codec->name);
f790b94d 4307fail_codec:
f0fba2ad
LG
4308 kfree(codec);
4309 return ret;
0d0cf00a
MB
4310}
4311EXPORT_SYMBOL_GPL(snd_soc_register_codec);
4312
4313/**
4314 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4315 *
ac11a2b3 4316 * @codec: codec to unregister
0d0cf00a 4317 */
f0fba2ad 4318void snd_soc_unregister_codec(struct device *dev)
0d0cf00a 4319{
f0fba2ad 4320 struct snd_soc_codec *codec;
f0fba2ad
LG
4321
4322 list_for_each_entry(codec, &codec_list, list) {
4323 if (dev == codec->dev)
4324 goto found;
4325 }
4326 return;
4327
4328found:
5acd7dfb 4329 snd_soc_unregister_dais(dev, codec->num_dai);
f0fba2ad 4330
0d0cf00a
MB
4331 mutex_lock(&client_mutex);
4332 list_del(&codec->list);
4333 mutex_unlock(&client_mutex);
4334
f110bfc7 4335 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
f0fba2ad 4336
7a30a3db 4337 snd_soc_cache_exit(codec);
3335ddca 4338 kfree(codec->reg_def_copy);
1aafcd4d 4339 kfree(codec->name);
f0fba2ad 4340 kfree(codec);
0d0cf00a
MB
4341}
4342EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4343
030e79f6
KM
4344
4345/**
4346 * snd_soc_register_component - Register a component with the ASoC core
4347 *
4348 */
4349int snd_soc_register_component(struct device *dev,
4350 const struct snd_soc_component_driver *cmpnt_drv,
4351 struct snd_soc_dai_driver *dai_drv,
4352 int num_dai)
4353{
4354 struct snd_soc_component *cmpnt;
4355 int ret;
4356
4357 dev_dbg(dev, "component register %s\n", dev_name(dev));
4358
4359 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4360 if (!cmpnt) {
4361 dev_err(dev, "ASoC: Failed to allocate memory\n");
4362 return -ENOMEM;
4363 }
4364
4365 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4366 if (!cmpnt->name) {
4367 dev_err(dev, "ASoC: Failed to simplifying name\n");
4368 return -ENOMEM;
4369 }
4370
4371 cmpnt->dev = dev;
4372 cmpnt->driver = cmpnt_drv;
4373 cmpnt->num_dai = num_dai;
4374
a1422b8c
KM
4375 /*
4376 * snd_soc_register_dai() uses fmt_single_name(), and
4377 * snd_soc_register_dais() uses fmt_multiple_name()
4378 * for dai->name which is used for name based matching
4379 */
4380 if (1 == num_dai)
4381 ret = snd_soc_register_dai(dev, dai_drv);
4382 else
4383 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
030e79f6
KM
4384 if (ret < 0) {
4385 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4386 goto error_component_name;
4387 }
4388
4389 mutex_lock(&client_mutex);
4390 list_add(&cmpnt->list, &component_list);
4391 mutex_unlock(&client_mutex);
4392
4393 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4394
4395 return ret;
4396
4397error_component_name:
4398 kfree(cmpnt->name);
4399
4400 return ret;
4401}
2e1cc199 4402EXPORT_SYMBOL_GPL(snd_soc_register_component);
030e79f6
KM
4403
4404/**
4405 * snd_soc_unregister_component - Unregister a component from the ASoC core
4406 *
4407 */
4408void snd_soc_unregister_component(struct device *dev)
4409{
4410 struct snd_soc_component *cmpnt;
4411
4412 list_for_each_entry(cmpnt, &component_list, list) {
4413 if (dev == cmpnt->dev)
4414 goto found;
4415 }
4416 return;
4417
4418found:
4419 snd_soc_unregister_dais(dev, cmpnt->num_dai);
4420
4421 mutex_lock(&client_mutex);
4422 list_del(&cmpnt->list);
4423 mutex_unlock(&client_mutex);
4424
4425 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4426 kfree(cmpnt->name);
4427}
2e1cc199 4428EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
030e79f6 4429
bec4fa05
SW
4430/* Retrieve a card's name from device tree */
4431int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4432 const char *propname)
4433{
4434 struct device_node *np = card->dev->of_node;
4435 int ret;
4436
4437 ret = of_property_read_string_index(np, propname, 0, &card->name);
4438 /*
4439 * EINVAL means the property does not exist. This is fine providing
4440 * card->name was previously set, which is checked later in
4441 * snd_soc_register_card.
4442 */
4443 if (ret < 0 && ret != -EINVAL) {
4444 dev_err(card->dev,
f110bfc7 4445 "ASoC: Property '%s' could not be read: %d\n",
bec4fa05
SW
4446 propname, ret);
4447 return ret;
4448 }
4449
4450 return 0;
4451}
4452EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4453
a4a54dd5
SW
4454int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4455 const char *propname)
4456{
4457 struct device_node *np = card->dev->of_node;
4458 int num_routes;
4459 struct snd_soc_dapm_route *routes;
4460 int i, ret;
4461
4462 num_routes = of_property_count_strings(np, propname);
c34ce320 4463 if (num_routes < 0 || num_routes & 1) {
10e8aa9a
MM
4464 dev_err(card->dev,
4465 "ASoC: Property '%s' does not exist or its length is not even\n",
4466 propname);
a4a54dd5
SW
4467 return -EINVAL;
4468 }
4469 num_routes /= 2;
4470 if (!num_routes) {
f110bfc7 4471 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
a4a54dd5
SW
4472 propname);
4473 return -EINVAL;
4474 }
4475
4476 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
4477 GFP_KERNEL);
4478 if (!routes) {
4479 dev_err(card->dev,
f110bfc7 4480 "ASoC: Could not allocate DAPM route table\n");
a4a54dd5
SW
4481 return -EINVAL;
4482 }
4483
4484 for (i = 0; i < num_routes; i++) {
4485 ret = of_property_read_string_index(np, propname,
4486 2 * i, &routes[i].sink);
4487 if (ret) {
c871bd0b
MB
4488 dev_err(card->dev,
4489 "ASoC: Property '%s' index %d could not be read: %d\n",
4490 propname, 2 * i, ret);
a4a54dd5
SW
4491 return -EINVAL;
4492 }
4493 ret = of_property_read_string_index(np, propname,
4494 (2 * i) + 1, &routes[i].source);
4495 if (ret) {
4496 dev_err(card->dev,
c871bd0b
MB
4497 "ASoC: Property '%s' index %d could not be read: %d\n",
4498 propname, (2 * i) + 1, ret);
a4a54dd5
SW
4499 return -EINVAL;
4500 }
4501 }
4502
4503 card->num_dapm_routes = num_routes;
4504 card->dapm_routes = routes;
4505
4506 return 0;
4507}
4508EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4509
a7930ed4
KM
4510unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4511 const char *prefix)
4512{
4513 int ret, i;
4514 char prop[128];
4515 unsigned int format = 0;
4516 int bit, frame;
4517 const char *str;
4518 struct {
4519 char *name;
4520 unsigned int val;
4521 } of_fmt_table[] = {
4522 { "i2s", SND_SOC_DAIFMT_I2S },
4523 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
4524 { "left_j", SND_SOC_DAIFMT_LEFT_J },
4525 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
4526 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
4527 { "ac97", SND_SOC_DAIFMT_AC97 },
4528 { "pdm", SND_SOC_DAIFMT_PDM},
4529 { "msb", SND_SOC_DAIFMT_MSB },
4530 { "lsb", SND_SOC_DAIFMT_LSB },
a7930ed4
KM
4531 };
4532
4533 if (!prefix)
4534 prefix = "";
4535
4536 /*
4537 * check "[prefix]format = xxx"
4538 * SND_SOC_DAIFMT_FORMAT_MASK area
4539 */
4540 snprintf(prop, sizeof(prop), "%sformat", prefix);
4541 ret = of_property_read_string(np, prop, &str);
4542 if (ret == 0) {
4543 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
4544 if (strcmp(str, of_fmt_table[i].name) == 0) {
4545 format |= of_fmt_table[i].val;
4546 break;
4547 }
4548 }
4549 }
4550
4551 /*
8c2d6a9f 4552 * check "[prefix]continuous-clock"
a7930ed4
KM
4553 * SND_SOC_DAIFMT_CLOCK_MASK area
4554 */
8c2d6a9f
KM
4555 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
4556 if (of_get_property(np, prop, NULL))
4557 format |= SND_SOC_DAIFMT_CONT;
4558 else
4559 format |= SND_SOC_DAIFMT_GATED;
a7930ed4
KM
4560
4561 /*
4562 * check "[prefix]bitclock-inversion"
4563 * check "[prefix]frame-inversion"
4564 * SND_SOC_DAIFMT_INV_MASK area
4565 */
4566 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
4567 bit = !!of_get_property(np, prop, NULL);
4568
4569 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
4570 frame = !!of_get_property(np, prop, NULL);
4571
4572 switch ((bit << 4) + frame) {
4573 case 0x11:
4574 format |= SND_SOC_DAIFMT_IB_IF;
4575 break;
4576 case 0x10:
4577 format |= SND_SOC_DAIFMT_IB_NF;
4578 break;
4579 case 0x01:
4580 format |= SND_SOC_DAIFMT_NB_IF;
4581 break;
4582 default:
4583 /* SND_SOC_DAIFMT_NB_NF is default */
4584 break;
4585 }
4586
4587 /*
4588 * check "[prefix]bitclock-master"
4589 * check "[prefix]frame-master"
4590 * SND_SOC_DAIFMT_MASTER_MASK area
4591 */
4592 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
4593 bit = !!of_get_property(np, prop, NULL);
4594
4595 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
4596 frame = !!of_get_property(np, prop, NULL);
4597
4598 switch ((bit << 4) + frame) {
4599 case 0x11:
4600 format |= SND_SOC_DAIFMT_CBM_CFM;
4601 break;
4602 case 0x10:
4603 format |= SND_SOC_DAIFMT_CBM_CFS;
4604 break;
4605 case 0x01:
4606 format |= SND_SOC_DAIFMT_CBS_CFM;
4607 break;
4608 default:
4609 format |= SND_SOC_DAIFMT_CBS_CFS;
4610 break;
4611 }
4612
4613 return format;
4614}
4615EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4616
c9b3a40f 4617static int __init snd_soc_init(void)
db2a4165 4618{
384c89e2 4619#ifdef CONFIG_DEBUG_FS
8a9dab1a
MB
4620 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
4621 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
0837fc62 4622 pr_warn("ASoC: Failed to create debugfs directory\n");
8a9dab1a 4623 snd_soc_debugfs_root = NULL;
384c89e2 4624 }
c3c5a19a 4625
8a9dab1a 4626 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
c3c5a19a
MB
4627 &codec_list_fops))
4628 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4629
8a9dab1a 4630 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
f3208780
MB
4631 &dai_list_fops))
4632 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
19c7ac27 4633
8a9dab1a 4634 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
19c7ac27
MB
4635 &platform_list_fops))
4636 pr_warn("ASoC: Failed to create platform list debugfs file\n");
384c89e2
MB
4637#endif
4638
fb257897
MB
4639 snd_soc_util_init();
4640
db2a4165
FM
4641 return platform_driver_register(&soc_driver);
4642}
4abe8e16 4643module_init(snd_soc_init);
db2a4165 4644
7d8c16a6 4645static void __exit snd_soc_exit(void)
db2a4165 4646{
fb257897
MB
4647 snd_soc_util_exit();
4648
384c89e2 4649#ifdef CONFIG_DEBUG_FS
8a9dab1a 4650 debugfs_remove_recursive(snd_soc_debugfs_root);
384c89e2 4651#endif
3ff3f64b 4652 platform_driver_unregister(&soc_driver);
db2a4165 4653}
db2a4165
FM
4654module_exit(snd_soc_exit);
4655
4656/* Module information */
d331124d 4657MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
db2a4165
FM
4658MODULE_DESCRIPTION("ALSA SoC Core");
4659MODULE_LICENSE("GPL");
8b45a209 4660MODULE_ALIAS("platform:soc-audio");
This page took 0.669318 seconds and 5 git commands to generate.