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