blob: 6bad7cd4131e11198f9acfb5e4dc512e2c61a9e2 [file] [log] [blame]
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001/*
2 * soc-core.c -- ALSA SoC Audio Layer
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
Liam Girdwood0664d882006-12-18 14:39:02 +01005 * Copyright 2005 Openedhand Ltd.
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00006 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
Liam Girdwood0664d882006-12-18 14:39:02 +01008 *
Liam Girdwoodd3311242008-10-12 13:17:36 +01009 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood0664d882006-12-18 14:39:02 +010010 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020012 *
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 *
Frank Mandarinodb2a4162006-10-06 18:31:09 +020018 * 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>
Troy Kisky12ef1932008-10-13 17:42:14 -070031#include <linux/debugfs.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020032#include <linux/platform_device.h>
Mark Brownf0e8ed82011-09-20 11:41:54 +010033#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Stephen Warrenbec4fa02011-12-12 15:55:34 -070035#include <linux/of.h>
Marek Vasut474828a2009-07-22 13:01:03 +020036#include <sound/ac97_codec.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020037#include <sound/core.h>
Mark Brown3028eb82010-12-05 12:22:46 +000038#include <sound/jack.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020039#include <sound/pcm.h>
40#include <sound/pcm_params.h>
41#include <sound/soc.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020042#include <sound/initval.h>
43
Mark Browna8b1d342010-11-03 18:05:58 -040044#define CREATE_TRACE_POINTS
45#include <trace/events/asoc.h>
46
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000047#define NAME_SIZE 32
48
Frank Mandarinodb2a4162006-10-06 18:31:09 +020049static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
50
Mark Brown384c89e2008-12-03 17:34:03 +000051#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +000052struct dentry *snd_soc_debugfs_root;
53EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
Mark Brown384c89e2008-12-03 17:34:03 +000054#endif
55
Mark Brownc5af3a22008-11-28 13:29:45 +000056static DEFINE_MUTEX(client_mutex);
57static LIST_HEAD(card_list);
Mark Brown91151712008-11-30 23:31:24 +000058static LIST_HEAD(dai_list);
Mark Brown12a48a8c2008-12-03 19:40:30 +000059static LIST_HEAD(platform_list);
Mark Brown0d0cf002008-12-10 14:32:45 +000060static LIST_HEAD(codec_list);
Mark Brownc5af3a22008-11-28 13:29:45 +000061
Frank Mandarinodb2a4162006-10-06 18:31:09 +020062/*
63 * This is a timeout to do a DAPM powerdown after a stream is closed().
64 * It can be used to eliminate pops between different playback streams, e.g.
65 * between two audio tracks.
66 */
67static int pmdown_time = 5000;
68module_param(pmdown_time, int, 0);
69MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
70
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +000071/* returns the minimum number of bytes needed to represent
72 * a particular given value */
73static int min_bytes_needed(unsigned long val)
74{
75 int c = 0;
76 int i;
77
78 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
79 if (val & (1UL << i))
80 break;
81 c = (sizeof val * 8) - c;
82 if (!c || (c % 8))
83 c = (c + 8) / 8;
84 else
85 c /= 8;
86 return c;
87}
88
Dimitris Papastamos13fd1792011-02-02 13:58:58 +000089/* fill buf which is 'len' bytes with a formatted
90 * string of the form 'reg: value\n' */
91static int format_register_str(struct snd_soc_codec *codec,
92 unsigned int reg, char *buf, size_t len)
Mark Brown2624d5f2009-11-03 21:56:13 +000093{
Stephen Warren00b317a2011-04-01 14:50:44 -060094 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
95 int regsize = codec->driver->reg_word_size * 2;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +000096 int ret;
97 char tmpbuf[len + 1];
98 char regbuf[regsize + 1];
99
100 /* since tmpbuf is allocated on the stack, warn the callers if they
101 * try to abuse this function */
102 WARN_ON(len > 63);
103
104 /* +2 for ': ' and + 1 for '\n' */
105 if (wordsize + regsize + 2 + 1 != len)
106 return -EINVAL;
107
Mark Brown25032c12011-08-01 13:52:48 +0900108 ret = snd_soc_read(codec, reg);
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000109 if (ret < 0) {
110 memset(regbuf, 'X', regsize);
111 regbuf[regsize] = '\0';
112 } else {
113 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
114 }
115
116 /* prepare the buffer */
117 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
118 /* copy it back to the caller without the '\0' */
119 memcpy(buf, tmpbuf, len);
120
121 return 0;
122}
123
124/* codec register dump */
125static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
126 size_t count, loff_t pos)
127{
128 int i, step = 1;
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +0000129 int wordsize, regsize;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000130 int len;
131 size_t total = 0;
132 loff_t p = 0;
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +0000133
Stephen Warren00b317a2011-04-01 14:50:44 -0600134 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
135 regsize = codec->driver->reg_word_size * 2;
Mark Brown2624d5f2009-11-03 21:56:13 +0000136
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000137 len = wordsize + regsize + 2 + 1;
138
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000139 if (!codec->driver->reg_cache_size)
Mark Brown2624d5f2009-11-03 21:56:13 +0000140 return 0;
141
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000142 if (codec->driver->reg_cache_step)
143 step = codec->driver->reg_cache_step;
Mark Brown2624d5f2009-11-03 21:56:13 +0000144
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000145 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
Lars-Peter Clausenb92d1502011-08-27 18:24:14 +0200146 if (!snd_soc_codec_readable_register(codec, i))
Mark Brown2624d5f2009-11-03 21:56:13 +0000147 continue;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000148 if (codec->driver->display_register) {
149 count += codec->driver->display_register(codec, buf + count,
Mark Brown2624d5f2009-11-03 21:56:13 +0000150 PAGE_SIZE - count, i);
Mark Brown5164d742010-07-14 16:14:33 +0100151 } else {
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000152 /* only support larger than PAGE_SIZE bytes debugfs
153 * entries for the default case */
154 if (p >= pos) {
155 if (total + len >= count - 1)
156 break;
157 format_register_str(codec, i, buf + total, len);
158 total += len;
159 }
160 p += len;
Mark Brown5164d742010-07-14 16:14:33 +0100161 }
Mark Brown2624d5f2009-11-03 21:56:13 +0000162 }
163
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000164 total = min(total, count - 1);
Mark Brown2624d5f2009-11-03 21:56:13 +0000165
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000166 return total;
Mark Brown2624d5f2009-11-03 21:56:13 +0000167}
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000168
Mark Brown2624d5f2009-11-03 21:56:13 +0000169static ssize_t codec_reg_show(struct device *dev,
170 struct device_attribute *attr, char *buf)
171{
Mark Brown36ae1a92012-01-06 17:12:45 -0800172 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000173
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000174 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
Mark Brown2624d5f2009-11-03 21:56:13 +0000175}
176
177static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
178
Mark Browndbe21402010-02-12 11:37:24 +0000179static ssize_t pmdown_time_show(struct device *dev,
180 struct device_attribute *attr, char *buf)
181{
Mark Brown36ae1a92012-01-06 17:12:45 -0800182 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Mark Browndbe21402010-02-12 11:37:24 +0000183
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184 return sprintf(buf, "%ld\n", rtd->pmdown_time);
Mark Browndbe21402010-02-12 11:37:24 +0000185}
186
187static ssize_t pmdown_time_set(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
190{
Mark Brown36ae1a92012-01-06 17:12:45 -0800191 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Mark Brownc593b522010-10-27 20:11:17 -0700192 int ret;
Mark Browndbe21402010-02-12 11:37:24 +0000193
Mark Brownc593b522010-10-27 20:11:17 -0700194 ret = strict_strtol(buf, 10, &rtd->pmdown_time);
195 if (ret)
196 return ret;
Mark Browndbe21402010-02-12 11:37:24 +0000197
198 return count;
199}
200
201static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
202
Mark Brown2624d5f2009-11-03 21:56:13 +0000203#ifdef CONFIG_DEBUG_FS
204static int codec_reg_open_file(struct inode *inode, struct file *file)
205{
206 file->private_data = inode->i_private;
207 return 0;
208}
209
210static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000211 size_t count, loff_t *ppos)
Mark Brown2624d5f2009-11-03 21:56:13 +0000212{
213 ssize_t ret;
214 struct snd_soc_codec *codec = file->private_data;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000215 char *buf;
216
217 if (*ppos < 0 || !count)
218 return -EINVAL;
219
220 buf = kmalloc(count, GFP_KERNEL);
Mark Brown2624d5f2009-11-03 21:56:13 +0000221 if (!buf)
222 return -ENOMEM;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000223
224 ret = soc_codec_reg_show(codec, buf, count, *ppos);
225 if (ret >= 0) {
226 if (copy_to_user(user_buf, buf, ret)) {
227 kfree(buf);
228 return -EFAULT;
229 }
230 *ppos += ret;
231 }
232
Mark Brown2624d5f2009-11-03 21:56:13 +0000233 kfree(buf);
234 return ret;
235}
236
237static ssize_t codec_reg_write_file(struct file *file,
238 const char __user *user_buf, size_t count, loff_t *ppos)
239{
240 char buf[32];
Stephen Boyd34e268d2011-05-12 16:50:10 -0700241 size_t buf_size;
Mark Brown2624d5f2009-11-03 21:56:13 +0000242 char *start = buf;
243 unsigned long reg, value;
Mark Brown2624d5f2009-11-03 21:56:13 +0000244 struct snd_soc_codec *codec = file->private_data;
245
246 buf_size = min(count, (sizeof(buf)-1));
247 if (copy_from_user(buf, user_buf, buf_size))
248 return -EFAULT;
249 buf[buf_size] = 0;
250
Mark Brown2624d5f2009-11-03 21:56:13 +0000251 while (*start == ' ')
252 start++;
253 reg = simple_strtoul(start, &start, 16);
Mark Brown2624d5f2009-11-03 21:56:13 +0000254 while (*start == ' ')
255 start++;
256 if (strict_strtoul(start, 16, &value))
257 return -EINVAL;
Mark Brown0d51a9c2011-01-06 16:04:57 +0000258
259 /* Userspace has been fiddling around behind the kernel's back */
260 add_taint(TAINT_USER);
261
Dimitris Papastamose4f078d2010-12-07 16:30:38 +0000262 snd_soc_write(codec, reg, value);
Mark Brown2624d5f2009-11-03 21:56:13 +0000263 return buf_size;
264}
265
266static const struct file_operations codec_reg_fops = {
267 .open = codec_reg_open_file,
268 .read = codec_reg_read_file,
269 .write = codec_reg_write_file,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200270 .llseek = default_llseek,
Mark Brown2624d5f2009-11-03 21:56:13 +0000271};
272
273static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
274{
Jarkko Nikulad6ce4cf2010-11-05 20:35:20 +0200275 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
276
277 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
278 debugfs_card_root);
Mark Brown2624d5f2009-11-03 21:56:13 +0000279 if (!codec->debugfs_codec_root) {
Liam Girdwood64e60f92012-02-15 15:15:37 +0000280 dev_warn(codec->dev, "Failed to create codec debugfs directory\n");
Mark Brown2624d5f2009-11-03 21:56:13 +0000281 return;
282 }
283
Mark Brownaaee8ef2011-01-26 20:53:50 +0000284 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
285 &codec->cache_sync);
286 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
287 &codec->cache_only);
288
Mark Brown2624d5f2009-11-03 21:56:13 +0000289 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
290 codec->debugfs_codec_root,
291 codec, &codec_reg_fops);
292 if (!codec->debugfs_reg)
Liam Girdwood64e60f92012-02-15 15:15:37 +0000293 dev_warn(codec->dev, "Failed to create codec register debugfs file\n");
Mark Brown2624d5f2009-11-03 21:56:13 +0000294
Lars-Peter Clausen8eecaf62011-04-30 19:45:48 +0200295 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
Mark Brown2624d5f2009-11-03 21:56:13 +0000296}
297
298static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
299{
300 debugfs_remove_recursive(codec->debugfs_codec_root);
301}
302
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000303static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
304{
305 struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
306
307 platform->debugfs_platform_root = debugfs_create_dir(platform->name,
308 debugfs_card_root);
309 if (!platform->debugfs_platform_root) {
310 dev_warn(platform->dev,
311 "Failed to create platform debugfs directory\n");
312 return;
313 }
314
315 snd_soc_dapm_debugfs_init(&platform->dapm,
316 platform->debugfs_platform_root);
317}
318
319static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
320{
321 debugfs_remove_recursive(platform->debugfs_platform_root);
322}
323
Mark Brownc3c5a192010-09-15 18:15:14 +0100324static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
325 size_t count, loff_t *ppos)
326{
327 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100328 ssize_t len, ret = 0;
Mark Brownc3c5a192010-09-15 18:15:14 +0100329 struct snd_soc_codec *codec;
330
331 if (!buf)
332 return -ENOMEM;
333
Mark Brown2b194f9d2010-10-13 10:52:16 +0100334 list_for_each_entry(codec, &codec_list, list) {
335 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
336 codec->name);
337 if (len >= 0)
338 ret += len;
339 if (ret > PAGE_SIZE) {
340 ret = PAGE_SIZE;
341 break;
342 }
343 }
Mark Brownc3c5a192010-09-15 18:15:14 +0100344
345 if (ret >= 0)
346 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
347
348 kfree(buf);
349
350 return ret;
351}
352
353static const struct file_operations codec_list_fops = {
354 .read = codec_list_read_file,
355 .llseek = default_llseek,/* read accesses f_pos */
356};
357
Mark Brownf3208782010-09-15 18:19:07 +0100358static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
359 size_t count, loff_t *ppos)
360{
361 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100362 ssize_t len, ret = 0;
Mark Brownf3208782010-09-15 18:19:07 +0100363 struct snd_soc_dai *dai;
364
365 if (!buf)
366 return -ENOMEM;
367
Mark Brown2b194f9d2010-10-13 10:52:16 +0100368 list_for_each_entry(dai, &dai_list, list) {
369 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
370 if (len >= 0)
371 ret += len;
372 if (ret > PAGE_SIZE) {
373 ret = PAGE_SIZE;
374 break;
375 }
376 }
Mark Brownf3208782010-09-15 18:19:07 +0100377
Mark Brown2b194f9d2010-10-13 10:52:16 +0100378 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brownf3208782010-09-15 18:19:07 +0100379
380 kfree(buf);
381
382 return ret;
383}
384
385static const struct file_operations dai_list_fops = {
386 .read = dai_list_read_file,
387 .llseek = default_llseek,/* read accesses f_pos */
388};
389
Mark Brown19c7ac22010-09-15 18:22:40 +0100390static ssize_t platform_list_read_file(struct file *file,
391 char __user *user_buf,
392 size_t count, loff_t *ppos)
393{
394 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100395 ssize_t len, ret = 0;
Mark Brown19c7ac22010-09-15 18:22:40 +0100396 struct snd_soc_platform *platform;
397
398 if (!buf)
399 return -ENOMEM;
400
Mark Brown2b194f9d2010-10-13 10:52:16 +0100401 list_for_each_entry(platform, &platform_list, list) {
402 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
403 platform->name);
404 if (len >= 0)
405 ret += len;
406 if (ret > PAGE_SIZE) {
407 ret = PAGE_SIZE;
408 break;
409 }
410 }
Mark Brown19c7ac22010-09-15 18:22:40 +0100411
Mark Brown2b194f9d2010-10-13 10:52:16 +0100412 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brown19c7ac22010-09-15 18:22:40 +0100413
414 kfree(buf);
415
416 return ret;
417}
418
419static const struct file_operations platform_list_fops = {
420 .read = platform_list_read_file,
421 .llseek = default_llseek,/* read accesses f_pos */
422};
423
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200424static void soc_init_card_debugfs(struct snd_soc_card *card)
425{
426 card->debugfs_card_root = debugfs_create_dir(card->name,
Mark Brown8a9dab12011-01-10 22:25:21 +0000427 snd_soc_debugfs_root);
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200428 if (!card->debugfs_card_root) {
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200429 dev_warn(card->dev,
Lothar Waßmann7c08be82011-12-09 14:16:29 +0100430 "ASoC: Failed to create card debugfs directory\n");
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200431 return;
432 }
433
434 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
435 card->debugfs_card_root,
436 &card->pop_time);
437 if (!card->debugfs_pop_time)
438 dev_warn(card->dev,
439 "Failed to create pop time debugfs file\n");
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200440}
441
442static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
443{
444 debugfs_remove_recursive(card->debugfs_card_root);
445}
446
Mark Brown2624d5f2009-11-03 21:56:13 +0000447#else
448
449static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
450{
451}
452
453static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
454{
455}
Axel Linb95fccb2010-11-09 17:06:44 +0800456
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000457static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
458{
459}
460
461static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
462{
463}
464
Axel Linb95fccb2010-11-09 17:06:44 +0800465static inline void soc_init_card_debugfs(struct snd_soc_card *card)
466{
467}
468
469static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
470{
471}
Mark Brown2624d5f2009-11-03 21:56:13 +0000472#endif
473
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200474#ifdef CONFIG_SND_SOC_AC97_BUS
475/* unregister ac97 codec */
476static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
477{
478 if (codec->ac97->dev.bus)
479 device_unregister(&codec->ac97->dev);
480 return 0;
481}
482
483/* stop no dev release warning */
484static void soc_ac97_device_release(struct device *dev){}
485
486/* register ac97 codec to bus */
487static int soc_ac97_dev_register(struct snd_soc_codec *codec)
488{
489 int err;
490
491 codec->ac97->dev.bus = &ac97_bus_type;
Mark Brown4ac5c612009-04-01 19:35:01 +0100492 codec->ac97->dev.parent = codec->card->dev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200493 codec->ac97->dev.release = soc_ac97_device_release;
494
Kay Sieversbb072bf2008-11-02 03:50:35 +0100495 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000496 codec->card->snd_card->number, 0, codec->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200497 err = device_register(&codec->ac97->dev);
498 if (err < 0) {
499 snd_printk(KERN_ERR "Can't register ac97 bus\n");
500 codec->ac97->dev.bus = NULL;
501 return err;
502 }
503 return 0;
504}
505#endif
506
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000507#ifdef CONFIG_PM_SLEEP
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200508/* powers down audio subsystem for suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000509int snd_soc_suspend(struct device *dev)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200510{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000511 struct snd_soc_card *card = dev_get_drvdata(dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200512 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200513 int i;
514
Daniel Macke3509ff2009-06-03 17:44:49 +0200515 /* If the initialization of this soc device failed, there is no codec
516 * associated with it. Just bail out in this case.
517 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000518 if (list_empty(&card->codec_dev_list))
Daniel Macke3509ff2009-06-03 17:44:49 +0200519 return 0;
520
Andy Green6ed25972008-06-13 16:24:05 +0100521 /* Due to the resume being scheduled into a workqueue we could
522 * suspend before that's finished - wait for it to complete.
523 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000524 snd_power_lock(card->snd_card);
525 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
526 snd_power_unlock(card->snd_card);
Andy Green6ed25972008-06-13 16:24:05 +0100527
528 /* we're going to block userspace touching us until resume completes */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000529 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
Andy Green6ed25972008-06-13 16:24:05 +0100530
Mark Browna00f90f2010-12-02 16:24:24 +0000531 /* mute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000532 for (i = 0; i < card->num_rtd; i++) {
533 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
534 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100535
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000536 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100537 continue;
538
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000539 if (drv->ops->digital_mute && dai->playback_active)
540 drv->ops->digital_mute(dai, 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200541 }
542
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100543 /* suspend all pcms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000544 for (i = 0; i < card->num_rtd; i++) {
545 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100546 continue;
547
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000548 snd_pcm_suspend_all(card->rtd[i].pcm);
Mark Brown3efab7d2010-05-09 13:25:43 +0100549 }
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100550
Mark Brown87506542008-11-18 20:50:34 +0000551 if (card->suspend_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000552 card->suspend_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200553
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000554 for (i = 0; i < card->num_rtd; i++) {
555 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
556 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100557
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000558 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100559 continue;
560
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000561 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
562 cpu_dai->driver->suspend(cpu_dai);
563 if (platform->driver->suspend && !platform->suspended) {
564 platform->driver->suspend(cpu_dai);
565 platform->suspended = 1;
Mark Brown1547aba2010-05-07 21:11:40 +0100566 }
567 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200568
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000569 /* close any waiting streams and save state */
570 for (i = 0; i < card->num_rtd; i++) {
Tejun Heo5b84ba22010-12-11 17:51:26 +0100571 flush_delayed_work_sync(&card->rtd[i].delayed_work);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200572 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000573 }
Mark Brown3efab7d2010-05-09 13:25:43 +0100574
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000575 for (i = 0; i < card->num_rtd; i++) {
576 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
577
578 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100579 continue;
580
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000581 if (driver->playback.stream_name != NULL)
582 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
583 SND_SOC_DAPM_STREAM_SUSPEND);
584
585 if (driver->capture.stream_name != NULL)
586 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
587 SND_SOC_DAPM_STREAM_SUSPEND);
588 }
589
590 /* suspend all CODECs */
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200591 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000592 /* If there are paths active then the CODEC will be held with
593 * bias _ON and should not be suspended. */
594 if (!codec->suspended && codec->driver->suspend) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200595 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000596 case SND_SOC_BIAS_STANDBY:
Mark Brown125a25d2012-01-31 15:49:10 +0000597 /*
598 * If the CODEC is capable of idle
599 * bias off then being in STANDBY
600 * means it's doing something,
601 * otherwise fall through.
602 */
603 if (codec->dapm.idle_bias_off) {
604 dev_dbg(codec->dev,
605 "idle_bias_off CODEC on over suspend\n");
606 break;
607 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000608 case SND_SOC_BIAS_OFF:
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100609 codec->driver->suspend(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000610 codec->suspended = 1;
Mark Brown7be4ba22011-07-18 13:17:13 +0900611 codec->cache_sync = 1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000612 break;
613 default:
614 dev_dbg(codec->dev, "CODEC is on over suspend\n");
615 break;
616 }
617 }
618 }
619
620 for (i = 0; i < card->num_rtd; i++) {
621 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
622
623 if (card->rtd[i].dai_link->ignore_suspend)
624 continue;
625
626 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
627 cpu_dai->driver->suspend(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200628 }
629
Mark Brown87506542008-11-18 20:50:34 +0000630 if (card->suspend_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000631 card->suspend_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200632
633 return 0;
634}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000635EXPORT_SYMBOL_GPL(snd_soc_suspend);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200636
Andy Green6ed25972008-06-13 16:24:05 +0100637/* deferred resume work, so resume can complete before we finished
638 * setting our codec back up, which can be very slow on I2C
639 */
640static void soc_resume_deferred(struct work_struct *work)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200641{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000642 struct snd_soc_card *card =
643 container_of(work, struct snd_soc_card, deferred_resume_work);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200644 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200645 int i;
646
Andy Green6ed25972008-06-13 16:24:05 +0100647 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
648 * so userspace apps are blocked from touching us
649 */
650
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000651 dev_dbg(card->dev, "starting resume work\n");
Andy Green6ed25972008-06-13 16:24:05 +0100652
Mark Brown99497882010-05-07 20:24:05 +0100653 /* Bring us up into D2 so that DAPM starts enabling things */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000654 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
Mark Brown99497882010-05-07 20:24:05 +0100655
Mark Brown87506542008-11-18 20:50:34 +0000656 if (card->resume_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000657 card->resume_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200658
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000659 /* resume AC97 DAIs */
660 for (i = 0; i < card->num_rtd; i++) {
661 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Mark Brown3efab7d2010-05-09 13:25:43 +0100662
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000663 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100664 continue;
665
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000666 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
667 cpu_dai->driver->resume(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200668 }
669
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200670 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000671 /* If the CODEC was idle over suspend then it will have been
672 * left with bias OFF or STANDBY and suspended so we must now
673 * resume. Otherwise the suspend was suppressed.
674 */
675 if (codec->driver->resume && codec->suspended) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200676 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000677 case SND_SOC_BIAS_STANDBY:
678 case SND_SOC_BIAS_OFF:
679 codec->driver->resume(codec);
680 codec->suspended = 0;
681 break;
682 default:
683 dev_dbg(codec->dev, "CODEC was on over suspend\n");
684 break;
685 }
Mark Brown1547aba2010-05-07 21:11:40 +0100686 }
687 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200688
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000689 for (i = 0; i < card->num_rtd; i++) {
690 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100691
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000692 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100693 continue;
694
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000695 if (driver->playback.stream_name != NULL)
696 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200697 SND_SOC_DAPM_STREAM_RESUME);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000698
699 if (driver->capture.stream_name != NULL)
700 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200701 SND_SOC_DAPM_STREAM_RESUME);
702 }
703
Mark Brown3ff3f642008-05-19 12:32:25 +0200704 /* unmute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000705 for (i = 0; i < card->num_rtd; i++) {
706 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
707 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100708
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000709 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100710 continue;
711
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000712 if (drv->ops->digital_mute && dai->playback_active)
713 drv->ops->digital_mute(dai, 0);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200714 }
715
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000716 for (i = 0; i < card->num_rtd; i++) {
717 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
718 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100719
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000720 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100721 continue;
722
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000723 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
724 cpu_dai->driver->resume(cpu_dai);
725 if (platform->driver->resume && platform->suspended) {
726 platform->driver->resume(cpu_dai);
727 platform->suspended = 0;
728 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200729 }
730
Mark Brown87506542008-11-18 20:50:34 +0000731 if (card->resume_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000732 card->resume_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200733
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000734 dev_dbg(card->dev, "resume work completed\n");
Andy Green6ed25972008-06-13 16:24:05 +0100735
736 /* userspace can access us now we are back as we were before */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000737 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
Andy Green6ed25972008-06-13 16:24:05 +0100738}
739
740/* powers up audio subsystem after a suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000741int snd_soc_resume(struct device *dev)
Andy Green6ed25972008-06-13 16:24:05 +0100742{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000743 struct snd_soc_card *card = dev_get_drvdata(dev);
Stephen Warren82e14e82011-05-25 14:06:41 -0600744 int i, ac97_control = 0;
Peter Ujfalusib9dd94a2010-02-22 13:27:13 +0200745
Eric Miao5ff1ddf2011-11-23 22:37:00 +0800746 /* If the initialization of this soc device failed, there is no codec
747 * associated with it. Just bail out in this case.
748 */
749 if (list_empty(&card->codec_dev_list))
750 return 0;
751
Mark Brown64ab9ba2009-03-31 11:27:03 +0100752 /* AC97 devices might have other drivers hanging off them so
753 * need to resume immediately. Other drivers don't have that
754 * problem and may take a substantial amount of time to resume
755 * due to I/O costs and anti-pop so handle them out of line.
756 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000757 for (i = 0; i < card->num_rtd; i++) {
758 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Stephen Warren82e14e82011-05-25 14:06:41 -0600759 ac97_control |= cpu_dai->driver->ac97_control;
760 }
761 if (ac97_control) {
762 dev_dbg(dev, "Resuming AC97 immediately\n");
763 soc_resume_deferred(&card->deferred_resume_work);
764 } else {
765 dev_dbg(dev, "Scheduling resume work\n");
766 if (!schedule_work(&card->deferred_resume_work))
767 dev_err(dev, "resume work item may be lost\n");
Mark Brown64ab9ba2009-03-31 11:27:03 +0100768 }
Andy Green6ed25972008-06-13 16:24:05 +0100769
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200770 return 0;
771}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000772EXPORT_SYMBOL_GPL(snd_soc_resume);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200773#else
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000774#define snd_soc_suspend NULL
775#define snd_soc_resume NULL
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200776#endif
777
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100778static const struct snd_soc_dai_ops null_dai_ops = {
Barry Song02a06d32009-10-16 18:13:38 +0800779};
780
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000781static int soc_bind_dai_link(struct snd_soc_card *card, int num)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200782{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000783 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
784 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
Mark Brownfe3e78e2009-11-03 22:13:13 +0000785 struct snd_soc_codec *codec;
Mark Brown435c5e22008-12-04 15:32:53 +0000786 struct snd_soc_platform *platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000787 struct snd_soc_dai *codec_dai, *cpu_dai;
Mark Brown848dd8b2011-04-27 18:16:32 +0100788 const char *platform_name;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200789
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000790 if (rtd->complete)
791 return 1;
792 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
Mark Brown63084192008-12-02 15:08:03 +0000793
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000794 /* do we already have the CPU DAI for this link ? */
795 if (rtd->cpu_dai) {
796 goto find_codec;
797 }
798 /* no, then find CPU DAI from registered DAIs*/
799 list_for_each_entry(cpu_dai, &dai_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700800 if (dai_link->cpu_dai_of_node) {
801 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
802 continue;
803 } else {
804 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
805 continue;
806 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700807
808 rtd->cpu_dai = cpu_dai;
809 goto find_codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000810 }
811 dev_dbg(card->dev, "CPU DAI %s not registered\n",
812 dai_link->cpu_dai_name);
813
814find_codec:
815 /* do we already have the CODEC for this link ? */
816 if (rtd->codec) {
817 goto find_platform;
Mark Brownc5af3a22008-11-28 13:29:45 +0000818 }
819
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000820 /* no, then find CODEC from registered CODECs*/
821 list_for_each_entry(codec, &codec_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700822 if (dai_link->codec_of_node) {
823 if (codec->dev->of_node != dai_link->codec_of_node)
824 continue;
825 } else {
826 if (strcmp(codec->name, dai_link->codec_name))
827 continue;
828 }
Mark Brown6b05eda2008-12-08 19:26:48 +0000829
Stephen Warren2610ab72011-12-07 13:58:27 -0700830 rtd->codec = codec;
831
832 /*
833 * CODEC found, so find CODEC DAI from registered DAIs from
834 * this CODEC
835 */
836 list_for_each_entry(codec_dai, &dai_list, list) {
837 if (codec->dev == codec_dai->dev &&
838 !strcmp(codec_dai->name,
839 dai_link->codec_dai_name)) {
840
841 rtd->codec_dai = codec_dai;
842 goto find_platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000843 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000844 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700845 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
846 dai_link->codec_dai_name);
847
848 goto find_platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000849 }
850 dev_dbg(card->dev, "CODEC %s not registered\n",
851 dai_link->codec_name);
852
853find_platform:
Mark Brown848dd8b2011-04-27 18:16:32 +0100854 /* do we need a platform? */
855 if (rtd->platform)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000856 goto out;
Mark Brown848dd8b2011-04-27 18:16:32 +0100857
858 /* if there's no platform we match on the empty platform */
859 platform_name = dai_link->platform_name;
Stephen Warren5a504962011-12-21 10:40:59 -0700860 if (!platform_name && !dai_link->platform_of_node)
Mark Brown848dd8b2011-04-27 18:16:32 +0100861 platform_name = "snd-soc-dummy";
862
863 /* no, then find one from the set of registered platforms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000864 list_for_each_entry(platform, &platform_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700865 if (dai_link->platform_of_node) {
866 if (platform->dev->of_node !=
867 dai_link->platform_of_node)
868 continue;
869 } else {
870 if (strcmp(platform->name, platform_name))
871 continue;
872 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700873
874 rtd->platform = platform;
875 goto out;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000876 }
877
878 dev_dbg(card->dev, "platform %s not registered\n",
879 dai_link->platform_name);
880 return 0;
881
882out:
883 /* mark rtd as complete if we found all 4 of our client devices */
884 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
885 rtd->complete = 1;
886 card->num_rtd++;
887 }
888 return 1;
889}
890
Jarkko Nikula589c3562010-12-06 16:27:07 +0200891static void soc_remove_codec(struct snd_soc_codec *codec)
892{
893 int err;
894
895 if (codec->driver->remove) {
896 err = codec->driver->remove(codec);
897 if (err < 0)
898 dev_err(codec->dev,
899 "asoc: failed to remove %s: %d\n",
900 codec->name, err);
901 }
902
903 /* Make sure all DAPM widgets are freed */
904 snd_soc_dapm_free(&codec->dapm);
905
906 soc_cleanup_codec_debugfs(codec);
907 codec->probed = 0;
908 list_del(&codec->card_list);
909 module_put(codec->dev->driver->owner);
910}
911
Liam Girdwood0168bf02011-06-07 16:08:05 +0100912static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000913{
914 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
915 struct snd_soc_codec *codec = rtd->codec;
916 struct snd_soc_platform *platform = rtd->platform;
917 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
918 int err;
919
920 /* unregister the rtd device */
921 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -0800922 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
923 device_remove_file(rtd->dev, &dev_attr_codec_reg);
924 device_unregister(rtd->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000925 rtd->dev_registered = 0;
926 }
927
928 /* remove the CODEC DAI */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100929 if (codec_dai && codec_dai->probed &&
930 codec_dai->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000931 if (codec_dai->driver->remove) {
932 err = codec_dai->driver->remove(codec_dai);
933 if (err < 0)
934 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
935 }
936 codec_dai->probed = 0;
937 list_del(&codec_dai->card_list);
938 }
939
940 /* remove the platform */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100941 if (platform && platform->probed &&
942 platform->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000943 if (platform->driver->remove) {
944 err = platform->driver->remove(platform);
945 if (err < 0)
946 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
947 }
Liam Girdwood675c4962012-01-16 15:25:37 +0000948
949 /* Make sure all DAPM widgets are freed */
950 snd_soc_dapm_free(&platform->dapm);
951
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000952 soc_cleanup_platform_debugfs(platform);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000953 platform->probed = 0;
954 list_del(&platform->card_list);
955 module_put(platform->dev->driver->owner);
956 }
957
958 /* remove the CODEC */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100959 if (codec && codec->probed &&
960 codec->driver->remove_order == order)
Jarkko Nikula589c3562010-12-06 16:27:07 +0200961 soc_remove_codec(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000962
963 /* remove the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100964 if (cpu_dai && cpu_dai->probed &&
965 cpu_dai->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000966 if (cpu_dai->driver->remove) {
967 err = cpu_dai->driver->remove(cpu_dai);
968 if (err < 0)
969 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
970 }
971 cpu_dai->probed = 0;
972 list_del(&cpu_dai->card_list);
973 module_put(cpu_dai->dev->driver->owner);
974 }
975}
976
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900977static void soc_remove_dai_links(struct snd_soc_card *card)
978{
Liam Girdwood0168bf02011-06-07 16:08:05 +0100979 int dai, order;
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900980
Liam Girdwood0168bf02011-06-07 16:08:05 +0100981 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
982 order++) {
983 for (dai = 0; dai < card->num_rtd; dai++)
984 soc_remove_dai_link(card, dai, order);
985 }
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900986 card->num_rtd = 0;
987}
988
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200989static void soc_set_name_prefix(struct snd_soc_card *card,
990 struct snd_soc_codec *codec)
991{
992 int i;
993
Dimitris Papastamosff819b82010-12-02 14:53:03 +0000994 if (card->codec_conf == NULL)
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200995 return;
996
Dimitris Papastamosff819b82010-12-02 14:53:03 +0000997 for (i = 0; i < card->num_configs; i++) {
998 struct snd_soc_codec_conf *map = &card->codec_conf[i];
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200999 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1000 codec->name_prefix = map->name_prefix;
1001 break;
1002 }
1003 }
1004}
1005
Jarkko Nikula589c3562010-12-06 16:27:07 +02001006static int soc_probe_codec(struct snd_soc_card *card,
1007 struct snd_soc_codec *codec)
1008{
1009 int ret = 0;
Mark Brown89b95ac02011-03-07 16:38:44 +00001010 const struct snd_soc_codec_driver *driver = codec->driver;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001011
1012 codec->card = card;
1013 codec->dapm.card = card;
1014 soc_set_name_prefix(card, codec);
1015
Jarkko Nikula70d29332011-01-27 16:24:22 +02001016 if (!try_module_get(codec->dev->driver->owner))
1017 return -ENODEV;
1018
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001019 soc_init_codec_debugfs(codec);
1020
Lars-Peter Clausen77530152011-05-05 16:59:09 +02001021 if (driver->dapm_widgets)
1022 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
1023 driver->num_dapm_widgets);
1024
Mark Brown33c5f962011-08-22 18:40:30 +01001025 codec->dapm.idle_bias_off = driver->idle_bias_off;
1026
Mark Brown89b95ac02011-03-07 16:38:44 +00001027 if (driver->probe) {
1028 ret = driver->probe(codec);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001029 if (ret < 0) {
1030 dev_err(codec->dev,
1031 "asoc: failed to probe CODEC %s: %d\n",
1032 codec->name, ret);
Jarkko Nikula70d29332011-01-27 16:24:22 +02001033 goto err_probe;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001034 }
1035 }
1036
Mark Brownb7af1da2011-04-07 19:18:44 +09001037 if (driver->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001038 snd_soc_add_codec_controls(codec, driver->controls,
Mark Brownb7af1da2011-04-07 19:18:44 +09001039 driver->num_controls);
Mark Brown89b95ac02011-03-07 16:38:44 +00001040 if (driver->dapm_routes)
1041 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1042 driver->num_dapm_routes);
1043
Jarkko Nikula589c3562010-12-06 16:27:07 +02001044 /* mark codec as probed and add to card codec list */
1045 codec->probed = 1;
1046 list_add(&codec->card_list, &card->codec_dev_list);
Jarkko Nikula7be31be82010-12-14 12:18:32 +02001047 list_add(&codec->dapm.list, &card->dapm_list);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001048
Jarkko Nikula70d29332011-01-27 16:24:22 +02001049 return 0;
1050
1051err_probe:
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001052 soc_cleanup_codec_debugfs(codec);
Jarkko Nikula70d29332011-01-27 16:24:22 +02001053 module_put(codec->dev->driver->owner);
1054
Jarkko Nikula589c3562010-12-06 16:27:07 +02001055 return ret;
1056}
1057
Liam Girdwood956245e2011-07-01 16:54:08 +01001058static int soc_probe_platform(struct snd_soc_card *card,
1059 struct snd_soc_platform *platform)
1060{
1061 int ret = 0;
1062 const struct snd_soc_platform_driver *driver = platform->driver;
1063
1064 platform->card = card;
Liam Girdwoodb7950642011-07-04 22:10:52 +01001065 platform->dapm.card = card;
Liam Girdwood956245e2011-07-01 16:54:08 +01001066
1067 if (!try_module_get(platform->dev->driver->owner))
1068 return -ENODEV;
1069
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +00001070 soc_init_platform_debugfs(platform);
1071
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001072 if (driver->dapm_widgets)
1073 snd_soc_dapm_new_controls(&platform->dapm,
1074 driver->dapm_widgets, driver->num_dapm_widgets);
1075
Liam Girdwood956245e2011-07-01 16:54:08 +01001076 if (driver->probe) {
1077 ret = driver->probe(platform);
1078 if (ret < 0) {
1079 dev_err(platform->dev,
1080 "asoc: failed to probe platform %s: %d\n",
1081 platform->name, ret);
1082 goto err_probe;
1083 }
1084 }
1085
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001086 if (driver->controls)
1087 snd_soc_add_platform_controls(platform, driver->controls,
1088 driver->num_controls);
1089 if (driver->dapm_routes)
1090 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1091 driver->num_dapm_routes);
1092
Liam Girdwood956245e2011-07-01 16:54:08 +01001093 /* mark platform as probed and add to card platform list */
1094 platform->probed = 1;
1095 list_add(&platform->card_list, &card->platform_dev_list);
Liam Girdwoodb7950642011-07-04 22:10:52 +01001096 list_add(&platform->dapm.list, &card->dapm_list);
Liam Girdwood956245e2011-07-01 16:54:08 +01001097
1098 return 0;
1099
1100err_probe:
1101 module_put(platform->dev->driver->owner);
1102
1103 return ret;
1104}
1105
Mark Brown36ae1a92012-01-06 17:12:45 -08001106static void rtd_release(struct device *dev)
1107{
1108 kfree(dev);
1109}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001110
Jarkko Nikula589c3562010-12-06 16:27:07 +02001111static int soc_post_component_init(struct snd_soc_card *card,
1112 struct snd_soc_codec *codec,
1113 int num, int dailess)
1114{
1115 struct snd_soc_dai_link *dai_link = NULL;
1116 struct snd_soc_aux_dev *aux_dev = NULL;
1117 struct snd_soc_pcm_runtime *rtd;
1118 const char *temp, *name;
1119 int ret = 0;
1120
1121 if (!dailess) {
1122 dai_link = &card->dai_link[num];
1123 rtd = &card->rtd[num];
1124 name = dai_link->name;
1125 } else {
1126 aux_dev = &card->aux_dev[num];
1127 rtd = &card->rtd_aux[num];
1128 name = aux_dev->name;
1129 }
Janusz Krzysztofik0962bb22011-02-02 21:11:41 +01001130 rtd->card = card;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001131
Mark Brown4b1cfcb2011-10-18 00:11:49 +01001132 /* Make sure all DAPM widgets are instantiated */
1133 snd_soc_dapm_new_widgets(&codec->dapm);
1134
Jarkko Nikula589c3562010-12-06 16:27:07 +02001135 /* machine controls, routes and widgets are not prefixed */
1136 temp = codec->name_prefix;
1137 codec->name_prefix = NULL;
1138
1139 /* do machine specific initialization */
1140 if (!dailess && dai_link->init)
1141 ret = dai_link->init(rtd);
1142 else if (dailess && aux_dev->init)
1143 ret = aux_dev->init(&codec->dapm);
1144 if (ret < 0) {
1145 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1146 return ret;
1147 }
1148 codec->name_prefix = temp;
1149
Jarkko Nikula589c3562010-12-06 16:27:07 +02001150 /* register the rtd device */
1151 rtd->codec = codec;
Mark Brown36ae1a92012-01-06 17:12:45 -08001152
1153 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1154 if (!rtd->dev)
1155 return -ENOMEM;
1156 device_initialize(rtd->dev);
1157 rtd->dev->parent = card->dev;
1158 rtd->dev->release = rtd_release;
1159 rtd->dev->init_name = name;
1160 dev_set_drvdata(rtd->dev, rtd);
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +01001161 mutex_init(&rtd->pcm_mutex);
Mark Brown36ae1a92012-01-06 17:12:45 -08001162 ret = device_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001163 if (ret < 0) {
1164 dev_err(card->dev,
1165 "asoc: failed to register runtime device: %d\n", ret);
1166 return ret;
1167 }
1168 rtd->dev_registered = 1;
1169
1170 /* add DAPM sysfs entries for this codec */
Mark Brown36ae1a92012-01-06 17:12:45 -08001171 ret = snd_soc_dapm_sys_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001172 if (ret < 0)
1173 dev_err(codec->dev,
1174 "asoc: failed to add codec dapm sysfs entries: %d\n",
1175 ret);
1176
1177 /* add codec sysfs entries */
Mark Brown36ae1a92012-01-06 17:12:45 -08001178 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001179 if (ret < 0)
1180 dev_err(codec->dev,
1181 "asoc: failed to add codec sysfs files: %d\n", ret);
1182
1183 return 0;
1184}
1185
Liam Girdwood0168bf02011-06-07 16:08:05 +01001186static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001187{
1188 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1189 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1190 struct snd_soc_codec *codec = rtd->codec;
1191 struct snd_soc_platform *platform = rtd->platform;
1192 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1193 int ret;
1194
Liam Girdwood0168bf02011-06-07 16:08:05 +01001195 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1196 card->name, num, order);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001197
1198 /* config components */
1199 codec_dai->codec = codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001200 cpu_dai->platform = platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001201 codec_dai->card = card;
1202 cpu_dai->card = card;
1203
1204 /* set default power off timeout */
1205 rtd->pmdown_time = pmdown_time;
1206
1207 /* probe the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001208 if (!cpu_dai->probed &&
1209 cpu_dai->driver->probe_order == order) {
Liam Girdwood61b61e32011-05-24 13:57:43 +01001210 if (!try_module_get(cpu_dai->dev->driver->owner))
1211 return -ENODEV;
1212
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001213 if (cpu_dai->driver->probe) {
1214 ret = cpu_dai->driver->probe(cpu_dai);
1215 if (ret < 0) {
1216 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1217 cpu_dai->name);
Liam Girdwood61b61e32011-05-24 13:57:43 +01001218 module_put(cpu_dai->dev->driver->owner);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001219 return ret;
1220 }
1221 }
1222 cpu_dai->probed = 1;
Wolfram Sang1c8371d2011-07-17 18:00:26 +02001223 /* mark cpu_dai as probed and add to card dai list */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001224 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1225 }
1226
1227 /* probe the CODEC */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001228 if (!codec->probed &&
1229 codec->driver->probe_order == order) {
Jarkko Nikula589c3562010-12-06 16:27:07 +02001230 ret = soc_probe_codec(card, codec);
1231 if (ret < 0)
1232 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001233 }
1234
1235 /* probe the platform */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001236 if (!platform->probed &&
1237 platform->driver->probe_order == order) {
Liam Girdwood956245e2011-07-01 16:54:08 +01001238 ret = soc_probe_platform(card, platform);
1239 if (ret < 0)
1240 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001241 }
1242
1243 /* probe the CODEC DAI */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001244 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001245 if (codec_dai->driver->probe) {
1246 ret = codec_dai->driver->probe(codec_dai);
1247 if (ret < 0) {
1248 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1249 codec_dai->name);
1250 return ret;
Mark Brown6b05eda2008-12-08 19:26:48 +00001251 }
1252 }
1253
Wolfram Sang1c8371d2011-07-17 18:00:26 +02001254 /* mark codec_dai as probed and add to card dai list */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001255 codec_dai->probed = 1;
1256 list_add(&codec_dai->card_list, &card->dai_dev_list);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001257 }
1258
Liam Girdwood0168bf02011-06-07 16:08:05 +01001259 /* complete DAI probe during last probe */
1260 if (order != SND_SOC_COMP_ORDER_LAST)
1261 return 0;
1262
Jarkko Nikula589c3562010-12-06 16:27:07 +02001263 ret = soc_post_component_init(card, codec, num, 0);
1264 if (ret)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001265 return ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001266
Mark Brown36ae1a92012-01-06 17:12:45 -08001267 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001268 if (ret < 0)
1269 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1270
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001271 /* create the pcm */
1272 ret = soc_new_pcm(rtd, num);
1273 if (ret < 0) {
1274 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1275 return ret;
1276 }
1277
1278 /* add platform data for AC97 devices */
1279 if (rtd->codec_dai->driver->ac97_control)
1280 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1281
1282 return 0;
1283}
1284
1285#ifdef CONFIG_SND_SOC_AC97_BUS
1286static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1287{
1288 int ret;
1289
1290 /* Only instantiate AC97 if not already done by the adaptor
1291 * for the generic AC97 subsystem.
1292 */
1293 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
Mika Westerberg0562f782010-10-13 11:30:32 +03001294 /*
1295 * It is possible that the AC97 device is already registered to
1296 * the device subsystem. This happens when the device is created
1297 * via snd_ac97_mixer(). Currently only SoC codec that does so
1298 * is the generic AC97 glue but others migh emerge.
1299 *
1300 * In those cases we don't try to register the device again.
1301 */
1302 if (!rtd->codec->ac97_created)
1303 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001304
1305 ret = soc_ac97_dev_register(rtd->codec);
1306 if (ret < 0) {
1307 printk(KERN_ERR "asoc: AC97 device register failed\n");
1308 return ret;
1309 }
1310
1311 rtd->codec->ac97_registered = 1;
1312 }
1313 return 0;
1314}
1315
1316static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1317{
1318 if (codec->ac97_registered) {
1319 soc_ac97_dev_unregister(codec);
1320 codec->ac97_registered = 0;
1321 }
1322}
1323#endif
1324
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001325static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1326{
1327 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001328 struct snd_soc_codec *codec;
Jarkko Nikula676ad982010-12-03 09:18:22 +02001329 int ret = -ENODEV;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001330
1331 /* find CODEC from registered CODECs*/
1332 list_for_each_entry(codec, &codec_list, list) {
1333 if (!strcmp(codec->name, aux_dev->codec_name)) {
1334 if (codec->probed) {
1335 dev_err(codec->dev,
1336 "asoc: codec already probed");
1337 ret = -EBUSY;
1338 goto out;
1339 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001340 goto found;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001341 }
1342 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001343 /* codec not found */
1344 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1345 goto out;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001346
Jarkko Nikula676ad982010-12-03 09:18:22 +02001347found:
Jarkko Nikula589c3562010-12-06 16:27:07 +02001348 ret = soc_probe_codec(card, codec);
1349 if (ret < 0)
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001350 return ret;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001351
Jarkko Nikula589c3562010-12-06 16:27:07 +02001352 ret = soc_post_component_init(card, codec, num, 1);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001353
1354out:
1355 return ret;
1356}
1357
1358static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1359{
1360 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1361 struct snd_soc_codec *codec = rtd->codec;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001362
1363 /* unregister the rtd device */
1364 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -08001365 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1366 device_del(rtd->dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001367 rtd->dev_registered = 0;
1368 }
1369
Jarkko Nikula589c3562010-12-06 16:27:07 +02001370 if (codec && codec->probed)
1371 soc_remove_codec(codec);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001372}
1373
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001374static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1375 enum snd_soc_compress_type compress_type)
1376{
1377 int ret;
1378
1379 if (codec->cache_init)
1380 return 0;
1381
1382 /* override the compress_type if necessary */
1383 if (compress_type && codec->compress_type != compress_type)
1384 codec->compress_type = compress_type;
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001385 ret = snd_soc_cache_init(codec);
1386 if (ret < 0) {
1387 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1388 ret);
1389 return ret;
1390 }
1391 codec->cache_init = 1;
1392 return 0;
1393}
1394
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001395static void snd_soc_instantiate_card(struct snd_soc_card *card)
1396{
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001397 struct snd_soc_codec *codec;
1398 struct snd_soc_codec_conf *codec_conf;
1399 enum snd_soc_compress_type compress_type;
Mark Brown75d9ac42011-09-27 16:41:01 +01001400 struct snd_soc_dai_link *dai_link;
Liam Girdwood0168bf02011-06-07 16:08:05 +01001401 int ret, i, order;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001402
1403 mutex_lock(&card->mutex);
1404
1405 if (card->instantiated) {
1406 mutex_unlock(&card->mutex);
1407 return;
1408 }
1409
1410 /* bind DAIs */
1411 for (i = 0; i < card->num_links; i++)
1412 soc_bind_dai_link(card, i);
1413
1414 /* bind completed ? */
1415 if (card->num_rtd != card->num_links) {
1416 mutex_unlock(&card->mutex);
1417 return;
1418 }
1419
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001420 /* initialize the register cache for each available codec */
1421 list_for_each_entry(codec, &codec_list, list) {
1422 if (codec->cache_init)
1423 continue;
Dimitris Papastamos861f2fa2011-01-11 11:43:51 +00001424 /* by default we don't override the compress_type */
1425 compress_type = 0;
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001426 /* check to see if we need to override the compress_type */
1427 for (i = 0; i < card->num_configs; ++i) {
1428 codec_conf = &card->codec_conf[i];
1429 if (!strcmp(codec->name, codec_conf->dev_name)) {
1430 compress_type = codec_conf->compress_type;
1431 if (compress_type && compress_type
1432 != codec->compress_type)
1433 break;
1434 }
1435 }
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001436 ret = snd_soc_init_codec_cache(codec, compress_type);
1437 if (ret < 0) {
1438 mutex_unlock(&card->mutex);
1439 return;
1440 }
1441 }
1442
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001443 /* card bind complete so register a sound card */
1444 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1445 card->owner, 0, &card->snd_card);
1446 if (ret < 0) {
1447 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1448 card->name);
1449 mutex_unlock(&card->mutex);
1450 return;
1451 }
1452 card->snd_card->dev = card->dev;
1453
Mark Browne37a4972011-03-02 18:21:57 +00001454 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1455 card->dapm.dev = card->dev;
1456 card->dapm.card = card;
1457 list_add(&card->dapm.list, &card->dapm_list);
1458
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001459#ifdef CONFIG_DEBUG_FS
1460 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1461#endif
1462
Mark Brown88ee1c62011-02-02 10:43:26 +00001463#ifdef CONFIG_PM_SLEEP
Andy Green6ed25972008-06-13 16:24:05 +01001464 /* deferred resume work */
Mark Brown63084192008-12-02 15:08:03 +00001465 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
Randy Dunlap1301a962008-06-17 19:19:34 +01001466#endif
Andy Green6ed25972008-06-13 16:24:05 +01001467
Mark Brown9a841eb2011-04-12 17:51:37 -07001468 if (card->dapm_widgets)
1469 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1470 card->num_dapm_widgets);
1471
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001472 /* initialise the sound card only once */
1473 if (card->probe) {
Mark Browne7361ec2011-01-26 14:17:20 +00001474 ret = card->probe(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001475 if (ret < 0)
1476 goto card_probe_error;
1477 }
1478
Liam Girdwood0168bf02011-06-07 16:08:05 +01001479 /* early DAI link probe */
1480 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1481 order++) {
1482 for (i = 0; i < card->num_links; i++) {
1483 ret = soc_probe_dai_link(card, i, order);
1484 if (ret < 0) {
1485 pr_err("asoc: failed to instantiate card %s: %d\n",
Mark Brown321de0d2010-09-21 15:09:37 +01001486 card->name, ret);
Liam Girdwood0168bf02011-06-07 16:08:05 +01001487 goto probe_dai_err;
1488 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001489 }
1490 }
1491
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001492 for (i = 0; i < card->num_aux_devs; i++) {
1493 ret = soc_probe_aux_dev(card, i);
1494 if (ret < 0) {
1495 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1496 card->name, ret);
1497 goto probe_aux_dev_err;
1498 }
1499 }
1500
Mark Brownb7af1da2011-04-07 19:18:44 +09001501 if (card->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001502 snd_soc_add_card_controls(card, card->controls, card->num_controls);
Mark Brownb7af1da2011-04-07 19:18:44 +09001503
Mark Brownb8ad29d2011-03-02 18:35:51 +00001504 if (card->dapm_routes)
1505 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1506 card->num_dapm_routes);
1507
Mark Brownb90d2f92011-10-10 13:38:06 +01001508 snd_soc_dapm_new_widgets(&card->dapm);
1509
Mark Brown75d9ac42011-09-27 16:41:01 +01001510 for (i = 0; i < card->num_links; i++) {
1511 dai_link = &card->dai_link[i];
1512
1513 if (dai_link->dai_fmt) {
1514 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1515 dai_link->dai_fmt);
1516 if (ret != 0)
1517 dev_warn(card->rtd[i].codec_dai->dev,
1518 "Failed to set DAI format: %d\n",
1519 ret);
1520
1521 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1522 dai_link->dai_fmt);
1523 if (ret != 0)
1524 dev_warn(card->rtd[i].cpu_dai->dev,
1525 "Failed to set DAI format: %d\n",
1526 ret);
1527 }
1528 }
1529
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001530 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001531 "%s", card->name);
Liam Girdwood22de71b2011-05-12 16:14:04 +01001532 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1533 "%s", card->long_name ? card->long_name : card->name);
Mark Brownf0e8ed82011-09-20 11:41:54 +01001534 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1535 "%s", card->driver_name ? card->driver_name : card->name);
1536 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1537 switch (card->snd_card->driver[i]) {
1538 case '_':
1539 case '-':
1540 case '\0':
1541 break;
1542 default:
1543 if (!isalnum(card->snd_card->driver[i]))
1544 card->snd_card->driver[i] = '_';
1545 break;
1546 }
1547 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001548
Mark Brown28e9ad92011-03-02 18:36:34 +00001549 if (card->late_probe) {
1550 ret = card->late_probe(card);
1551 if (ret < 0) {
1552 dev_err(card->dev, "%s late_probe() failed: %d\n",
1553 card->name, ret);
1554 goto probe_aux_dev_err;
1555 }
1556 }
1557
Mark Brown2dc00212011-10-08 13:59:44 +01001558 snd_soc_dapm_new_widgets(&card->dapm);
1559
Stephen Warren16332812011-11-23 12:42:04 -07001560 if (card->fully_routed)
Mark Brownb05d8dc2011-11-27 19:38:34 +00001561 list_for_each_entry(codec, &card->codec_dev_list, card_list)
Stephen Warren16332812011-11-23 12:42:04 -07001562 snd_soc_dapm_auto_nc_codec_pins(codec);
1563
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001564 ret = snd_card_register(card->snd_card);
1565 if (ret < 0) {
1566 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
Axel Lin6b3ed782010-12-07 16:12:29 +08001567 goto probe_aux_dev_err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001568 }
1569
1570#ifdef CONFIG_SND_SOC_AC97_BUS
1571 /* register any AC97 codecs */
1572 for (i = 0; i < card->num_rtd; i++) {
Axel Lin6b3ed782010-12-07 16:12:29 +08001573 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1574 if (ret < 0) {
1575 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1576 while (--i >= 0)
Mark Brown7d8316d2010-12-13 17:03:27 +00001577 soc_unregister_ac97_dai_link(card->rtd[i].codec);
Axel Lin6b3ed782010-12-07 16:12:29 +08001578 goto probe_aux_dev_err;
Mark Brownfe3e78e2009-11-03 22:13:13 +00001579 }
Axel Lin6b3ed782010-12-07 16:12:29 +08001580 }
Mark Brownfe3e78e2009-11-03 22:13:13 +00001581#endif
1582
Mark Brown435c5e22008-12-04 15:32:53 +00001583 card->instantiated = 1;
Mark Brown4f4c0072011-10-07 14:29:19 +01001584 snd_soc_dapm_sync(&card->dapm);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001585 mutex_unlock(&card->mutex);
Mark Brown435c5e22008-12-04 15:32:53 +00001586 return;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001587
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001588probe_aux_dev_err:
1589 for (i = 0; i < card->num_aux_devs; i++)
1590 soc_remove_aux_dev(card, i);
1591
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001592probe_dai_err:
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001593 soc_remove_dai_links(card);
Mark Brownfe3e78e2009-11-03 22:13:13 +00001594
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001595card_probe_error:
Mark Brown87506542008-11-18 20:50:34 +00001596 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001597 card->remove(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001598
1599 snd_card_free(card->snd_card);
1600
1601 mutex_unlock(&card->mutex);
Mark Brown435c5e22008-12-04 15:32:53 +00001602}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001603
Mark Brown435c5e22008-12-04 15:32:53 +00001604/*
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001605 * Attempt to initialise any uninitialised cards. Must be called with
Mark Brown435c5e22008-12-04 15:32:53 +00001606 * client_mutex.
1607 */
1608static void snd_soc_instantiate_cards(void)
1609{
1610 struct snd_soc_card *card;
1611 list_for_each_entry(card, &card_list, list)
1612 snd_soc_instantiate_card(card);
1613}
1614
1615/* probes a new socdev */
1616static int soc_probe(struct platform_device *pdev)
1617{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001618 struct snd_soc_card *card = platform_get_drvdata(pdev);
Mark Brown435c5e22008-12-04 15:32:53 +00001619 int ret = 0;
Mark Brown435c5e22008-12-04 15:32:53 +00001620
Vinod Koul70a7ca32011-01-14 19:22:48 +05301621 /*
1622 * no card, so machine driver should be registering card
1623 * we should not be here in that case so ret error
1624 */
1625 if (!card)
1626 return -EINVAL;
1627
Mark Brown435c5e22008-12-04 15:32:53 +00001628 /* Bodge while we unpick instantiation */
1629 card->dev = &pdev->dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001630
Mark Brown435c5e22008-12-04 15:32:53 +00001631 ret = snd_soc_register_card(card);
1632 if (ret != 0) {
1633 dev_err(&pdev->dev, "Failed to register card\n");
1634 return ret;
1635 }
1636
1637 return 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001638}
1639
Vinod Koulb0e26482011-01-13 22:48:02 +05301640static int soc_cleanup_card_resources(struct snd_soc_card *card)
1641{
Vinod Koulb0e26482011-01-13 22:48:02 +05301642 int i;
1643
1644 /* make sure any delayed work runs */
1645 for (i = 0; i < card->num_rtd; i++) {
1646 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1647 flush_delayed_work_sync(&rtd->delayed_work);
1648 }
1649
1650 /* remove auxiliary devices */
1651 for (i = 0; i < card->num_aux_devs; i++)
1652 soc_remove_aux_dev(card, i);
1653
1654 /* remove and free each DAI */
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001655 soc_remove_dai_links(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301656
1657 soc_cleanup_card_debugfs(card);
1658
1659 /* remove the card */
1660 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001661 card->remove(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301662
Lars-Peter Clausen0aaae522011-04-30 19:45:47 +02001663 snd_soc_dapm_free(&card->dapm);
1664
Vinod Koulb0e26482011-01-13 22:48:02 +05301665 kfree(card->rtd);
1666 snd_card_free(card->snd_card);
1667 return 0;
1668
1669}
1670
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001671/* removes a socdev */
1672static int soc_remove(struct platform_device *pdev)
1673{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001674 struct snd_soc_card *card = platform_get_drvdata(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001675
Mark Brownc5af3a22008-11-28 13:29:45 +00001676 snd_soc_unregister_card(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001677 return 0;
1678}
1679
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001680int snd_soc_poweroff(struct device *dev)
Mark Brown51737472009-06-22 13:16:51 +01001681{
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001682 struct snd_soc_card *card = dev_get_drvdata(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001683 int i;
Mark Brown51737472009-06-22 13:16:51 +01001684
1685 if (!card->instantiated)
Mark Brown416356f2009-06-30 19:05:15 +01001686 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001687
1688 /* Flush out pmdown_time work - we actually do want to run it
1689 * now, we're shutting down so no imminent restart. */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001690 for (i = 0; i < card->num_rtd; i++) {
1691 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
Tejun Heo5b84ba22010-12-11 17:51:26 +01001692 flush_delayed_work_sync(&rtd->delayed_work);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001693 }
Mark Brown51737472009-06-22 13:16:51 +01001694
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001695 snd_soc_dapm_shutdown(card);
Mark Brown416356f2009-06-30 19:05:15 +01001696
1697 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001698}
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001699EXPORT_SYMBOL_GPL(snd_soc_poweroff);
Mark Brown51737472009-06-22 13:16:51 +01001700
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001701const struct dev_pm_ops snd_soc_pm_ops = {
Mark Brown5aa44b12012-01-31 15:30:28 +00001702 SET_SYSTEM_SLEEP_PM_OPS(snd_soc_suspend, snd_soc_resume)
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001703 .poweroff = snd_soc_poweroff,
Mark Brown416356f2009-06-30 19:05:15 +01001704};
Stephen Warrendeb26072011-04-05 19:35:30 -06001705EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
Mark Brown416356f2009-06-30 19:05:15 +01001706
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001707/* ASoC platform driver */
1708static struct platform_driver soc_driver = {
1709 .driver = {
1710 .name = "soc-audio",
Kay Sievers8b45a202008-04-14 13:33:36 +02001711 .owner = THIS_MODULE,
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001712 .pm = &snd_soc_pm_ops,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001713 },
1714 .probe = soc_probe,
1715 .remove = soc_remove,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001716};
1717
Mark Brown096e49d2009-07-05 15:12:22 +01001718/**
1719 * snd_soc_codec_volatile_register: Report if a register is volatile.
1720 *
1721 * @codec: CODEC to query.
1722 * @reg: Register to query.
1723 *
1724 * Boolean function indiciating if a CODEC register is volatile.
1725 */
Mark Brown181e0552011-01-24 14:05:25 +00001726int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1727 unsigned int reg)
Mark Brown096e49d2009-07-05 15:12:22 +01001728{
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00001729 if (codec->volatile_register)
1730 return codec->volatile_register(codec, reg);
Mark Brown096e49d2009-07-05 15:12:22 +01001731 else
1732 return 0;
1733}
1734EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1735
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001736/**
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001737 * snd_soc_codec_readable_register: Report if a register is readable.
1738 *
1739 * @codec: CODEC to query.
1740 * @reg: Register to query.
1741 *
1742 * Boolean function indicating if a CODEC register is readable.
1743 */
1744int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1745 unsigned int reg)
1746{
1747 if (codec->readable_register)
1748 return codec->readable_register(codec, reg);
1749 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02001750 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001751}
1752EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1753
1754/**
1755 * snd_soc_codec_writable_register: Report if a register is writable.
1756 *
1757 * @codec: CODEC to query.
1758 * @reg: Register to query.
1759 *
1760 * Boolean function indicating if a CODEC register is writable.
1761 */
1762int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1763 unsigned int reg)
1764{
1765 if (codec->writable_register)
1766 return codec->writable_register(codec, reg);
1767 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02001768 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001769}
1770EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1771
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001772int snd_soc_platform_read(struct snd_soc_platform *platform,
1773 unsigned int reg)
1774{
1775 unsigned int ret;
1776
1777 if (!platform->driver->read) {
1778 dev_err(platform->dev, "platform has no read back\n");
1779 return -1;
1780 }
1781
1782 ret = platform->driver->read(platform, reg);
1783 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01001784 trace_snd_soc_preg_read(platform, reg, ret);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001785
1786 return ret;
1787}
1788EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1789
1790int snd_soc_platform_write(struct snd_soc_platform *platform,
1791 unsigned int reg, unsigned int val)
1792{
1793 if (!platform->driver->write) {
1794 dev_err(platform->dev, "platform has no write back\n");
1795 return -1;
1796 }
1797
1798 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01001799 trace_snd_soc_preg_write(platform, reg, val);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001800 return platform->driver->write(platform, reg, val);
1801}
1802EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1803
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001804/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001805 * snd_soc_new_ac97_codec - initailise AC97 device
1806 * @codec: audio codec
1807 * @ops: AC97 bus operations
1808 * @num: AC97 codec number
1809 *
1810 * Initialises AC97 codec resources for use by ad-hoc devices only.
1811 */
1812int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1813 struct snd_ac97_bus_ops *ops, int num)
1814{
1815 mutex_lock(&codec->mutex);
1816
1817 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1818 if (codec->ac97 == NULL) {
1819 mutex_unlock(&codec->mutex);
1820 return -ENOMEM;
1821 }
1822
1823 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1824 if (codec->ac97->bus == NULL) {
1825 kfree(codec->ac97);
1826 codec->ac97 = NULL;
1827 mutex_unlock(&codec->mutex);
1828 return -ENOMEM;
1829 }
1830
1831 codec->ac97->bus->ops = ops;
1832 codec->ac97->num = num;
Mika Westerberg0562f782010-10-13 11:30:32 +03001833
1834 /*
1835 * Mark the AC97 device to be created by us. This way we ensure that the
1836 * device will be registered with the device subsystem later on.
1837 */
1838 codec->ac97_created = 1;
1839
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001840 mutex_unlock(&codec->mutex);
1841 return 0;
1842}
1843EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1844
1845/**
1846 * snd_soc_free_ac97_codec - free AC97 codec device
1847 * @codec: audio codec
1848 *
1849 * Frees AC97 codec device resources.
1850 */
1851void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1852{
1853 mutex_lock(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001854#ifdef CONFIG_SND_SOC_AC97_BUS
1855 soc_unregister_ac97_dai_link(codec);
1856#endif
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001857 kfree(codec->ac97->bus);
1858 kfree(codec->ac97);
1859 codec->ac97 = NULL;
Mika Westerberg0562f782010-10-13 11:30:32 +03001860 codec->ac97_created = 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001861 mutex_unlock(&codec->mutex);
1862}
1863EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1864
Mark Brownc3753702010-11-01 15:41:57 -04001865unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1866{
1867 unsigned int ret;
1868
Mark Brownc3acec22010-12-02 16:15:29 +00001869 ret = codec->read(codec, reg);
Mark Brownc3753702010-11-01 15:41:57 -04001870 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
Mark Browna8b1d342010-11-03 18:05:58 -04001871 trace_snd_soc_reg_read(codec, reg, ret);
Mark Brownc3753702010-11-01 15:41:57 -04001872
1873 return ret;
1874}
1875EXPORT_SYMBOL_GPL(snd_soc_read);
1876
1877unsigned int snd_soc_write(struct snd_soc_codec *codec,
1878 unsigned int reg, unsigned int val)
1879{
1880 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
Mark Browna8b1d342010-11-03 18:05:58 -04001881 trace_snd_soc_reg_write(codec, reg, val);
Mark Brownc3acec22010-12-02 16:15:29 +00001882 return codec->write(codec, reg, val);
Mark Brownc3753702010-11-01 15:41:57 -04001883}
1884EXPORT_SYMBOL_GPL(snd_soc_write);
1885
Dimitris Papastamos5fb609d2011-03-22 10:37:03 +00001886unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1887 unsigned int reg, const void *data, size_t len)
1888{
1889 return codec->bulk_write_raw(codec, reg, data, len);
1890}
1891EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1892
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001893/**
1894 * snd_soc_update_bits - update codec register bits
1895 * @codec: audio codec
1896 * @reg: codec register
1897 * @mask: register mask
1898 * @value: new value
1899 *
1900 * Writes new register value.
1901 *
Timur Tabi180c3292011-01-10 15:58:13 -06001902 * Returns 1 for change, 0 for no change, or negative error code.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001903 */
1904int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001905 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001906{
Mark Brown8a713da2011-12-03 12:33:55 +00001907 bool change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001908 unsigned int old, new;
Timur Tabi180c3292011-01-10 15:58:13 -06001909 int ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001910
Mark Brown8a713da2011-12-03 12:33:55 +00001911 if (codec->using_regmap) {
1912 ret = regmap_update_bits_check(codec->control_data, reg,
1913 mask, value, &change);
1914 } else {
1915 ret = snd_soc_read(codec, reg);
Timur Tabi180c3292011-01-10 15:58:13 -06001916 if (ret < 0)
1917 return ret;
Mark Brown8a713da2011-12-03 12:33:55 +00001918
1919 old = ret;
1920 new = (old & ~mask) | (value & mask);
1921 change = old != new;
1922 if (change)
1923 ret = snd_soc_write(codec, reg, new);
Timur Tabi180c3292011-01-10 15:58:13 -06001924 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001925
Mark Brown8a713da2011-12-03 12:33:55 +00001926 if (ret < 0)
1927 return ret;
1928
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001929 return change;
1930}
1931EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1932
1933/**
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001934 * snd_soc_update_bits_locked - update codec register bits
1935 * @codec: audio codec
1936 * @reg: codec register
1937 * @mask: register mask
1938 * @value: new value
1939 *
1940 * Writes new register value, and takes the codec mutex.
1941 *
1942 * Returns 1 for change else 0.
1943 */
Mark Browndd1b3d52009-12-04 14:22:03 +00001944int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1945 unsigned short reg, unsigned int mask,
1946 unsigned int value)
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001947{
1948 int change;
1949
1950 mutex_lock(&codec->mutex);
1951 change = snd_soc_update_bits(codec, reg, mask, value);
1952 mutex_unlock(&codec->mutex);
1953
1954 return change;
1955}
Mark Browndd1b3d52009-12-04 14:22:03 +00001956EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001957
1958/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001959 * snd_soc_test_bits - test register for change
1960 * @codec: audio codec
1961 * @reg: codec register
1962 * @mask: register mask
1963 * @value: new value
1964 *
1965 * Tests a register with a new value and checks if the new value is
1966 * different from the old value.
1967 *
1968 * Returns 1 for change else 0.
1969 */
1970int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001971 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001972{
1973 int change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001974 unsigned int old, new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001975
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001976 old = snd_soc_read(codec, reg);
1977 new = (old & ~mask) | value;
1978 change = old != new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001979
1980 return change;
1981}
1982EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1983
1984/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001985 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1986 * @substream: the pcm substream
1987 * @hw: the hardware parameters
1988 *
1989 * Sets the substream runtime hardware parameters.
1990 */
1991int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1992 const struct snd_pcm_hardware *hw)
1993{
1994 struct snd_pcm_runtime *runtime = substream->runtime;
1995 runtime->hw.info = hw->info;
1996 runtime->hw.formats = hw->formats;
1997 runtime->hw.period_bytes_min = hw->period_bytes_min;
1998 runtime->hw.period_bytes_max = hw->period_bytes_max;
1999 runtime->hw.periods_min = hw->periods_min;
2000 runtime->hw.periods_max = hw->periods_max;
2001 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
2002 runtime->hw.fifo_size = hw->fifo_size;
2003 return 0;
2004}
2005EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
2006
2007/**
2008 * snd_soc_cnew - create new control
2009 * @_template: control template
2010 * @data: control private data
Mark Brownac11a2b2009-01-01 12:18:17 +00002011 * @long_name: control long name
Mark Brownefb7ac32011-03-08 17:23:24 +00002012 * @prefix: control name prefix
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002013 *
2014 * Create a new mixer control from a template control.
2015 *
2016 * Returns 0 for success, else error.
2017 */
2018struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
Mark Brownefb7ac32011-03-08 17:23:24 +00002019 void *data, char *long_name,
2020 const char *prefix)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002021{
2022 struct snd_kcontrol_new template;
Mark Brownefb7ac32011-03-08 17:23:24 +00002023 struct snd_kcontrol *kcontrol;
2024 char *name = NULL;
2025 int name_len;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002026
2027 memcpy(&template, _template, sizeof(template));
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002028 template.index = 0;
2029
Mark Brownefb7ac32011-03-08 17:23:24 +00002030 if (!long_name)
2031 long_name = template.name;
2032
2033 if (prefix) {
2034 name_len = strlen(long_name) + strlen(prefix) + 2;
Axel Lin57cf9d42011-08-20 11:03:44 +08002035 name = kmalloc(name_len, GFP_KERNEL);
Mark Brownefb7ac32011-03-08 17:23:24 +00002036 if (!name)
2037 return NULL;
2038
2039 snprintf(name, name_len, "%s %s", prefix, long_name);
2040
2041 template.name = name;
2042 } else {
2043 template.name = long_name;
2044 }
2045
2046 kcontrol = snd_ctl_new1(&template, data);
2047
2048 kfree(name);
2049
2050 return kcontrol;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002051}
2052EXPORT_SYMBOL_GPL(snd_soc_cnew);
2053
Liam Girdwood022658b2012-02-03 17:43:09 +00002054static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2055 const struct snd_kcontrol_new *controls, int num_controls,
2056 const char *prefix, void *data)
2057{
2058 int err, i;
2059
2060 for (i = 0; i < num_controls; i++) {
2061 const struct snd_kcontrol_new *control = &controls[i];
2062 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2063 control->name, prefix));
2064 if (err < 0) {
2065 dev_err(dev, "Failed to add %s: %d\n", control->name, err);
2066 return err;
2067 }
2068 }
2069
2070 return 0;
2071}
2072
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002073/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002074 * snd_soc_add_codec_controls - add an array of controls to a codec.
2075 * Convenience function to add a list of controls. Many codecs were
Ian Molton3e8e1952009-01-09 00:23:21 +00002076 * duplicating this code.
2077 *
2078 * @codec: codec to add controls to
2079 * @controls: array of controls to add
2080 * @num_controls: number of elements in the array
2081 *
2082 * Return 0 for success, else error.
2083 */
Liam Girdwood022658b2012-02-03 17:43:09 +00002084int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
Ian Molton3e8e1952009-01-09 00:23:21 +00002085 const struct snd_kcontrol_new *controls, int num_controls)
2086{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002087 struct snd_card *card = codec->card->snd_card;
Ian Molton3e8e1952009-01-09 00:23:21 +00002088
Liam Girdwood022658b2012-02-03 17:43:09 +00002089 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2090 codec->name_prefix, codec);
Ian Molton3e8e1952009-01-09 00:23:21 +00002091}
Liam Girdwood022658b2012-02-03 17:43:09 +00002092EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
Ian Molton3e8e1952009-01-09 00:23:21 +00002093
2094/**
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002095 * snd_soc_add_platform_controls - add an array of controls to a platform.
Liam Girdwood022658b2012-02-03 17:43:09 +00002096 * Convenience function to add a list of controls.
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002097 *
2098 * @platform: platform to add controls to
2099 * @controls: array of controls to add
2100 * @num_controls: number of elements in the array
2101 *
2102 * Return 0 for success, else error.
2103 */
2104int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2105 const struct snd_kcontrol_new *controls, int num_controls)
2106{
2107 struct snd_card *card = platform->card->snd_card;
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002108
Liam Girdwood022658b2012-02-03 17:43:09 +00002109 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2110 NULL, platform);
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002111}
2112EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2113
2114/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002115 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2116 * Convenience function to add a list of controls.
2117 *
2118 * @soc_card: SoC card to add controls to
2119 * @controls: array of controls to add
2120 * @num_controls: number of elements in the array
2121 *
2122 * Return 0 for success, else error.
2123 */
2124int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2125 const struct snd_kcontrol_new *controls, int num_controls)
2126{
2127 struct snd_card *card = soc_card->snd_card;
2128
2129 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2130 NULL, soc_card);
2131}
2132EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2133
2134/**
2135 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2136 * Convienience function to add a list of controls.
2137 *
2138 * @dai: DAI to add controls to
2139 * @controls: array of controls to add
2140 * @num_controls: number of elements in the array
2141 *
2142 * Return 0 for success, else error.
2143 */
2144int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2145 const struct snd_kcontrol_new *controls, int num_controls)
2146{
2147 struct snd_card *card = dai->card->snd_card;
2148
2149 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2150 NULL, dai);
2151}
2152EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2153
2154/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002155 * snd_soc_info_enum_double - enumerated double mixer info callback
2156 * @kcontrol: mixer control
2157 * @uinfo: control element information
2158 *
2159 * Callback to provide information about a double enumerated
2160 * mixer control.
2161 *
2162 * Returns 0 for success.
2163 */
2164int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2165 struct snd_ctl_elem_info *uinfo)
2166{
2167 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2168
2169 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2170 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002171 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002172
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002173 if (uinfo->value.enumerated.item > e->max - 1)
2174 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002175 strcpy(uinfo->value.enumerated.name,
2176 e->texts[uinfo->value.enumerated.item]);
2177 return 0;
2178}
2179EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2180
2181/**
2182 * snd_soc_get_enum_double - enumerated double mixer get callback
2183 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002184 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002185 *
2186 * Callback to get the value of a double enumerated mixer.
2187 *
2188 * Returns 0 for success.
2189 */
2190int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2191 struct snd_ctl_elem_value *ucontrol)
2192{
2193 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2194 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002195 unsigned int val, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002196
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002197 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002198 ;
2199 val = snd_soc_read(codec, e->reg);
Mark Brown3ff3f642008-05-19 12:32:25 +02002200 ucontrol->value.enumerated.item[0]
2201 = (val >> e->shift_l) & (bitmask - 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002202 if (e->shift_l != e->shift_r)
2203 ucontrol->value.enumerated.item[1] =
2204 (val >> e->shift_r) & (bitmask - 1);
2205
2206 return 0;
2207}
2208EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2209
2210/**
2211 * snd_soc_put_enum_double - enumerated double mixer put callback
2212 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002213 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002214 *
2215 * Callback to set the value of a double enumerated mixer.
2216 *
2217 * Returns 0 for success.
2218 */
2219int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2220 struct snd_ctl_elem_value *ucontrol)
2221{
2222 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2223 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002224 unsigned int val;
2225 unsigned int mask, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002226
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002227 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002228 ;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002229 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002230 return -EINVAL;
2231 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2232 mask = (bitmask - 1) << e->shift_l;
2233 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002234 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002235 return -EINVAL;
2236 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2237 mask |= (bitmask - 1) << e->shift_r;
2238 }
2239
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002240 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002241}
2242EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2243
2244/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002245 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2246 * @kcontrol: mixer control
2247 * @ucontrol: control element information
2248 *
2249 * Callback to get the value of a double semi enumerated mixer.
2250 *
2251 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2252 * used for handling bitfield coded enumeration for example.
2253 *
2254 * Returns 0 for success.
2255 */
2256int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2257 struct snd_ctl_elem_value *ucontrol)
2258{
2259 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02002260 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002261 unsigned int reg_val, val, mux;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002262
2263 reg_val = snd_soc_read(codec, e->reg);
2264 val = (reg_val >> e->shift_l) & e->mask;
2265 for (mux = 0; mux < e->max; mux++) {
2266 if (val == e->values[mux])
2267 break;
2268 }
2269 ucontrol->value.enumerated.item[0] = mux;
2270 if (e->shift_l != e->shift_r) {
2271 val = (reg_val >> e->shift_r) & e->mask;
2272 for (mux = 0; mux < e->max; mux++) {
2273 if (val == e->values[mux])
2274 break;
2275 }
2276 ucontrol->value.enumerated.item[1] = mux;
2277 }
2278
2279 return 0;
2280}
2281EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2282
2283/**
2284 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2285 * @kcontrol: mixer control
2286 * @ucontrol: control element information
2287 *
2288 * Callback to set the value of a double semi enumerated mixer.
2289 *
2290 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2291 * used for handling bitfield coded enumeration for example.
2292 *
2293 * Returns 0 for success.
2294 */
2295int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2296 struct snd_ctl_elem_value *ucontrol)
2297{
2298 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02002299 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002300 unsigned int val;
2301 unsigned int mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002302
2303 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2304 return -EINVAL;
2305 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2306 mask = e->mask << e->shift_l;
2307 if (e->shift_l != e->shift_r) {
2308 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2309 return -EINVAL;
2310 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2311 mask |= e->mask << e->shift_r;
2312 }
2313
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002314 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002315}
2316EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2317
2318/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002319 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2320 * @kcontrol: mixer control
2321 * @uinfo: control element information
2322 *
2323 * Callback to provide information about an external enumerated
2324 * single mixer.
2325 *
2326 * Returns 0 for success.
2327 */
2328int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2329 struct snd_ctl_elem_info *uinfo)
2330{
2331 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2332
2333 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2334 uinfo->count = 1;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002335 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002336
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002337 if (uinfo->value.enumerated.item > e->max - 1)
2338 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002339 strcpy(uinfo->value.enumerated.name,
2340 e->texts[uinfo->value.enumerated.item]);
2341 return 0;
2342}
2343EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2344
2345/**
2346 * snd_soc_info_volsw_ext - external single mixer info callback
2347 * @kcontrol: mixer control
2348 * @uinfo: control element information
2349 *
2350 * Callback to provide information about a single external mixer control.
2351 *
2352 * Returns 0 for success.
2353 */
2354int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2355 struct snd_ctl_elem_info *uinfo)
2356{
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002357 int max = kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002358
Mark Brownfd5dfad2009-04-15 21:37:46 +01002359 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002360 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2361 else
2362 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2363
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002364 uinfo->count = 1;
2365 uinfo->value.integer.min = 0;
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002366 uinfo->value.integer.max = max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002367 return 0;
2368}
2369EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2370
2371/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002372 * snd_soc_info_volsw - single mixer info callback
2373 * @kcontrol: mixer control
2374 * @uinfo: control element information
2375 *
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002376 * Callback to provide information about a single mixer control, or a double
2377 * mixer control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002378 *
2379 * Returns 0 for success.
2380 */
2381int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2382 struct snd_ctl_elem_info *uinfo)
2383{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002384 struct soc_mixer_control *mc =
2385 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002386 int platform_max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002387
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002388 if (!mc->platform_max)
2389 mc->platform_max = mc->max;
2390 platform_max = mc->platform_max;
2391
2392 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002393 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2394 else
2395 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2396
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002397 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002398 uinfo->value.integer.min = 0;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002399 uinfo->value.integer.max = platform_max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002400 return 0;
2401}
2402EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2403
2404/**
2405 * snd_soc_get_volsw - single mixer get callback
2406 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002407 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002408 *
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002409 * Callback to get the value of a single mixer control, or a double mixer
2410 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002411 *
2412 * Returns 0 for success.
2413 */
2414int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2415 struct snd_ctl_elem_value *ucontrol)
2416{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002417 struct soc_mixer_control *mc =
2418 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002419 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002420 unsigned int reg = mc->reg;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002421 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002422 unsigned int shift = mc->shift;
2423 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002424 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002425 unsigned int mask = (1 << fls(max)) - 1;
2426 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002427
2428 ucontrol->value.integer.value[0] =
2429 (snd_soc_read(codec, reg) >> shift) & mask;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002430 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002431 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002432 max - ucontrol->value.integer.value[0];
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002433
2434 if (snd_soc_volsw_is_stereo(mc)) {
2435 if (reg == reg2)
2436 ucontrol->value.integer.value[1] =
2437 (snd_soc_read(codec, reg) >> rshift) & mask;
2438 else
2439 ucontrol->value.integer.value[1] =
2440 (snd_soc_read(codec, reg2) >> shift) & mask;
2441 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002442 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002443 max - ucontrol->value.integer.value[1];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002444 }
2445
2446 return 0;
2447}
2448EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2449
2450/**
2451 * snd_soc_put_volsw - single mixer put callback
2452 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002453 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002454 *
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002455 * Callback to set the value of a single mixer control, or a double mixer
2456 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002457 *
2458 * Returns 0 for success.
2459 */
2460int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2461 struct snd_ctl_elem_value *ucontrol)
2462{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002463 struct soc_mixer_control *mc =
2464 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002465 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002466 unsigned int reg = mc->reg;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002467 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002468 unsigned int shift = mc->shift;
2469 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002470 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002471 unsigned int mask = (1 << fls(max)) - 1;
2472 unsigned int invert = mc->invert;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002473 int err;
2474 bool type_2r = 0;
2475 unsigned int val2 = 0;
2476 unsigned int val, val_mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002477
2478 val = (ucontrol->value.integer.value[0] & mask);
2479 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002480 val = max - val;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002481 val_mask = mask << shift;
2482 val = val << shift;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002483 if (snd_soc_volsw_is_stereo(mc)) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002484 val2 = (ucontrol->value.integer.value[1] & mask);
2485 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002486 val2 = max - val2;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002487 if (reg == reg2) {
2488 val_mask |= mask << rshift;
2489 val |= val2 << rshift;
2490 } else {
2491 val2 = val2 << shift;
2492 type_2r = 1;
2493 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002494 }
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002495 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
Mark Brown3ff3f642008-05-19 12:32:25 +02002496 if (err < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002497 return err;
2498
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002499 if (type_2r)
2500 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2501
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002502 return err;
2503}
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002504EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002505
Mark Browne13ac2e2008-05-28 17:58:05 +01002506/**
2507 * snd_soc_info_volsw_s8 - signed mixer info callback
2508 * @kcontrol: mixer control
2509 * @uinfo: control element information
2510 *
2511 * Callback to provide information about a signed mixer control.
2512 *
2513 * Returns 0 for success.
2514 */
2515int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2516 struct snd_ctl_elem_info *uinfo)
2517{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002518 struct soc_mixer_control *mc =
2519 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002520 int platform_max;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002521 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002522
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002523 if (!mc->platform_max)
2524 mc->platform_max = mc->max;
2525 platform_max = mc->platform_max;
2526
Mark Browne13ac2e2008-05-28 17:58:05 +01002527 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2528 uinfo->count = 2;
2529 uinfo->value.integer.min = 0;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002530 uinfo->value.integer.max = platform_max - min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002531 return 0;
2532}
2533EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2534
2535/**
2536 * snd_soc_get_volsw_s8 - signed mixer get callback
2537 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002538 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002539 *
2540 * Callback to get the value of a signed mixer control.
2541 *
2542 * Returns 0 for success.
2543 */
2544int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2545 struct snd_ctl_elem_value *ucontrol)
2546{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002547 struct soc_mixer_control *mc =
2548 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002549 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002550 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002551 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002552 int val = snd_soc_read(codec, reg);
2553
2554 ucontrol->value.integer.value[0] =
2555 ((signed char)(val & 0xff))-min;
2556 ucontrol->value.integer.value[1] =
2557 ((signed char)((val >> 8) & 0xff))-min;
2558 return 0;
2559}
2560EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2561
2562/**
2563 * snd_soc_put_volsw_sgn - signed mixer put callback
2564 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002565 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002566 *
2567 * Callback to set the value of a signed mixer control.
2568 *
2569 * Returns 0 for success.
2570 */
2571int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2572 struct snd_ctl_elem_value *ucontrol)
2573{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002574 struct soc_mixer_control *mc =
2575 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002576 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002577 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002578 int min = mc->min;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002579 unsigned int val;
Mark Browne13ac2e2008-05-28 17:58:05 +01002580
2581 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2582 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2583
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002584 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
Mark Browne13ac2e2008-05-28 17:58:05 +01002585}
2586EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2587
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002588/**
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002589 * snd_soc_limit_volume - Set new limit to an existing volume control.
2590 *
2591 * @codec: where to look for the control
2592 * @name: Name of the control
2593 * @max: new maximum limit
2594 *
2595 * Return 0 for success, else error.
2596 */
2597int snd_soc_limit_volume(struct snd_soc_codec *codec,
2598 const char *name, int max)
2599{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002600 struct snd_card *card = codec->card->snd_card;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002601 struct snd_kcontrol *kctl;
2602 struct soc_mixer_control *mc;
2603 int found = 0;
2604 int ret = -EINVAL;
2605
2606 /* Sanity check for name and max */
2607 if (unlikely(!name || max <= 0))
2608 return -EINVAL;
2609
2610 list_for_each_entry(kctl, &card->controls, list) {
2611 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2612 found = 1;
2613 break;
2614 }
2615 }
2616 if (found) {
2617 mc = (struct soc_mixer_control *)kctl->private_value;
2618 if (max <= mc->max) {
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002619 mc->platform_max = max;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002620 ret = 0;
2621 }
2622 }
2623 return ret;
2624}
2625EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2626
2627/**
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002628 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2629 * mixer info callback
2630 * @kcontrol: mixer control
2631 * @uinfo: control element information
2632 *
2633 * Returns 0 for success.
2634 */
2635int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_info *uinfo)
2637{
2638 struct soc_mixer_control *mc =
2639 (struct soc_mixer_control *)kcontrol->private_value;
2640 int max = mc->max;
2641 int min = mc->min;
2642
2643 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2644 uinfo->count = 2;
2645 uinfo->value.integer.min = 0;
2646 uinfo->value.integer.max = max-min;
2647
2648 return 0;
2649}
2650EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2651
2652/**
2653 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2654 * mixer get callback
2655 * @kcontrol: mixer control
2656 * @uinfo: control element information
2657 *
2658 * Returns 0 for success.
2659 */
2660int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2661 struct snd_ctl_elem_value *ucontrol)
2662{
2663 struct soc_mixer_control *mc =
2664 (struct soc_mixer_control *)kcontrol->private_value;
2665 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2666 unsigned int mask = (1<<mc->shift)-1;
2667 int min = mc->min;
2668 int val = snd_soc_read(codec, mc->reg) & mask;
2669 int valr = snd_soc_read(codec, mc->rreg) & mask;
2670
Stuart Longland20630c72010-06-18 12:56:10 +10002671 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2672 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002673 return 0;
2674}
2675EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2676
2677/**
2678 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2679 * mixer put callback
2680 * @kcontrol: mixer control
2681 * @uinfo: control element information
2682 *
2683 * Returns 0 for success.
2684 */
2685int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2686 struct snd_ctl_elem_value *ucontrol)
2687{
2688 struct soc_mixer_control *mc =
2689 (struct soc_mixer_control *)kcontrol->private_value;
2690 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2691 unsigned int mask = (1<<mc->shift)-1;
2692 int min = mc->min;
2693 int ret;
2694 unsigned int val, valr, oval, ovalr;
2695
2696 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2697 val &= mask;
2698 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2699 valr &= mask;
2700
2701 oval = snd_soc_read(codec, mc->reg) & mask;
2702 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2703
2704 ret = 0;
2705 if (oval != val) {
2706 ret = snd_soc_write(codec, mc->reg, val);
2707 if (ret < 0)
Mark Brownf1df5ae2010-06-15 15:14:31 +01002708 return ret;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002709 }
2710 if (ovalr != valr) {
2711 ret = snd_soc_write(codec, mc->rreg, valr);
2712 if (ret < 0)
Mark Brownf1df5ae2010-06-15 15:14:31 +01002713 return ret;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002714 }
2715
2716 return 0;
2717}
2718EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2719
2720/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002721 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2722 * @dai: DAI
2723 * @clk_id: DAI specific clock ID
2724 * @freq: new clock frequency in Hz
2725 * @dir: new clock direction - input/output.
2726 *
2727 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2728 */
2729int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2730 unsigned int freq, int dir)
2731{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002732 if (dai->driver && dai->driver->ops->set_sysclk)
2733 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00002734 else if (dai->codec && dai->codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01002735 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
Mark Brownec4ee522011-03-07 20:58:11 +00002736 freq, dir);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002737 else
2738 return -EINVAL;
2739}
2740EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2741
2742/**
Mark Brownec4ee522011-03-07 20:58:11 +00002743 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2744 * @codec: CODEC
2745 * @clk_id: DAI specific clock ID
Mark Brownda1c6ea2011-08-24 20:09:01 +01002746 * @source: Source for the clock
Mark Brownec4ee522011-03-07 20:58:11 +00002747 * @freq: new clock frequency in Hz
2748 * @dir: new clock direction - input/output.
2749 *
2750 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2751 */
2752int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
Mark Brownda1c6ea2011-08-24 20:09:01 +01002753 int source, unsigned int freq, int dir)
Mark Brownec4ee522011-03-07 20:58:11 +00002754{
2755 if (codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01002756 return codec->driver->set_sysclk(codec, clk_id, source,
2757 freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00002758 else
2759 return -EINVAL;
2760}
2761EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2762
2763/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002764 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2765 * @dai: DAI
Mark Brownac11a2b2009-01-01 12:18:17 +00002766 * @div_id: DAI specific clock divider ID
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002767 * @div: new clock divisor.
2768 *
2769 * Configures the clock dividers. This is used to derive the best DAI bit and
2770 * frame clocks from the system or master clock. It's best to set the DAI bit
2771 * and frame clocks as low as possible to save system power.
2772 */
2773int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2774 int div_id, int div)
2775{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002776 if (dai->driver && dai->driver->ops->set_clkdiv)
2777 return dai->driver->ops->set_clkdiv(dai, div_id, div);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002778 else
2779 return -EINVAL;
2780}
2781EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2782
2783/**
2784 * snd_soc_dai_set_pll - configure DAI PLL.
2785 * @dai: DAI
2786 * @pll_id: DAI specific PLL ID
Mark Brown85488032009-09-05 18:52:16 +01002787 * @source: DAI specific source for the PLL
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002788 * @freq_in: PLL input clock frequency in Hz
2789 * @freq_out: requested PLL output clock frequency in Hz
2790 *
2791 * Configures and enables PLL to generate output clock based on input clock.
2792 */
Mark Brown85488032009-09-05 18:52:16 +01002793int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2794 unsigned int freq_in, unsigned int freq_out)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002795{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002796 if (dai->driver && dai->driver->ops->set_pll)
2797 return dai->driver->ops->set_pll(dai, pll_id, source,
Mark Brown85488032009-09-05 18:52:16 +01002798 freq_in, freq_out);
Mark Brownec4ee522011-03-07 20:58:11 +00002799 else if (dai->codec && dai->codec->driver->set_pll)
2800 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2801 freq_in, freq_out);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002802 else
2803 return -EINVAL;
2804}
2805EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2806
Mark Brownec4ee522011-03-07 20:58:11 +00002807/*
2808 * snd_soc_codec_set_pll - configure codec PLL.
2809 * @codec: CODEC
2810 * @pll_id: DAI specific PLL ID
2811 * @source: DAI specific source for the PLL
2812 * @freq_in: PLL input clock frequency in Hz
2813 * @freq_out: requested PLL output clock frequency in Hz
2814 *
2815 * Configures and enables PLL to generate output clock based on input clock.
2816 */
2817int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2818 unsigned int freq_in, unsigned int freq_out)
2819{
2820 if (codec->driver->set_pll)
2821 return codec->driver->set_pll(codec, pll_id, source,
2822 freq_in, freq_out);
2823 else
2824 return -EINVAL;
2825}
2826EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2827
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002828/**
2829 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2830 * @dai: DAI
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002831 * @fmt: SND_SOC_DAIFMT_ format value.
2832 *
2833 * Configures the DAI hardware format and clocking.
2834 */
2835int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2836{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002837 if (dai->driver && dai->driver->ops->set_fmt)
2838 return dai->driver->ops->set_fmt(dai, fmt);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002839 else
2840 return -EINVAL;
2841}
2842EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2843
2844/**
2845 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2846 * @dai: DAI
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002847 * @tx_mask: bitmask representing active TX slots.
2848 * @rx_mask: bitmask representing active RX slots.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002849 * @slots: Number of slots in use.
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002850 * @slot_width: Width in bits for each slot.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002851 *
2852 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2853 * specific.
2854 */
2855int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002856 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002857{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002858 if (dai->driver && dai->driver->ops->set_tdm_slot)
2859 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002860 slots, slot_width);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002861 else
2862 return -EINVAL;
2863}
2864EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2865
2866/**
Barry Song472df3c2009-09-12 01:16:29 +08002867 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2868 * @dai: DAI
2869 * @tx_num: how many TX channels
2870 * @tx_slot: pointer to an array which imply the TX slot number channel
2871 * 0~num-1 uses
2872 * @rx_num: how many RX channels
2873 * @rx_slot: pointer to an array which imply the RX slot number channel
2874 * 0~num-1 uses
2875 *
2876 * configure the relationship between channel number and TDM slot number.
2877 */
2878int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2879 unsigned int tx_num, unsigned int *tx_slot,
2880 unsigned int rx_num, unsigned int *rx_slot)
2881{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002882 if (dai->driver && dai->driver->ops->set_channel_map)
2883 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
Barry Song472df3c2009-09-12 01:16:29 +08002884 rx_num, rx_slot);
2885 else
2886 return -EINVAL;
2887}
2888EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2889
2890/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002891 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2892 * @dai: DAI
2893 * @tristate: tristate enable
2894 *
2895 * Tristates the DAI so that others can use it.
2896 */
2897int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2898{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002899 if (dai->driver && dai->driver->ops->set_tristate)
2900 return dai->driver->ops->set_tristate(dai, tristate);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002901 else
2902 return -EINVAL;
2903}
2904EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2905
2906/**
2907 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2908 * @dai: DAI
2909 * @mute: mute enable
2910 *
2911 * Mutes the DAI DAC.
2912 */
2913int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2914{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002915 if (dai->driver && dai->driver->ops->digital_mute)
2916 return dai->driver->ops->digital_mute(dai, mute);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002917 else
2918 return -EINVAL;
2919}
2920EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2921
Mark Brownc5af3a22008-11-28 13:29:45 +00002922/**
2923 * snd_soc_register_card - Register a card with the ASoC core
2924 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002925 * @card: Card to register
Mark Brownc5af3a22008-11-28 13:29:45 +00002926 *
Mark Brownc5af3a22008-11-28 13:29:45 +00002927 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05302928int snd_soc_register_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00002929{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002930 int i;
2931
Mark Brownc5af3a22008-11-28 13:29:45 +00002932 if (!card->name || !card->dev)
2933 return -EINVAL;
2934
Stephen Warren5a504962011-12-21 10:40:59 -07002935 for (i = 0; i < card->num_links; i++) {
2936 struct snd_soc_dai_link *link = &card->dai_link[i];
2937
2938 /*
2939 * Codec must be specified by 1 of name or OF node,
2940 * not both or neither.
2941 */
2942 if (!!link->codec_name == !!link->codec_of_node) {
2943 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002944 "Neither/both codec name/of_node are set for %s\n",
2945 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002946 return -EINVAL;
2947 }
2948
2949 /*
2950 * Platform may be specified by either name or OF node, but
2951 * can be left unspecified, and a dummy platform will be used.
2952 */
2953 if (link->platform_name && link->platform_of_node) {
2954 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002955 "Both platform name/of_node are set for %s\n", link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002956 return -EINVAL;
2957 }
2958
2959 /*
2960 * CPU DAI must be specified by 1 of name or OF node,
2961 * not both or neither.
2962 */
2963 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2964 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002965 "Neither/both cpu_dai name/of_node are set for %s\n",
2966 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002967 return -EINVAL;
2968 }
2969 }
2970
Mark Browned77cc12011-05-03 18:25:34 +01002971 dev_set_drvdata(card->dev, card);
2972
Stephen Warren111c6412011-01-28 14:26:35 -07002973 snd_soc_initialize_card_lists(card);
2974
Vinod Koul150dd2f2011-01-13 22:48:32 +05302975 soc_init_card_debugfs(card);
2976
Jarkko Nikula2eea3922010-11-25 17:47:38 +02002977 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2978 (card->num_links + card->num_aux_devs),
2979 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002980 if (card->rtd == NULL)
2981 return -ENOMEM;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02002982 card->rtd_aux = &card->rtd[card->num_links];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002983
2984 for (i = 0; i < card->num_links; i++)
2985 card->rtd[i].dai_link = &card->dai_link[i];
2986
Mark Brownc5af3a22008-11-28 13:29:45 +00002987 INIT_LIST_HEAD(&card->list);
Mark Browndb432b42011-10-03 21:06:40 +01002988 INIT_LIST_HEAD(&card->dapm_dirty);
Mark Brownc5af3a22008-11-28 13:29:45 +00002989 card->instantiated = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002990 mutex_init(&card->mutex);
Mark Brownc5af3a22008-11-28 13:29:45 +00002991
2992 mutex_lock(&client_mutex);
2993 list_add(&card->list, &card_list);
Mark Brown435c5e22008-12-04 15:32:53 +00002994 snd_soc_instantiate_cards();
Mark Brownc5af3a22008-11-28 13:29:45 +00002995 mutex_unlock(&client_mutex);
2996
2997 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2998
2999 return 0;
3000}
Vinod Koul70a7ca32011-01-14 19:22:48 +05303001EXPORT_SYMBOL_GPL(snd_soc_register_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003002
3003/**
3004 * snd_soc_unregister_card - Unregister a card with the ASoC core
3005 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003006 * @card: Card to unregister
Mark Brownc5af3a22008-11-28 13:29:45 +00003007 *
Mark Brownc5af3a22008-11-28 13:29:45 +00003008 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05303009int snd_soc_unregister_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00003010{
Vinod Koulb0e26482011-01-13 22:48:02 +05303011 if (card->instantiated)
3012 soc_cleanup_card_resources(card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003013 mutex_lock(&client_mutex);
3014 list_del(&card->list);
3015 mutex_unlock(&client_mutex);
Mark Brownc5af3a22008-11-28 13:29:45 +00003016 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
3017
3018 return 0;
3019}
Vinod Koul70a7ca32011-01-14 19:22:48 +05303020EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003021
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003022/*
3023 * Simplify DAI link configuration by removing ".-1" from device names
3024 * and sanitizing names.
3025 */
Dimitris Papastamos0b9a2142010-12-06 15:49:20 +00003026static char *fmt_single_name(struct device *dev, int *id)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003027{
3028 char *found, name[NAME_SIZE];
3029 int id1, id2;
3030
3031 if (dev_name(dev) == NULL)
3032 return NULL;
3033
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003034 strlcpy(name, dev_name(dev), NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003035
3036 /* are we a "%s.%d" name (platform and SPI components) */
3037 found = strstr(name, dev->driver->name);
3038 if (found) {
3039 /* get ID */
3040 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3041
3042 /* discard ID from name if ID == -1 */
3043 if (*id == -1)
3044 found[strlen(dev->driver->name)] = '\0';
3045 }
3046
3047 } else {
3048 /* I2C component devices are named "bus-addr" */
3049 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3050 char tmp[NAME_SIZE];
3051
3052 /* create unique ID number from I2C addr and bus */
Jarkko Nikula05899442010-10-19 11:10:45 +03003053 *id = ((id1 & 0xffff) << 16) + id2;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003054
3055 /* sanitize component name for DAI link creation */
3056 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003057 strlcpy(name, tmp, NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003058 } else
3059 *id = 0;
3060 }
3061
3062 return kstrdup(name, GFP_KERNEL);
3063}
3064
3065/*
3066 * Simplify DAI link naming for single devices with multiple DAIs by removing
3067 * any ".-1" and using the DAI name (instead of device name).
3068 */
3069static inline char *fmt_multiple_name(struct device *dev,
3070 struct snd_soc_dai_driver *dai_drv)
3071{
3072 if (dai_drv->name == NULL) {
3073 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
3074 dev_name(dev));
3075 return NULL;
3076 }
3077
3078 return kstrdup(dai_drv->name, GFP_KERNEL);
3079}
3080
Mark Brown91151712008-11-30 23:31:24 +00003081/**
3082 * snd_soc_register_dai - Register a DAI with the ASoC core
3083 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003084 * @dai: DAI to register
Mark Brown91151712008-11-30 23:31:24 +00003085 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003086int snd_soc_register_dai(struct device *dev,
3087 struct snd_soc_dai_driver *dai_drv)
Mark Brown91151712008-11-30 23:31:24 +00003088{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003089 struct snd_soc_dai *dai;
Mark Brown91151712008-11-30 23:31:24 +00003090
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003091 dev_dbg(dev, "dai register %s\n", dev_name(dev));
Mark Brown91151712008-11-30 23:31:24 +00003092
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003093 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3094 if (dai == NULL)
Lu Guanquna7393622011-04-20 16:00:51 +08003095 return -ENOMEM;
Eric Miao6335d052009-03-03 09:41:00 +08003096
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003097 /* create DAI component name */
3098 dai->name = fmt_single_name(dev, &dai->id);
3099 if (dai->name == NULL) {
3100 kfree(dai);
3101 return -ENOMEM;
3102 }
3103
3104 dai->dev = dev;
3105 dai->driver = dai_drv;
3106 if (!dai->driver->ops)
3107 dai->driver->ops = &null_dai_ops;
Mark Brown91151712008-11-30 23:31:24 +00003108
3109 mutex_lock(&client_mutex);
3110 list_add(&dai->list, &dai_list);
Mark Brown435c5e22008-12-04 15:32:53 +00003111 snd_soc_instantiate_cards();
Mark Brown91151712008-11-30 23:31:24 +00003112 mutex_unlock(&client_mutex);
3113
3114 pr_debug("Registered DAI '%s'\n", dai->name);
3115
3116 return 0;
3117}
3118EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3119
3120/**
3121 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3122 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003123 * @dai: DAI to unregister
Mark Brown91151712008-11-30 23:31:24 +00003124 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003125void snd_soc_unregister_dai(struct device *dev)
Mark Brown91151712008-11-30 23:31:24 +00003126{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003127 struct snd_soc_dai *dai;
3128
3129 list_for_each_entry(dai, &dai_list, list) {
3130 if (dev == dai->dev)
3131 goto found;
3132 }
3133 return;
3134
3135found:
Mark Brown91151712008-11-30 23:31:24 +00003136 mutex_lock(&client_mutex);
3137 list_del(&dai->list);
3138 mutex_unlock(&client_mutex);
3139
3140 pr_debug("Unregistered DAI '%s'\n", dai->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003141 kfree(dai->name);
3142 kfree(dai);
Mark Brown91151712008-11-30 23:31:24 +00003143}
3144EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3145
3146/**
3147 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3148 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003149 * @dai: Array of DAIs to register
3150 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00003151 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003152int snd_soc_register_dais(struct device *dev,
3153 struct snd_soc_dai_driver *dai_drv, size_t count)
Mark Brown91151712008-11-30 23:31:24 +00003154{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003155 struct snd_soc_dai *dai;
3156 int i, ret = 0;
3157
Liam Girdwood720ffa42010-08-18 00:30:30 +01003158 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
Mark Brown91151712008-11-30 23:31:24 +00003159
3160 for (i = 0; i < count; i++) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003161
3162 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
Axel Linc46e0072010-11-03 15:04:45 +08003163 if (dai == NULL) {
3164 ret = -ENOMEM;
3165 goto err;
3166 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003167
3168 /* create DAI component name */
3169 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3170 if (dai->name == NULL) {
3171 kfree(dai);
3172 ret = -EINVAL;
Mark Brown91151712008-11-30 23:31:24 +00003173 goto err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003174 }
3175
3176 dai->dev = dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003177 dai->driver = &dai_drv[i];
Mark Brown0f9141c2010-10-12 15:43:21 +01003178 if (dai->driver->id)
3179 dai->id = dai->driver->id;
3180 else
3181 dai->id = i;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003182 if (!dai->driver->ops)
3183 dai->driver->ops = &null_dai_ops;
3184
3185 mutex_lock(&client_mutex);
3186 list_add(&dai->list, &dai_list);
3187 mutex_unlock(&client_mutex);
3188
3189 pr_debug("Registered DAI '%s'\n", dai->name);
Mark Brown91151712008-11-30 23:31:24 +00003190 }
3191
Axel Lin1dcb4f32010-12-06 16:48:03 +08003192 mutex_lock(&client_mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003193 snd_soc_instantiate_cards();
Axel Lin1dcb4f32010-12-06 16:48:03 +08003194 mutex_unlock(&client_mutex);
Mark Brown91151712008-11-30 23:31:24 +00003195 return 0;
3196
3197err:
3198 for (i--; i >= 0; i--)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003199 snd_soc_unregister_dai(dev);
Mark Brown91151712008-11-30 23:31:24 +00003200
3201 return ret;
3202}
3203EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3204
3205/**
3206 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3207 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003208 * @dai: Array of DAIs to unregister
3209 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00003210 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003211void snd_soc_unregister_dais(struct device *dev, size_t count)
Mark Brown91151712008-11-30 23:31:24 +00003212{
3213 int i;
3214
3215 for (i = 0; i < count; i++)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003216 snd_soc_unregister_dai(dev);
Mark Brown91151712008-11-30 23:31:24 +00003217}
3218EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3219
Mark Brown12a48a8c2008-12-03 19:40:30 +00003220/**
3221 * snd_soc_register_platform - Register a platform with the ASoC core
3222 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003223 * @platform: platform to register
Mark Brown12a48a8c2008-12-03 19:40:30 +00003224 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003225int snd_soc_register_platform(struct device *dev,
3226 struct snd_soc_platform_driver *platform_drv)
Mark Brown12a48a8c2008-12-03 19:40:30 +00003227{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003228 struct snd_soc_platform *platform;
Mark Brown12a48a8c2008-12-03 19:40:30 +00003229
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003230 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3231
3232 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3233 if (platform == NULL)
Lu Guanquna7393622011-04-20 16:00:51 +08003234 return -ENOMEM;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003235
3236 /* create platform component name */
3237 platform->name = fmt_single_name(dev, &platform->id);
3238 if (platform->name == NULL) {
3239 kfree(platform);
3240 return -ENOMEM;
3241 }
3242
3243 platform->dev = dev;
3244 platform->driver = platform_drv;
Liam Girdwoodb7950642011-07-04 22:10:52 +01003245 platform->dapm.dev = dev;
3246 platform->dapm.platform = platform;
Liam Girdwood64a648c2011-07-25 11:15:15 +01003247 platform->dapm.stream_event = platform_drv->stream_event;
Mark Brown12a48a8c2008-12-03 19:40:30 +00003248
3249 mutex_lock(&client_mutex);
3250 list_add(&platform->list, &platform_list);
Mark Brown435c5e22008-12-04 15:32:53 +00003251 snd_soc_instantiate_cards();
Mark Brown12a48a8c2008-12-03 19:40:30 +00003252 mutex_unlock(&client_mutex);
3253
3254 pr_debug("Registered platform '%s'\n", platform->name);
3255
3256 return 0;
3257}
3258EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3259
3260/**
3261 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3262 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003263 * @platform: platform to unregister
Mark Brown12a48a8c2008-12-03 19:40:30 +00003264 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003265void snd_soc_unregister_platform(struct device *dev)
Mark Brown12a48a8c2008-12-03 19:40:30 +00003266{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003267 struct snd_soc_platform *platform;
3268
3269 list_for_each_entry(platform, &platform_list, list) {
3270 if (dev == platform->dev)
3271 goto found;
3272 }
3273 return;
3274
3275found:
Mark Brown12a48a8c2008-12-03 19:40:30 +00003276 mutex_lock(&client_mutex);
3277 list_del(&platform->list);
3278 mutex_unlock(&client_mutex);
3279
3280 pr_debug("Unregistered platform '%s'\n", platform->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003281 kfree(platform->name);
3282 kfree(platform);
Mark Brown12a48a8c2008-12-03 19:40:30 +00003283}
3284EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3285
Mark Brown151ab222009-05-09 16:22:58 +01003286static u64 codec_format_map[] = {
3287 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3288 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3289 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3290 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3291 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3292 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3293 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3294 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3295 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3296 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3297 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3298 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3299 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3300 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3301 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3302 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3303};
3304
3305/* Fix up the DAI formats for endianness: codecs don't actually see
3306 * the endianness of the data but we're using the CPU format
3307 * definitions which do need to include endianness so we ensure that
3308 * codec DAIs always have both big and little endian variants set.
3309 */
3310static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3311{
3312 int i;
3313
3314 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3315 if (stream->formats & codec_format_map[i])
3316 stream->formats |= codec_format_map[i];
3317}
3318
Mark Brown0d0cf002008-12-10 14:32:45 +00003319/**
3320 * snd_soc_register_codec - Register a codec with the ASoC core
3321 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003322 * @codec: codec to register
Mark Brown0d0cf002008-12-10 14:32:45 +00003323 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003324int snd_soc_register_codec(struct device *dev,
Mark Brown001ae4c2010-12-02 16:21:08 +00003325 const struct snd_soc_codec_driver *codec_drv,
3326 struct snd_soc_dai_driver *dai_drv,
3327 int num_dai)
Mark Brown0d0cf002008-12-10 14:32:45 +00003328{
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003329 size_t reg_size;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003330 struct snd_soc_codec *codec;
3331 int ret, i;
Mark Brown151ab222009-05-09 16:22:58 +01003332
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003333 dev_dbg(dev, "codec register %s\n", dev_name(dev));
Mark Brown0d0cf002008-12-10 14:32:45 +00003334
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003335 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3336 if (codec == NULL)
3337 return -ENOMEM;
Mark Brown0d0cf002008-12-10 14:32:45 +00003338
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003339 /* create CODEC component name */
3340 codec->name = fmt_single_name(dev, &codec->id);
3341 if (codec->name == NULL) {
3342 kfree(codec);
3343 return -ENOMEM;
Mark Brown151ab222009-05-09 16:22:58 +01003344 }
3345
Dimitris Papastamos23bbce32010-12-02 14:53:01 +00003346 if (codec_drv->compress_type)
3347 codec->compress_type = codec_drv->compress_type;
3348 else
3349 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3350
Mark Brownc3acec22010-12-02 16:15:29 +00003351 codec->write = codec_drv->write;
3352 codec->read = codec_drv->read;
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003353 codec->volatile_register = codec_drv->volatile_register;
3354 codec->readable_register = codec_drv->readable_register;
Dimitris Papastamos80204542011-03-24 13:45:17 +00003355 codec->writable_register = codec_drv->writable_register;
Mark Brown5124e692012-02-08 13:20:50 +00003356 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003357 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3358 codec->dapm.dev = dev;
3359 codec->dapm.codec = codec;
Mark Brown474b62d2011-01-18 16:14:44 +00003360 codec->dapm.seq_notifier = codec_drv->seq_notifier;
Liam Girdwood64a648c2011-07-25 11:15:15 +01003361 codec->dapm.stream_event = codec_drv->stream_event;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003362 codec->dev = dev;
3363 codec->driver = codec_drv;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003364 codec->num_dai = num_dai;
3365 mutex_init(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003366
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003367 /* allocate CODEC register cache */
3368 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003369 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
Dimitris Papastamosaea170a2011-01-12 10:38:58 +00003370 codec->reg_size = reg_size;
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003371 /* it is necessary to make a copy of the default register cache
3372 * because in the case of using a compression type that requires
3373 * the default register cache to be marked as __devinitconst the
3374 * kernel might have freed the array by the time we initialize
3375 * the cache.
3376 */
Dimitris Papastamos2aa86322011-01-10 10:10:56 +00003377 if (codec_drv->reg_cache_default) {
3378 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3379 reg_size, GFP_KERNEL);
3380 if (!codec->reg_def_copy) {
3381 ret = -ENOMEM;
3382 goto fail;
3383 }
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003384 }
3385 }
3386
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003387 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3388 if (!codec->volatile_register)
3389 codec->volatile_register = snd_soc_default_volatile_register;
3390 if (!codec->readable_register)
3391 codec->readable_register = snd_soc_default_readable_register;
Dimitris Papastamos80204542011-03-24 13:45:17 +00003392 if (!codec->writable_register)
3393 codec->writable_register = snd_soc_default_writable_register;
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003394 }
3395
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003396 for (i = 0; i < num_dai; i++) {
3397 fixup_codec_formats(&dai_drv[i].playback);
3398 fixup_codec_formats(&dai_drv[i].capture);
3399 }
3400
Mark Brown26b01cc2010-08-18 20:20:55 +01003401 /* register any DAIs */
3402 if (num_dai) {
3403 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3404 if (ret < 0)
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00003405 goto fail;
Mark Brown26b01cc2010-08-18 20:20:55 +01003406 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003407
Mark Brown0d0cf002008-12-10 14:32:45 +00003408 mutex_lock(&client_mutex);
3409 list_add(&codec->list, &codec_list);
3410 snd_soc_instantiate_cards();
3411 mutex_unlock(&client_mutex);
3412
3413 pr_debug("Registered codec '%s'\n", codec->name);
Mark Brown0d0cf002008-12-10 14:32:45 +00003414 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003415
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00003416fail:
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003417 kfree(codec->reg_def_copy);
3418 codec->reg_def_copy = NULL;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003419 kfree(codec->name);
3420 kfree(codec);
3421 return ret;
Mark Brown0d0cf002008-12-10 14:32:45 +00003422}
3423EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3424
3425/**
3426 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3427 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003428 * @codec: codec to unregister
Mark Brown0d0cf002008-12-10 14:32:45 +00003429 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003430void snd_soc_unregister_codec(struct device *dev)
Mark Brown0d0cf002008-12-10 14:32:45 +00003431{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003432 struct snd_soc_codec *codec;
3433 int i;
3434
3435 list_for_each_entry(codec, &codec_list, list) {
3436 if (dev == codec->dev)
3437 goto found;
3438 }
3439 return;
3440
3441found:
Mark Brown26b01cc2010-08-18 20:20:55 +01003442 if (codec->num_dai)
3443 for (i = 0; i < codec->num_dai; i++)
3444 snd_soc_unregister_dai(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003445
Mark Brown0d0cf002008-12-10 14:32:45 +00003446 mutex_lock(&client_mutex);
3447 list_del(&codec->list);
3448 mutex_unlock(&client_mutex);
3449
3450 pr_debug("Unregistered codec '%s'\n", codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003451
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003452 snd_soc_cache_exit(codec);
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003453 kfree(codec->reg_def_copy);
Dimitris Papastamos1aafcd42010-10-21 13:19:45 +01003454 kfree(codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003455 kfree(codec);
Mark Brown0d0cf002008-12-10 14:32:45 +00003456}
3457EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3458
Stephen Warrenbec4fa02011-12-12 15:55:34 -07003459/* Retrieve a card's name from device tree */
3460int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3461 const char *propname)
3462{
3463 struct device_node *np = card->dev->of_node;
3464 int ret;
3465
3466 ret = of_property_read_string_index(np, propname, 0, &card->name);
3467 /*
3468 * EINVAL means the property does not exist. This is fine providing
3469 * card->name was previously set, which is checked later in
3470 * snd_soc_register_card.
3471 */
3472 if (ret < 0 && ret != -EINVAL) {
3473 dev_err(card->dev,
3474 "Property '%s' could not be read: %d\n",
3475 propname, ret);
3476 return ret;
3477 }
3478
3479 return 0;
3480}
3481EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3482
Stephen Warrena4a54dd2011-12-12 15:55:35 -07003483int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3484 const char *propname)
3485{
3486 struct device_node *np = card->dev->of_node;
3487 int num_routes;
3488 struct snd_soc_dapm_route *routes;
3489 int i, ret;
3490
3491 num_routes = of_property_count_strings(np, propname);
3492 if (num_routes & 1) {
3493 dev_err(card->dev,
3494 "Property '%s's length is not even\n",
3495 propname);
3496 return -EINVAL;
3497 }
3498 num_routes /= 2;
3499 if (!num_routes) {
3500 dev_err(card->dev,
3501 "Property '%s's length is zero\n",
3502 propname);
3503 return -EINVAL;
3504 }
3505
3506 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3507 GFP_KERNEL);
3508 if (!routes) {
3509 dev_err(card->dev,
3510 "Could not allocate DAPM route table\n");
3511 return -EINVAL;
3512 }
3513
3514 for (i = 0; i < num_routes; i++) {
3515 ret = of_property_read_string_index(np, propname,
3516 2 * i, &routes[i].sink);
3517 if (ret) {
3518 dev_err(card->dev,
3519 "Property '%s' index %d could not be read: %d\n",
3520 propname, 2 * i, ret);
3521 return -EINVAL;
3522 }
3523 ret = of_property_read_string_index(np, propname,
3524 (2 * i) + 1, &routes[i].source);
3525 if (ret) {
3526 dev_err(card->dev,
3527 "Property '%s' index %d could not be read: %d\n",
3528 propname, (2 * i) + 1, ret);
3529 return -EINVAL;
3530 }
3531 }
3532
3533 card->num_dapm_routes = num_routes;
3534 card->dapm_routes = routes;
3535
3536 return 0;
3537}
3538EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3539
Takashi Iwaic9b3a402008-12-10 07:47:22 +01003540static int __init snd_soc_init(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003541{
Mark Brown384c89e2008-12-03 17:34:03 +00003542#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00003543 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3544 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
Mark Brown384c89e2008-12-03 17:34:03 +00003545 printk(KERN_WARNING
3546 "ASoC: Failed to create debugfs directory\n");
Mark Brown8a9dab12011-01-10 22:25:21 +00003547 snd_soc_debugfs_root = NULL;
Mark Brown384c89e2008-12-03 17:34:03 +00003548 }
Mark Brownc3c5a192010-09-15 18:15:14 +01003549
Mark Brown8a9dab12011-01-10 22:25:21 +00003550 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
Mark Brownc3c5a192010-09-15 18:15:14 +01003551 &codec_list_fops))
3552 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3553
Mark Brown8a9dab12011-01-10 22:25:21 +00003554 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
Mark Brownf3208782010-09-15 18:19:07 +01003555 &dai_list_fops))
3556 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
Mark Brown19c7ac22010-09-15 18:22:40 +01003557
Mark Brown8a9dab12011-01-10 22:25:21 +00003558 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
Mark Brown19c7ac22010-09-15 18:22:40 +01003559 &platform_list_fops))
3560 pr_warn("ASoC: Failed to create platform list debugfs file\n");
Mark Brown384c89e2008-12-03 17:34:03 +00003561#endif
3562
Mark Brownfb257892011-04-28 10:57:54 +01003563 snd_soc_util_init();
3564
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003565 return platform_driver_register(&soc_driver);
3566}
Mark Brown4abe8e12010-10-12 17:41:03 +01003567module_init(snd_soc_init);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003568
Mark Brown7d8c16a2008-11-30 22:11:24 +00003569static void __exit snd_soc_exit(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003570{
Mark Brownfb257892011-04-28 10:57:54 +01003571 snd_soc_util_exit();
3572
Mark Brown384c89e2008-12-03 17:34:03 +00003573#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00003574 debugfs_remove_recursive(snd_soc_debugfs_root);
Mark Brown384c89e2008-12-03 17:34:03 +00003575#endif
Mark Brown3ff3f642008-05-19 12:32:25 +02003576 platform_driver_unregister(&soc_driver);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003577}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003578module_exit(snd_soc_exit);
3579
3580/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01003581MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003582MODULE_DESCRIPTION("ALSA SoC Core");
3583MODULE_LICENSE("GPL");
Kay Sievers8b45a202008-04-14 13:33:36 +02003584MODULE_ALIAS("platform:soc-audio");