blob: 50b8b80acdf4eb4c5ae7550595c841b059aea72a [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
Mark Brownc3c5a192010-09-15 18:15:14 +0100303static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
304 size_t count, loff_t *ppos)
305{
306 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100307 ssize_t len, ret = 0;
Mark Brownc3c5a192010-09-15 18:15:14 +0100308 struct snd_soc_codec *codec;
309
310 if (!buf)
311 return -ENOMEM;
312
Mark Brown2b194f9d2010-10-13 10:52:16 +0100313 list_for_each_entry(codec, &codec_list, list) {
314 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
315 codec->name);
316 if (len >= 0)
317 ret += len;
318 if (ret > PAGE_SIZE) {
319 ret = PAGE_SIZE;
320 break;
321 }
322 }
Mark Brownc3c5a192010-09-15 18:15:14 +0100323
324 if (ret >= 0)
325 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
326
327 kfree(buf);
328
329 return ret;
330}
331
332static const struct file_operations codec_list_fops = {
333 .read = codec_list_read_file,
334 .llseek = default_llseek,/* read accesses f_pos */
335};
336
Mark Brownf3208782010-09-15 18:19:07 +0100337static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
338 size_t count, loff_t *ppos)
339{
340 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100341 ssize_t len, ret = 0;
Mark Brownf3208782010-09-15 18:19:07 +0100342 struct snd_soc_dai *dai;
343
344 if (!buf)
345 return -ENOMEM;
346
Mark Brown2b194f9d2010-10-13 10:52:16 +0100347 list_for_each_entry(dai, &dai_list, list) {
348 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
349 if (len >= 0)
350 ret += len;
351 if (ret > PAGE_SIZE) {
352 ret = PAGE_SIZE;
353 break;
354 }
355 }
Mark Brownf3208782010-09-15 18:19:07 +0100356
Mark Brown2b194f9d2010-10-13 10:52:16 +0100357 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brownf3208782010-09-15 18:19:07 +0100358
359 kfree(buf);
360
361 return ret;
362}
363
364static const struct file_operations dai_list_fops = {
365 .read = dai_list_read_file,
366 .llseek = default_llseek,/* read accesses f_pos */
367};
368
Mark Brown19c7ac22010-09-15 18:22:40 +0100369static ssize_t platform_list_read_file(struct file *file,
370 char __user *user_buf,
371 size_t count, loff_t *ppos)
372{
373 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100374 ssize_t len, ret = 0;
Mark Brown19c7ac22010-09-15 18:22:40 +0100375 struct snd_soc_platform *platform;
376
377 if (!buf)
378 return -ENOMEM;
379
Mark Brown2b194f9d2010-10-13 10:52:16 +0100380 list_for_each_entry(platform, &platform_list, list) {
381 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
382 platform->name);
383 if (len >= 0)
384 ret += len;
385 if (ret > PAGE_SIZE) {
386 ret = PAGE_SIZE;
387 break;
388 }
389 }
Mark Brown19c7ac22010-09-15 18:22:40 +0100390
Mark Brown2b194f9d2010-10-13 10:52:16 +0100391 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brown19c7ac22010-09-15 18:22:40 +0100392
393 kfree(buf);
394
395 return ret;
396}
397
398static const struct file_operations platform_list_fops = {
399 .read = platform_list_read_file,
400 .llseek = default_llseek,/* read accesses f_pos */
401};
402
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200403static void soc_init_card_debugfs(struct snd_soc_card *card)
404{
405 card->debugfs_card_root = debugfs_create_dir(card->name,
Mark Brown8a9dab12011-01-10 22:25:21 +0000406 snd_soc_debugfs_root);
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200407 if (!card->debugfs_card_root) {
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200408 dev_warn(card->dev,
Lothar Waßmann7c08be82011-12-09 14:16:29 +0100409 "ASoC: Failed to create card debugfs directory\n");
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200410 return;
411 }
412
413 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
414 card->debugfs_card_root,
415 &card->pop_time);
416 if (!card->debugfs_pop_time)
417 dev_warn(card->dev,
418 "Failed to create pop time debugfs file\n");
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200419}
420
421static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
422{
423 debugfs_remove_recursive(card->debugfs_card_root);
424}
425
Mark Brown2624d5f2009-11-03 21:56:13 +0000426#else
427
428static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
429{
430}
431
432static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
433{
434}
Axel Linb95fccb2010-11-09 17:06:44 +0800435
436static inline void soc_init_card_debugfs(struct snd_soc_card *card)
437{
438}
439
440static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
441{
442}
Mark Brown2624d5f2009-11-03 21:56:13 +0000443#endif
444
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200445#ifdef CONFIG_SND_SOC_AC97_BUS
446/* unregister ac97 codec */
447static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
448{
449 if (codec->ac97->dev.bus)
450 device_unregister(&codec->ac97->dev);
451 return 0;
452}
453
454/* stop no dev release warning */
455static void soc_ac97_device_release(struct device *dev){}
456
457/* register ac97 codec to bus */
458static int soc_ac97_dev_register(struct snd_soc_codec *codec)
459{
460 int err;
461
462 codec->ac97->dev.bus = &ac97_bus_type;
Mark Brown4ac5c612009-04-01 19:35:01 +0100463 codec->ac97->dev.parent = codec->card->dev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200464 codec->ac97->dev.release = soc_ac97_device_release;
465
Kay Sieversbb072bf2008-11-02 03:50:35 +0100466 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000467 codec->card->snd_card->number, 0, codec->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200468 err = device_register(&codec->ac97->dev);
469 if (err < 0) {
470 snd_printk(KERN_ERR "Can't register ac97 bus\n");
471 codec->ac97->dev.bus = NULL;
472 return err;
473 }
474 return 0;
475}
476#endif
477
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000478#ifdef CONFIG_PM_SLEEP
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200479/* powers down audio subsystem for suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000480int snd_soc_suspend(struct device *dev)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200481{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000482 struct snd_soc_card *card = dev_get_drvdata(dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200483 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200484 int i;
485
Daniel Macke3509ff2009-06-03 17:44:49 +0200486 /* If the initialization of this soc device failed, there is no codec
487 * associated with it. Just bail out in this case.
488 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000489 if (list_empty(&card->codec_dev_list))
Daniel Macke3509ff2009-06-03 17:44:49 +0200490 return 0;
491
Andy Green6ed25972008-06-13 16:24:05 +0100492 /* Due to the resume being scheduled into a workqueue we could
493 * suspend before that's finished - wait for it to complete.
494 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000495 snd_power_lock(card->snd_card);
496 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
497 snd_power_unlock(card->snd_card);
Andy Green6ed25972008-06-13 16:24:05 +0100498
499 /* we're going to block userspace touching us until resume completes */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000500 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
Andy Green6ed25972008-06-13 16:24:05 +0100501
Mark Browna00f90f2010-12-02 16:24:24 +0000502 /* mute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000503 for (i = 0; i < card->num_rtd; i++) {
504 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
505 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100506
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000507 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100508 continue;
509
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000510 if (drv->ops->digital_mute && dai->playback_active)
511 drv->ops->digital_mute(dai, 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200512 }
513
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100514 /* suspend all pcms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000515 for (i = 0; i < card->num_rtd; i++) {
516 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100517 continue;
518
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000519 snd_pcm_suspend_all(card->rtd[i].pcm);
Mark Brown3efab7d2010-05-09 13:25:43 +0100520 }
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100521
Mark Brown87506542008-11-18 20:50:34 +0000522 if (card->suspend_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000523 card->suspend_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200524
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000525 for (i = 0; i < card->num_rtd; i++) {
526 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
527 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100528
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000529 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100530 continue;
531
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000532 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
533 cpu_dai->driver->suspend(cpu_dai);
534 if (platform->driver->suspend && !platform->suspended) {
535 platform->driver->suspend(cpu_dai);
536 platform->suspended = 1;
Mark Brown1547aba2010-05-07 21:11:40 +0100537 }
538 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200539
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000540 /* close any waiting streams and save state */
541 for (i = 0; i < card->num_rtd; i++) {
Tejun Heo5b84ba22010-12-11 17:51:26 +0100542 flush_delayed_work_sync(&card->rtd[i].delayed_work);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200543 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000544 }
Mark Brown3efab7d2010-05-09 13:25:43 +0100545
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000546 for (i = 0; i < card->num_rtd; i++) {
547 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
548
549 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100550 continue;
551
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000552 if (driver->playback.stream_name != NULL)
553 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
554 SND_SOC_DAPM_STREAM_SUSPEND);
555
556 if (driver->capture.stream_name != NULL)
557 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
558 SND_SOC_DAPM_STREAM_SUSPEND);
559 }
560
561 /* suspend all CODECs */
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200562 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000563 /* If there are paths active then the CODEC will be held with
564 * bias _ON and should not be suspended. */
565 if (!codec->suspended && codec->driver->suspend) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200566 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000567 case SND_SOC_BIAS_STANDBY:
Mark Brown125a25d2012-01-31 15:49:10 +0000568 /*
569 * If the CODEC is capable of idle
570 * bias off then being in STANDBY
571 * means it's doing something,
572 * otherwise fall through.
573 */
574 if (codec->dapm.idle_bias_off) {
575 dev_dbg(codec->dev,
576 "idle_bias_off CODEC on over suspend\n");
577 break;
578 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000579 case SND_SOC_BIAS_OFF:
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100580 codec->driver->suspend(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000581 codec->suspended = 1;
Mark Brown7be4ba22011-07-18 13:17:13 +0900582 codec->cache_sync = 1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000583 break;
584 default:
585 dev_dbg(codec->dev, "CODEC is on over suspend\n");
586 break;
587 }
588 }
589 }
590
591 for (i = 0; i < card->num_rtd; i++) {
592 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
593
594 if (card->rtd[i].dai_link->ignore_suspend)
595 continue;
596
597 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
598 cpu_dai->driver->suspend(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200599 }
600
Mark Brown87506542008-11-18 20:50:34 +0000601 if (card->suspend_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000602 card->suspend_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200603
604 return 0;
605}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000606EXPORT_SYMBOL_GPL(snd_soc_suspend);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200607
Andy Green6ed25972008-06-13 16:24:05 +0100608/* deferred resume work, so resume can complete before we finished
609 * setting our codec back up, which can be very slow on I2C
610 */
611static void soc_resume_deferred(struct work_struct *work)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200612{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000613 struct snd_soc_card *card =
614 container_of(work, struct snd_soc_card, deferred_resume_work);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200615 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200616 int i;
617
Andy Green6ed25972008-06-13 16:24:05 +0100618 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
619 * so userspace apps are blocked from touching us
620 */
621
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000622 dev_dbg(card->dev, "starting resume work\n");
Andy Green6ed25972008-06-13 16:24:05 +0100623
Mark Brown9949788b2010-05-07 20:24:05 +0100624 /* Bring us up into D2 so that DAPM starts enabling things */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000625 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
Mark Brown9949788b2010-05-07 20:24:05 +0100626
Mark Brown87506542008-11-18 20:50:34 +0000627 if (card->resume_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000628 card->resume_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200629
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000630 /* resume AC97 DAIs */
631 for (i = 0; i < card->num_rtd; i++) {
632 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Mark Brown3efab7d2010-05-09 13:25:43 +0100633
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000634 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100635 continue;
636
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000637 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
638 cpu_dai->driver->resume(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200639 }
640
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200641 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000642 /* If the CODEC was idle over suspend then it will have been
643 * left with bias OFF or STANDBY and suspended so we must now
644 * resume. Otherwise the suspend was suppressed.
645 */
646 if (codec->driver->resume && codec->suspended) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200647 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000648 case SND_SOC_BIAS_STANDBY:
649 case SND_SOC_BIAS_OFF:
650 codec->driver->resume(codec);
651 codec->suspended = 0;
652 break;
653 default:
654 dev_dbg(codec->dev, "CODEC was on over suspend\n");
655 break;
656 }
Mark Brown1547aba2010-05-07 21:11:40 +0100657 }
658 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200659
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000660 for (i = 0; i < card->num_rtd; i++) {
661 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
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 (driver->playback.stream_name != NULL)
667 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200668 SND_SOC_DAPM_STREAM_RESUME);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000669
670 if (driver->capture.stream_name != NULL)
671 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200672 SND_SOC_DAPM_STREAM_RESUME);
673 }
674
Mark Brown3ff3f642008-05-19 12:32:25 +0200675 /* unmute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000676 for (i = 0; i < card->num_rtd; i++) {
677 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
678 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100679
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000680 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100681 continue;
682
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000683 if (drv->ops->digital_mute && dai->playback_active)
684 drv->ops->digital_mute(dai, 0);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200685 }
686
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000687 for (i = 0; i < card->num_rtd; i++) {
688 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
689 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100690
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000691 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100692 continue;
693
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000694 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
695 cpu_dai->driver->resume(cpu_dai);
696 if (platform->driver->resume && platform->suspended) {
697 platform->driver->resume(cpu_dai);
698 platform->suspended = 0;
699 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200700 }
701
Mark Brown87506542008-11-18 20:50:34 +0000702 if (card->resume_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000703 card->resume_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200704
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000705 dev_dbg(card->dev, "resume work completed\n");
Andy Green6ed25972008-06-13 16:24:05 +0100706
707 /* userspace can access us now we are back as we were before */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000708 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
Andy Green6ed25972008-06-13 16:24:05 +0100709}
710
711/* powers up audio subsystem after a suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000712int snd_soc_resume(struct device *dev)
Andy Green6ed25972008-06-13 16:24:05 +0100713{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000714 struct snd_soc_card *card = dev_get_drvdata(dev);
Stephen Warren82e14e82011-05-25 14:06:41 -0600715 int i, ac97_control = 0;
Peter Ujfalusib9dd94a2010-02-22 13:27:13 +0200716
Eric Miao5ff1ddf2011-11-23 22:37:00 +0800717 /* If the initialization of this soc device failed, there is no codec
718 * associated with it. Just bail out in this case.
719 */
720 if (list_empty(&card->codec_dev_list))
721 return 0;
722
Mark Brown64ab9ba2009-03-31 11:27:03 +0100723 /* AC97 devices might have other drivers hanging off them so
724 * need to resume immediately. Other drivers don't have that
725 * problem and may take a substantial amount of time to resume
726 * due to I/O costs and anti-pop so handle them out of line.
727 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000728 for (i = 0; i < card->num_rtd; i++) {
729 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Stephen Warren82e14e82011-05-25 14:06:41 -0600730 ac97_control |= cpu_dai->driver->ac97_control;
731 }
732 if (ac97_control) {
733 dev_dbg(dev, "Resuming AC97 immediately\n");
734 soc_resume_deferred(&card->deferred_resume_work);
735 } else {
736 dev_dbg(dev, "Scheduling resume work\n");
737 if (!schedule_work(&card->deferred_resume_work))
738 dev_err(dev, "resume work item may be lost\n");
Mark Brown64ab9ba2009-03-31 11:27:03 +0100739 }
Andy Green6ed25972008-06-13 16:24:05 +0100740
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200741 return 0;
742}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000743EXPORT_SYMBOL_GPL(snd_soc_resume);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200744#else
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000745#define snd_soc_suspend NULL
746#define snd_soc_resume NULL
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200747#endif
748
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100749static const struct snd_soc_dai_ops null_dai_ops = {
Barry Song02a06d32009-10-16 18:13:38 +0800750};
751
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000752static int soc_bind_dai_link(struct snd_soc_card *card, int num)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200753{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000754 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
755 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
Mark Brownfe3e78e2009-11-03 22:13:13 +0000756 struct snd_soc_codec *codec;
Mark Brown435c5e22008-12-04 15:32:53 +0000757 struct snd_soc_platform *platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000758 struct snd_soc_dai *codec_dai, *cpu_dai;
Mark Brown848dd8b2011-04-27 18:16:32 +0100759 const char *platform_name;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200760
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000761 if (rtd->complete)
762 return 1;
763 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
Mark Brown63084192008-12-02 15:08:03 +0000764
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000765 /* do we already have the CPU DAI for this link ? */
766 if (rtd->cpu_dai) {
767 goto find_codec;
768 }
769 /* no, then find CPU DAI from registered DAIs*/
770 list_for_each_entry(cpu_dai, &dai_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700771 if (dai_link->cpu_dai_of_node) {
772 if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node)
773 continue;
774 } else {
775 if (strcmp(cpu_dai->name, dai_link->cpu_dai_name))
776 continue;
777 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700778
779 rtd->cpu_dai = cpu_dai;
780 goto find_codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000781 }
782 dev_dbg(card->dev, "CPU DAI %s not registered\n",
783 dai_link->cpu_dai_name);
784
785find_codec:
786 /* do we already have the CODEC for this link ? */
787 if (rtd->codec) {
788 goto find_platform;
Mark Brownc5af3a22008-11-28 13:29:45 +0000789 }
790
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000791 /* no, then find CODEC from registered CODECs*/
792 list_for_each_entry(codec, &codec_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700793 if (dai_link->codec_of_node) {
794 if (codec->dev->of_node != dai_link->codec_of_node)
795 continue;
796 } else {
797 if (strcmp(codec->name, dai_link->codec_name))
798 continue;
799 }
Mark Brown6b05eda2008-12-08 19:26:48 +0000800
Stephen Warren2610ab72011-12-07 13:58:27 -0700801 rtd->codec = codec;
802
803 /*
804 * CODEC found, so find CODEC DAI from registered DAIs from
805 * this CODEC
806 */
807 list_for_each_entry(codec_dai, &dai_list, list) {
808 if (codec->dev == codec_dai->dev &&
809 !strcmp(codec_dai->name,
810 dai_link->codec_dai_name)) {
811
812 rtd->codec_dai = codec_dai;
813 goto find_platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000814 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000815 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700816 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
817 dai_link->codec_dai_name);
818
819 goto find_platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000820 }
821 dev_dbg(card->dev, "CODEC %s not registered\n",
822 dai_link->codec_name);
823
824find_platform:
Mark Brown848dd8b2011-04-27 18:16:32 +0100825 /* do we need a platform? */
826 if (rtd->platform)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000827 goto out;
Mark Brown848dd8b2011-04-27 18:16:32 +0100828
829 /* if there's no platform we match on the empty platform */
830 platform_name = dai_link->platform_name;
Stephen Warren5a504962011-12-21 10:40:59 -0700831 if (!platform_name && !dai_link->platform_of_node)
Mark Brown848dd8b2011-04-27 18:16:32 +0100832 platform_name = "snd-soc-dummy";
833
834 /* no, then find one from the set of registered platforms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000835 list_for_each_entry(platform, &platform_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700836 if (dai_link->platform_of_node) {
837 if (platform->dev->of_node !=
838 dai_link->platform_of_node)
839 continue;
840 } else {
841 if (strcmp(platform->name, platform_name))
842 continue;
843 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700844
845 rtd->platform = platform;
846 goto out;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000847 }
848
849 dev_dbg(card->dev, "platform %s not registered\n",
850 dai_link->platform_name);
851 return 0;
852
853out:
854 /* mark rtd as complete if we found all 4 of our client devices */
855 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
856 rtd->complete = 1;
857 card->num_rtd++;
858 }
859 return 1;
860}
861
Jarkko Nikula589c3562010-12-06 16:27:07 +0200862static void soc_remove_codec(struct snd_soc_codec *codec)
863{
864 int err;
865
866 if (codec->driver->remove) {
867 err = codec->driver->remove(codec);
868 if (err < 0)
869 dev_err(codec->dev,
870 "asoc: failed to remove %s: %d\n",
871 codec->name, err);
872 }
873
874 /* Make sure all DAPM widgets are freed */
875 snd_soc_dapm_free(&codec->dapm);
876
877 soc_cleanup_codec_debugfs(codec);
878 codec->probed = 0;
879 list_del(&codec->card_list);
880 module_put(codec->dev->driver->owner);
881}
882
Liam Girdwood0168bf02011-06-07 16:08:05 +0100883static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000884{
885 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
886 struct snd_soc_codec *codec = rtd->codec;
887 struct snd_soc_platform *platform = rtd->platform;
888 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
889 int err;
890
891 /* unregister the rtd device */
892 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -0800893 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
894 device_remove_file(rtd->dev, &dev_attr_codec_reg);
895 device_unregister(rtd->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000896 rtd->dev_registered = 0;
897 }
898
899 /* remove the CODEC DAI */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100900 if (codec_dai && codec_dai->probed &&
901 codec_dai->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000902 if (codec_dai->driver->remove) {
903 err = codec_dai->driver->remove(codec_dai);
904 if (err < 0)
905 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
906 }
907 codec_dai->probed = 0;
908 list_del(&codec_dai->card_list);
909 }
910
911 /* remove the platform */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100912 if (platform && platform->probed &&
913 platform->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000914 if (platform->driver->remove) {
915 err = platform->driver->remove(platform);
916 if (err < 0)
917 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
918 }
Liam Girdwood675c4962012-01-16 15:25:37 +0000919
920 /* Make sure all DAPM widgets are freed */
921 snd_soc_dapm_free(&platform->dapm);
922
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000923 platform->probed = 0;
924 list_del(&platform->card_list);
925 module_put(platform->dev->driver->owner);
926 }
927
928 /* remove the CODEC */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100929 if (codec && codec->probed &&
930 codec->driver->remove_order == order)
Jarkko Nikula589c3562010-12-06 16:27:07 +0200931 soc_remove_codec(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000932
933 /* remove the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +0100934 if (cpu_dai && cpu_dai->probed &&
935 cpu_dai->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000936 if (cpu_dai->driver->remove) {
937 err = cpu_dai->driver->remove(cpu_dai);
938 if (err < 0)
939 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
940 }
941 cpu_dai->probed = 0;
942 list_del(&cpu_dai->card_list);
943 module_put(cpu_dai->dev->driver->owner);
944 }
945}
946
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900947static void soc_remove_dai_links(struct snd_soc_card *card)
948{
Liam Girdwood0168bf02011-06-07 16:08:05 +0100949 int dai, order;
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900950
Liam Girdwood0168bf02011-06-07 16:08:05 +0100951 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
952 order++) {
953 for (dai = 0; dai < card->num_rtd; dai++)
954 soc_remove_dai_link(card, dai, order);
955 }
Kuninori Morimoto0671fd82011-04-08 14:50:44 +0900956 card->num_rtd = 0;
957}
958
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200959static void soc_set_name_prefix(struct snd_soc_card *card,
960 struct snd_soc_codec *codec)
961{
962 int i;
963
Dimitris Papastamosff819b82010-12-02 14:53:03 +0000964 if (card->codec_conf == NULL)
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200965 return;
966
Dimitris Papastamosff819b82010-12-02 14:53:03 +0000967 for (i = 0; i < card->num_configs; i++) {
968 struct snd_soc_codec_conf *map = &card->codec_conf[i];
Jarkko Nikulaead9b912010-11-13 20:40:44 +0200969 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
970 codec->name_prefix = map->name_prefix;
971 break;
972 }
973 }
974}
975
Jarkko Nikula589c3562010-12-06 16:27:07 +0200976static int soc_probe_codec(struct snd_soc_card *card,
977 struct snd_soc_codec *codec)
978{
979 int ret = 0;
Mark Brown89b95ac02011-03-07 16:38:44 +0000980 const struct snd_soc_codec_driver *driver = codec->driver;
Jarkko Nikula589c3562010-12-06 16:27:07 +0200981
982 codec->card = card;
983 codec->dapm.card = card;
984 soc_set_name_prefix(card, codec);
985
Jarkko Nikula70d293312011-01-27 16:24:22 +0200986 if (!try_module_get(codec->dev->driver->owner))
987 return -ENODEV;
988
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +0200989 soc_init_codec_debugfs(codec);
990
Lars-Peter Clausen77530152011-05-05 16:59:09 +0200991 if (driver->dapm_widgets)
992 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
993 driver->num_dapm_widgets);
994
Mark Brown33c5f962011-08-22 18:40:30 +0100995 codec->dapm.idle_bias_off = driver->idle_bias_off;
996
Mark Brown89b95ac02011-03-07 16:38:44 +0000997 if (driver->probe) {
998 ret = driver->probe(codec);
Jarkko Nikula589c3562010-12-06 16:27:07 +0200999 if (ret < 0) {
1000 dev_err(codec->dev,
1001 "asoc: failed to probe CODEC %s: %d\n",
1002 codec->name, ret);
Jarkko Nikula70d293312011-01-27 16:24:22 +02001003 goto err_probe;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001004 }
1005 }
1006
Mark Brownb7af1da2011-04-07 19:18:44 +09001007 if (driver->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001008 snd_soc_add_codec_controls(codec, driver->controls,
Mark Brownb7af1da2011-04-07 19:18:44 +09001009 driver->num_controls);
Mark Brown89b95ac02011-03-07 16:38:44 +00001010 if (driver->dapm_routes)
1011 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1012 driver->num_dapm_routes);
1013
Jarkko Nikula589c3562010-12-06 16:27:07 +02001014 /* mark codec as probed and add to card codec list */
1015 codec->probed = 1;
1016 list_add(&codec->card_list, &card->codec_dev_list);
Jarkko Nikula7be31be82010-12-14 12:18:32 +02001017 list_add(&codec->dapm.list, &card->dapm_list);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001018
Jarkko Nikula70d293312011-01-27 16:24:22 +02001019 return 0;
1020
1021err_probe:
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001022 soc_cleanup_codec_debugfs(codec);
Jarkko Nikula70d293312011-01-27 16:24:22 +02001023 module_put(codec->dev->driver->owner);
1024
Jarkko Nikula589c3562010-12-06 16:27:07 +02001025 return ret;
1026}
1027
Liam Girdwood956245e2011-07-01 16:54:08 +01001028static int soc_probe_platform(struct snd_soc_card *card,
1029 struct snd_soc_platform *platform)
1030{
1031 int ret = 0;
1032 const struct snd_soc_platform_driver *driver = platform->driver;
1033
1034 platform->card = card;
Liam Girdwoodb7950642011-07-04 22:10:52 +01001035 platform->dapm.card = card;
Liam Girdwood956245e2011-07-01 16:54:08 +01001036
1037 if (!try_module_get(platform->dev->driver->owner))
1038 return -ENODEV;
1039
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001040 if (driver->dapm_widgets)
1041 snd_soc_dapm_new_controls(&platform->dapm,
1042 driver->dapm_widgets, driver->num_dapm_widgets);
1043
Liam Girdwood956245e2011-07-01 16:54:08 +01001044 if (driver->probe) {
1045 ret = driver->probe(platform);
1046 if (ret < 0) {
1047 dev_err(platform->dev,
1048 "asoc: failed to probe platform %s: %d\n",
1049 platform->name, ret);
1050 goto err_probe;
1051 }
1052 }
1053
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001054 if (driver->controls)
1055 snd_soc_add_platform_controls(platform, driver->controls,
1056 driver->num_controls);
1057 if (driver->dapm_routes)
1058 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1059 driver->num_dapm_routes);
1060
Liam Girdwood956245e2011-07-01 16:54:08 +01001061 /* mark platform as probed and add to card platform list */
1062 platform->probed = 1;
1063 list_add(&platform->card_list, &card->platform_dev_list);
Liam Girdwoodb7950642011-07-04 22:10:52 +01001064 list_add(&platform->dapm.list, &card->dapm_list);
Liam Girdwood956245e2011-07-01 16:54:08 +01001065
1066 return 0;
1067
1068err_probe:
1069 module_put(platform->dev->driver->owner);
1070
1071 return ret;
1072}
1073
Mark Brown36ae1a92012-01-06 17:12:45 -08001074static void rtd_release(struct device *dev)
1075{
1076 kfree(dev);
1077}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001078
Jarkko Nikula589c3562010-12-06 16:27:07 +02001079static int soc_post_component_init(struct snd_soc_card *card,
1080 struct snd_soc_codec *codec,
1081 int num, int dailess)
1082{
1083 struct snd_soc_dai_link *dai_link = NULL;
1084 struct snd_soc_aux_dev *aux_dev = NULL;
1085 struct snd_soc_pcm_runtime *rtd;
1086 const char *temp, *name;
1087 int ret = 0;
1088
1089 if (!dailess) {
1090 dai_link = &card->dai_link[num];
1091 rtd = &card->rtd[num];
1092 name = dai_link->name;
1093 } else {
1094 aux_dev = &card->aux_dev[num];
1095 rtd = &card->rtd_aux[num];
1096 name = aux_dev->name;
1097 }
Janusz Krzysztofik0962bb22011-02-02 21:11:41 +01001098 rtd->card = card;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001099
Mark Brown4b1cfcb2011-10-18 00:11:49 +01001100 /* Make sure all DAPM widgets are instantiated */
1101 snd_soc_dapm_new_widgets(&codec->dapm);
1102
Jarkko Nikula589c3562010-12-06 16:27:07 +02001103 /* machine controls, routes and widgets are not prefixed */
1104 temp = codec->name_prefix;
1105 codec->name_prefix = NULL;
1106
1107 /* do machine specific initialization */
1108 if (!dailess && dai_link->init)
1109 ret = dai_link->init(rtd);
1110 else if (dailess && aux_dev->init)
1111 ret = aux_dev->init(&codec->dapm);
1112 if (ret < 0) {
1113 dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1114 return ret;
1115 }
1116 codec->name_prefix = temp;
1117
Jarkko Nikula589c3562010-12-06 16:27:07 +02001118 /* register the rtd device */
1119 rtd->codec = codec;
Mark Brown36ae1a92012-01-06 17:12:45 -08001120
1121 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1122 if (!rtd->dev)
1123 return -ENOMEM;
1124 device_initialize(rtd->dev);
1125 rtd->dev->parent = card->dev;
1126 rtd->dev->release = rtd_release;
1127 rtd->dev->init_name = name;
1128 dev_set_drvdata(rtd->dev, rtd);
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +01001129 mutex_init(&rtd->pcm_mutex);
Mark Brown36ae1a92012-01-06 17:12:45 -08001130 ret = device_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001131 if (ret < 0) {
1132 dev_err(card->dev,
1133 "asoc: failed to register runtime device: %d\n", ret);
1134 return ret;
1135 }
1136 rtd->dev_registered = 1;
1137
1138 /* add DAPM sysfs entries for this codec */
Mark Brown36ae1a92012-01-06 17:12:45 -08001139 ret = snd_soc_dapm_sys_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001140 if (ret < 0)
1141 dev_err(codec->dev,
1142 "asoc: failed to add codec dapm sysfs entries: %d\n",
1143 ret);
1144
1145 /* add codec sysfs entries */
Mark Brown36ae1a92012-01-06 17:12:45 -08001146 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001147 if (ret < 0)
1148 dev_err(codec->dev,
1149 "asoc: failed to add codec sysfs files: %d\n", ret);
1150
1151 return 0;
1152}
1153
Liam Girdwood0168bf02011-06-07 16:08:05 +01001154static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001155{
1156 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1157 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1158 struct snd_soc_codec *codec = rtd->codec;
1159 struct snd_soc_platform *platform = rtd->platform;
1160 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1161 int ret;
1162
Liam Girdwood0168bf02011-06-07 16:08:05 +01001163 dev_dbg(card->dev, "probe %s dai link %d late %d\n",
1164 card->name, num, order);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001165
1166 /* config components */
1167 codec_dai->codec = codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001168 cpu_dai->platform = platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001169 codec_dai->card = card;
1170 cpu_dai->card = card;
1171
1172 /* set default power off timeout */
1173 rtd->pmdown_time = pmdown_time;
1174
1175 /* probe the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001176 if (!cpu_dai->probed &&
1177 cpu_dai->driver->probe_order == order) {
Liam Girdwood61b61e32011-05-24 13:57:43 +01001178 if (!try_module_get(cpu_dai->dev->driver->owner))
1179 return -ENODEV;
1180
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001181 if (cpu_dai->driver->probe) {
1182 ret = cpu_dai->driver->probe(cpu_dai);
1183 if (ret < 0) {
1184 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1185 cpu_dai->name);
Liam Girdwood61b61e32011-05-24 13:57:43 +01001186 module_put(cpu_dai->dev->driver->owner);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001187 return ret;
1188 }
1189 }
1190 cpu_dai->probed = 1;
Wolfram Sang1c8371d2011-07-17 18:00:26 +02001191 /* mark cpu_dai as probed and add to card dai list */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001192 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1193 }
1194
1195 /* probe the CODEC */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001196 if (!codec->probed &&
1197 codec->driver->probe_order == order) {
Jarkko Nikula589c3562010-12-06 16:27:07 +02001198 ret = soc_probe_codec(card, codec);
1199 if (ret < 0)
1200 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001201 }
1202
1203 /* probe the platform */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001204 if (!platform->probed &&
1205 platform->driver->probe_order == order) {
Liam Girdwood956245e2011-07-01 16:54:08 +01001206 ret = soc_probe_platform(card, platform);
1207 if (ret < 0)
1208 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001209 }
1210
1211 /* probe the CODEC DAI */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001212 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001213 if (codec_dai->driver->probe) {
1214 ret = codec_dai->driver->probe(codec_dai);
1215 if (ret < 0) {
1216 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1217 codec_dai->name);
1218 return ret;
Mark Brown6b05eda2008-12-08 19:26:48 +00001219 }
1220 }
1221
Wolfram Sang1c8371d2011-07-17 18:00:26 +02001222 /* mark codec_dai as probed and add to card dai list */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001223 codec_dai->probed = 1;
1224 list_add(&codec_dai->card_list, &card->dai_dev_list);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001225 }
1226
Liam Girdwood0168bf02011-06-07 16:08:05 +01001227 /* complete DAI probe during last probe */
1228 if (order != SND_SOC_COMP_ORDER_LAST)
1229 return 0;
1230
Jarkko Nikula589c3562010-12-06 16:27:07 +02001231 ret = soc_post_component_init(card, codec, num, 0);
1232 if (ret)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001233 return ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001234
Mark Brown36ae1a92012-01-06 17:12:45 -08001235 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001236 if (ret < 0)
1237 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1238
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001239 /* create the pcm */
1240 ret = soc_new_pcm(rtd, num);
1241 if (ret < 0) {
1242 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1243 return ret;
1244 }
1245
1246 /* add platform data for AC97 devices */
1247 if (rtd->codec_dai->driver->ac97_control)
1248 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1249
1250 return 0;
1251}
1252
1253#ifdef CONFIG_SND_SOC_AC97_BUS
1254static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1255{
1256 int ret;
1257
1258 /* Only instantiate AC97 if not already done by the adaptor
1259 * for the generic AC97 subsystem.
1260 */
1261 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
Mika Westerberg0562f782010-10-13 11:30:32 +03001262 /*
1263 * It is possible that the AC97 device is already registered to
1264 * the device subsystem. This happens when the device is created
1265 * via snd_ac97_mixer(). Currently only SoC codec that does so
1266 * is the generic AC97 glue but others migh emerge.
1267 *
1268 * In those cases we don't try to register the device again.
1269 */
1270 if (!rtd->codec->ac97_created)
1271 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001272
1273 ret = soc_ac97_dev_register(rtd->codec);
1274 if (ret < 0) {
1275 printk(KERN_ERR "asoc: AC97 device register failed\n");
1276 return ret;
1277 }
1278
1279 rtd->codec->ac97_registered = 1;
1280 }
1281 return 0;
1282}
1283
1284static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1285{
1286 if (codec->ac97_registered) {
1287 soc_ac97_dev_unregister(codec);
1288 codec->ac97_registered = 0;
1289 }
1290}
1291#endif
1292
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001293static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1294{
1295 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001296 struct snd_soc_codec *codec;
Jarkko Nikula676ad982010-12-03 09:18:22 +02001297 int ret = -ENODEV;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001298
1299 /* find CODEC from registered CODECs*/
1300 list_for_each_entry(codec, &codec_list, list) {
1301 if (!strcmp(codec->name, aux_dev->codec_name)) {
1302 if (codec->probed) {
1303 dev_err(codec->dev,
1304 "asoc: codec already probed");
1305 ret = -EBUSY;
1306 goto out;
1307 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001308 goto found;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001309 }
1310 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001311 /* codec not found */
1312 dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1313 goto out;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001314
Jarkko Nikula676ad982010-12-03 09:18:22 +02001315found:
Jarkko Nikula589c3562010-12-06 16:27:07 +02001316 ret = soc_probe_codec(card, codec);
1317 if (ret < 0)
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001318 return ret;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001319
Jarkko Nikula589c3562010-12-06 16:27:07 +02001320 ret = soc_post_component_init(card, codec, num, 1);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001321
1322out:
1323 return ret;
1324}
1325
1326static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1327{
1328 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1329 struct snd_soc_codec *codec = rtd->codec;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001330
1331 /* unregister the rtd device */
1332 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -08001333 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1334 device_del(rtd->dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001335 rtd->dev_registered = 0;
1336 }
1337
Jarkko Nikula589c3562010-12-06 16:27:07 +02001338 if (codec && codec->probed)
1339 soc_remove_codec(codec);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001340}
1341
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001342static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1343 enum snd_soc_compress_type compress_type)
1344{
1345 int ret;
1346
1347 if (codec->cache_init)
1348 return 0;
1349
1350 /* override the compress_type if necessary */
1351 if (compress_type && codec->compress_type != compress_type)
1352 codec->compress_type = compress_type;
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001353 ret = snd_soc_cache_init(codec);
1354 if (ret < 0) {
1355 dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1356 ret);
1357 return ret;
1358 }
1359 codec->cache_init = 1;
1360 return 0;
1361}
1362
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001363static void snd_soc_instantiate_card(struct snd_soc_card *card)
1364{
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001365 struct snd_soc_codec *codec;
1366 struct snd_soc_codec_conf *codec_conf;
1367 enum snd_soc_compress_type compress_type;
Mark Brown75d9ac42011-09-27 16:41:01 +01001368 struct snd_soc_dai_link *dai_link;
Liam Girdwood0168bf02011-06-07 16:08:05 +01001369 int ret, i, order;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001370
1371 mutex_lock(&card->mutex);
1372
1373 if (card->instantiated) {
1374 mutex_unlock(&card->mutex);
1375 return;
1376 }
1377
1378 /* bind DAIs */
1379 for (i = 0; i < card->num_links; i++)
1380 soc_bind_dai_link(card, i);
1381
1382 /* bind completed ? */
1383 if (card->num_rtd != card->num_links) {
1384 mutex_unlock(&card->mutex);
1385 return;
1386 }
1387
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001388 /* initialize the register cache for each available codec */
1389 list_for_each_entry(codec, &codec_list, list) {
1390 if (codec->cache_init)
1391 continue;
Dimitris Papastamos861f2fa2011-01-11 11:43:51 +00001392 /* by default we don't override the compress_type */
1393 compress_type = 0;
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001394 /* check to see if we need to override the compress_type */
1395 for (i = 0; i < card->num_configs; ++i) {
1396 codec_conf = &card->codec_conf[i];
1397 if (!strcmp(codec->name, codec_conf->dev_name)) {
1398 compress_type = codec_conf->compress_type;
1399 if (compress_type && compress_type
1400 != codec->compress_type)
1401 break;
1402 }
1403 }
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001404 ret = snd_soc_init_codec_cache(codec, compress_type);
1405 if (ret < 0) {
1406 mutex_unlock(&card->mutex);
1407 return;
1408 }
1409 }
1410
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001411 /* card bind complete so register a sound card */
1412 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1413 card->owner, 0, &card->snd_card);
1414 if (ret < 0) {
1415 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1416 card->name);
1417 mutex_unlock(&card->mutex);
1418 return;
1419 }
1420 card->snd_card->dev = card->dev;
1421
Mark Browne37a4972011-03-02 18:21:57 +00001422 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1423 card->dapm.dev = card->dev;
1424 card->dapm.card = card;
1425 list_add(&card->dapm.list, &card->dapm_list);
1426
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001427#ifdef CONFIG_DEBUG_FS
1428 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1429#endif
1430
Mark Brown88ee1c62011-02-02 10:43:26 +00001431#ifdef CONFIG_PM_SLEEP
Andy Green6ed25972008-06-13 16:24:05 +01001432 /* deferred resume work */
Mark Brown63084192008-12-02 15:08:03 +00001433 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
Randy Dunlap1301a962008-06-17 19:19:34 +01001434#endif
Andy Green6ed25972008-06-13 16:24:05 +01001435
Mark Brown9a841eb2011-04-12 17:51:37 -07001436 if (card->dapm_widgets)
1437 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1438 card->num_dapm_widgets);
1439
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001440 /* initialise the sound card only once */
1441 if (card->probe) {
Mark Browne7361ec2011-01-26 14:17:20 +00001442 ret = card->probe(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001443 if (ret < 0)
1444 goto card_probe_error;
1445 }
1446
Liam Girdwood0168bf02011-06-07 16:08:05 +01001447 /* early DAI link probe */
1448 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1449 order++) {
1450 for (i = 0; i < card->num_links; i++) {
1451 ret = soc_probe_dai_link(card, i, order);
1452 if (ret < 0) {
1453 pr_err("asoc: failed to instantiate card %s: %d\n",
Mark Brown321de0d2010-09-21 15:09:37 +01001454 card->name, ret);
Liam Girdwood0168bf02011-06-07 16:08:05 +01001455 goto probe_dai_err;
1456 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001457 }
1458 }
1459
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001460 for (i = 0; i < card->num_aux_devs; i++) {
1461 ret = soc_probe_aux_dev(card, i);
1462 if (ret < 0) {
1463 pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1464 card->name, ret);
1465 goto probe_aux_dev_err;
1466 }
1467 }
1468
Mark Brownb7af1da2011-04-07 19:18:44 +09001469 if (card->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001470 snd_soc_add_card_controls(card, card->controls, card->num_controls);
Mark Brownb7af1da2011-04-07 19:18:44 +09001471
Mark Brownb8ad29d2011-03-02 18:35:51 +00001472 if (card->dapm_routes)
1473 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1474 card->num_dapm_routes);
1475
Mark Brownb90d2f92011-10-10 13:38:06 +01001476 snd_soc_dapm_new_widgets(&card->dapm);
1477
Mark Brown75d9ac42011-09-27 16:41:01 +01001478 for (i = 0; i < card->num_links; i++) {
1479 dai_link = &card->dai_link[i];
1480
1481 if (dai_link->dai_fmt) {
1482 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
1483 dai_link->dai_fmt);
1484 if (ret != 0)
1485 dev_warn(card->rtd[i].codec_dai->dev,
1486 "Failed to set DAI format: %d\n",
1487 ret);
1488
1489 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1490 dai_link->dai_fmt);
1491 if (ret != 0)
1492 dev_warn(card->rtd[i].cpu_dai->dev,
1493 "Failed to set DAI format: %d\n",
1494 ret);
1495 }
1496 }
1497
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001498 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001499 "%s", card->name);
Liam Girdwood22de71b2011-05-12 16:14:04 +01001500 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1501 "%s", card->long_name ? card->long_name : card->name);
Mark Brownf0e8ed82011-09-20 11:41:54 +01001502 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1503 "%s", card->driver_name ? card->driver_name : card->name);
1504 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1505 switch (card->snd_card->driver[i]) {
1506 case '_':
1507 case '-':
1508 case '\0':
1509 break;
1510 default:
1511 if (!isalnum(card->snd_card->driver[i]))
1512 card->snd_card->driver[i] = '_';
1513 break;
1514 }
1515 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001516
Mark Brown28e9ad92011-03-02 18:36:34 +00001517 if (card->late_probe) {
1518 ret = card->late_probe(card);
1519 if (ret < 0) {
1520 dev_err(card->dev, "%s late_probe() failed: %d\n",
1521 card->name, ret);
1522 goto probe_aux_dev_err;
1523 }
1524 }
1525
Mark Brown2dc00212011-10-08 13:59:44 +01001526 snd_soc_dapm_new_widgets(&card->dapm);
1527
Stephen Warren16332812011-11-23 12:42:04 -07001528 if (card->fully_routed)
Mark Brownb05d8dc2011-11-27 19:38:34 +00001529 list_for_each_entry(codec, &card->codec_dev_list, card_list)
Stephen Warren16332812011-11-23 12:42:04 -07001530 snd_soc_dapm_auto_nc_codec_pins(codec);
1531
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001532 ret = snd_card_register(card->snd_card);
1533 if (ret < 0) {
1534 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
Axel Lin6b3ed782010-12-07 16:12:29 +08001535 goto probe_aux_dev_err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001536 }
1537
1538#ifdef CONFIG_SND_SOC_AC97_BUS
1539 /* register any AC97 codecs */
1540 for (i = 0; i < card->num_rtd; i++) {
Axel Lin6b3ed782010-12-07 16:12:29 +08001541 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1542 if (ret < 0) {
1543 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1544 while (--i >= 0)
Mark Brown7d8316d2010-12-13 17:03:27 +00001545 soc_unregister_ac97_dai_link(card->rtd[i].codec);
Axel Lin6b3ed782010-12-07 16:12:29 +08001546 goto probe_aux_dev_err;
Mark Brownfe3e78e2009-11-03 22:13:13 +00001547 }
Axel Lin6b3ed782010-12-07 16:12:29 +08001548 }
Mark Brownfe3e78e2009-11-03 22:13:13 +00001549#endif
1550
Mark Brown435c5e22008-12-04 15:32:53 +00001551 card->instantiated = 1;
Mark Brown4f4c0072011-10-07 14:29:19 +01001552 snd_soc_dapm_sync(&card->dapm);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001553 mutex_unlock(&card->mutex);
Mark Brown435c5e22008-12-04 15:32:53 +00001554 return;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001555
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001556probe_aux_dev_err:
1557 for (i = 0; i < card->num_aux_devs; i++)
1558 soc_remove_aux_dev(card, i);
1559
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001560probe_dai_err:
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001561 soc_remove_dai_links(card);
Mark Brownfe3e78e2009-11-03 22:13:13 +00001562
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001563card_probe_error:
Mark Brown87506542008-11-18 20:50:34 +00001564 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001565 card->remove(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001566
1567 snd_card_free(card->snd_card);
1568
1569 mutex_unlock(&card->mutex);
Mark Brown435c5e22008-12-04 15:32:53 +00001570}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001571
Mark Brown435c5e22008-12-04 15:32:53 +00001572/*
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001573 * Attempt to initialise any uninitialised cards. Must be called with
Mark Brown435c5e22008-12-04 15:32:53 +00001574 * client_mutex.
1575 */
1576static void snd_soc_instantiate_cards(void)
1577{
1578 struct snd_soc_card *card;
1579 list_for_each_entry(card, &card_list, list)
1580 snd_soc_instantiate_card(card);
1581}
1582
1583/* probes a new socdev */
1584static int soc_probe(struct platform_device *pdev)
1585{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001586 struct snd_soc_card *card = platform_get_drvdata(pdev);
Mark Brown435c5e22008-12-04 15:32:53 +00001587 int ret = 0;
Mark Brown435c5e22008-12-04 15:32:53 +00001588
Vinod Koul70a7ca32011-01-14 19:22:48 +05301589 /*
1590 * no card, so machine driver should be registering card
1591 * we should not be here in that case so ret error
1592 */
1593 if (!card)
1594 return -EINVAL;
1595
Mark Brown435c5e22008-12-04 15:32:53 +00001596 /* Bodge while we unpick instantiation */
1597 card->dev = &pdev->dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001598
Mark Brown435c5e22008-12-04 15:32:53 +00001599 ret = snd_soc_register_card(card);
1600 if (ret != 0) {
1601 dev_err(&pdev->dev, "Failed to register card\n");
1602 return ret;
1603 }
1604
1605 return 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001606}
1607
Vinod Koulb0e26482011-01-13 22:48:02 +05301608static int soc_cleanup_card_resources(struct snd_soc_card *card)
1609{
Vinod Koulb0e26482011-01-13 22:48:02 +05301610 int i;
1611
1612 /* make sure any delayed work runs */
1613 for (i = 0; i < card->num_rtd; i++) {
1614 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1615 flush_delayed_work_sync(&rtd->delayed_work);
1616 }
1617
1618 /* remove auxiliary devices */
1619 for (i = 0; i < card->num_aux_devs; i++)
1620 soc_remove_aux_dev(card, i);
1621
1622 /* remove and free each DAI */
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001623 soc_remove_dai_links(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301624
1625 soc_cleanup_card_debugfs(card);
1626
1627 /* remove the card */
1628 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001629 card->remove(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301630
Lars-Peter Clausen0aaae522011-04-30 19:45:47 +02001631 snd_soc_dapm_free(&card->dapm);
1632
Vinod Koulb0e26482011-01-13 22:48:02 +05301633 kfree(card->rtd);
1634 snd_card_free(card->snd_card);
1635 return 0;
1636
1637}
1638
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001639/* removes a socdev */
1640static int soc_remove(struct platform_device *pdev)
1641{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001642 struct snd_soc_card *card = platform_get_drvdata(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001643
Mark Brownc5af3a22008-11-28 13:29:45 +00001644 snd_soc_unregister_card(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001645 return 0;
1646}
1647
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001648int snd_soc_poweroff(struct device *dev)
Mark Brown51737472009-06-22 13:16:51 +01001649{
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001650 struct snd_soc_card *card = dev_get_drvdata(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001651 int i;
Mark Brown51737472009-06-22 13:16:51 +01001652
1653 if (!card->instantiated)
Mark Brown416356f2009-06-30 19:05:15 +01001654 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001655
1656 /* Flush out pmdown_time work - we actually do want to run it
1657 * now, we're shutting down so no imminent restart. */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001658 for (i = 0; i < card->num_rtd; i++) {
1659 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
Tejun Heo5b84ba22010-12-11 17:51:26 +01001660 flush_delayed_work_sync(&rtd->delayed_work);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001661 }
Mark Brown51737472009-06-22 13:16:51 +01001662
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001663 snd_soc_dapm_shutdown(card);
Mark Brown416356f2009-06-30 19:05:15 +01001664
1665 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001666}
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001667EXPORT_SYMBOL_GPL(snd_soc_poweroff);
Mark Brown51737472009-06-22 13:16:51 +01001668
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001669const struct dev_pm_ops snd_soc_pm_ops = {
Mark Brown5aa44b12012-01-31 15:30:28 +00001670 SET_SYSTEM_SLEEP_PM_OPS(snd_soc_suspend, snd_soc_resume)
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001671 .poweroff = snd_soc_poweroff,
Mark Brown416356f2009-06-30 19:05:15 +01001672};
Stephen Warrendeb26072011-04-05 19:35:30 -06001673EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
Mark Brown416356f2009-06-30 19:05:15 +01001674
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001675/* ASoC platform driver */
1676static struct platform_driver soc_driver = {
1677 .driver = {
1678 .name = "soc-audio",
Kay Sievers8b45a202008-04-14 13:33:36 +02001679 .owner = THIS_MODULE,
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001680 .pm = &snd_soc_pm_ops,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001681 },
1682 .probe = soc_probe,
1683 .remove = soc_remove,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001684};
1685
Mark Brown096e49d2009-07-05 15:12:22 +01001686/**
1687 * snd_soc_codec_volatile_register: Report if a register is volatile.
1688 *
1689 * @codec: CODEC to query.
1690 * @reg: Register to query.
1691 *
1692 * Boolean function indiciating if a CODEC register is volatile.
1693 */
Mark Brown181e0552011-01-24 14:05:25 +00001694int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
1695 unsigned int reg)
Mark Brown096e49d2009-07-05 15:12:22 +01001696{
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00001697 if (codec->volatile_register)
1698 return codec->volatile_register(codec, reg);
Mark Brown096e49d2009-07-05 15:12:22 +01001699 else
1700 return 0;
1701}
1702EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1703
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001704/**
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001705 * snd_soc_codec_readable_register: Report if a register is readable.
1706 *
1707 * @codec: CODEC to query.
1708 * @reg: Register to query.
1709 *
1710 * Boolean function indicating if a CODEC register is readable.
1711 */
1712int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
1713 unsigned int reg)
1714{
1715 if (codec->readable_register)
1716 return codec->readable_register(codec, reg);
1717 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02001718 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001719}
1720EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
1721
1722/**
1723 * snd_soc_codec_writable_register: Report if a register is writable.
1724 *
1725 * @codec: CODEC to query.
1726 * @reg: Register to query.
1727 *
1728 * Boolean function indicating if a CODEC register is writable.
1729 */
1730int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
1731 unsigned int reg)
1732{
1733 if (codec->writable_register)
1734 return codec->writable_register(codec, reg);
1735 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02001736 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001737}
1738EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
1739
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001740int snd_soc_platform_read(struct snd_soc_platform *platform,
1741 unsigned int reg)
1742{
1743 unsigned int ret;
1744
1745 if (!platform->driver->read) {
1746 dev_err(platform->dev, "platform has no read back\n");
1747 return -1;
1748 }
1749
1750 ret = platform->driver->read(platform, reg);
1751 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01001752 trace_snd_soc_preg_read(platform, reg, ret);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001753
1754 return ret;
1755}
1756EXPORT_SYMBOL_GPL(snd_soc_platform_read);
1757
1758int snd_soc_platform_write(struct snd_soc_platform *platform,
1759 unsigned int reg, unsigned int val)
1760{
1761 if (!platform->driver->write) {
1762 dev_err(platform->dev, "platform has no write back\n");
1763 return -1;
1764 }
1765
1766 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01001767 trace_snd_soc_preg_write(platform, reg, val);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01001768 return platform->driver->write(platform, reg, val);
1769}
1770EXPORT_SYMBOL_GPL(snd_soc_platform_write);
1771
Dimitris Papastamos239c9702011-03-24 13:45:18 +00001772/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001773 * snd_soc_new_ac97_codec - initailise AC97 device
1774 * @codec: audio codec
1775 * @ops: AC97 bus operations
1776 * @num: AC97 codec number
1777 *
1778 * Initialises AC97 codec resources for use by ad-hoc devices only.
1779 */
1780int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1781 struct snd_ac97_bus_ops *ops, int num)
1782{
1783 mutex_lock(&codec->mutex);
1784
1785 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1786 if (codec->ac97 == NULL) {
1787 mutex_unlock(&codec->mutex);
1788 return -ENOMEM;
1789 }
1790
1791 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1792 if (codec->ac97->bus == NULL) {
1793 kfree(codec->ac97);
1794 codec->ac97 = NULL;
1795 mutex_unlock(&codec->mutex);
1796 return -ENOMEM;
1797 }
1798
1799 codec->ac97->bus->ops = ops;
1800 codec->ac97->num = num;
Mika Westerberg0562f782010-10-13 11:30:32 +03001801
1802 /*
1803 * Mark the AC97 device to be created by us. This way we ensure that the
1804 * device will be registered with the device subsystem later on.
1805 */
1806 codec->ac97_created = 1;
1807
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001808 mutex_unlock(&codec->mutex);
1809 return 0;
1810}
1811EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1812
1813/**
1814 * snd_soc_free_ac97_codec - free AC97 codec device
1815 * @codec: audio codec
1816 *
1817 * Frees AC97 codec device resources.
1818 */
1819void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1820{
1821 mutex_lock(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001822#ifdef CONFIG_SND_SOC_AC97_BUS
1823 soc_unregister_ac97_dai_link(codec);
1824#endif
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001825 kfree(codec->ac97->bus);
1826 kfree(codec->ac97);
1827 codec->ac97 = NULL;
Mika Westerberg0562f782010-10-13 11:30:32 +03001828 codec->ac97_created = 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001829 mutex_unlock(&codec->mutex);
1830}
1831EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1832
Mark Brownc3753702010-11-01 15:41:57 -04001833unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
1834{
1835 unsigned int ret;
1836
Mark Brownc3acec22010-12-02 16:15:29 +00001837 ret = codec->read(codec, reg);
Mark Brownc3753702010-11-01 15:41:57 -04001838 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
Mark Browna8b1d342010-11-03 18:05:58 -04001839 trace_snd_soc_reg_read(codec, reg, ret);
Mark Brownc3753702010-11-01 15:41:57 -04001840
1841 return ret;
1842}
1843EXPORT_SYMBOL_GPL(snd_soc_read);
1844
1845unsigned int snd_soc_write(struct snd_soc_codec *codec,
1846 unsigned int reg, unsigned int val)
1847{
1848 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
Mark Browna8b1d342010-11-03 18:05:58 -04001849 trace_snd_soc_reg_write(codec, reg, val);
Mark Brownc3acec22010-12-02 16:15:29 +00001850 return codec->write(codec, reg, val);
Mark Brownc3753702010-11-01 15:41:57 -04001851}
1852EXPORT_SYMBOL_GPL(snd_soc_write);
1853
Dimitris Papastamos5fb609d2011-03-22 10:37:03 +00001854unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
1855 unsigned int reg, const void *data, size_t len)
1856{
1857 return codec->bulk_write_raw(codec, reg, data, len);
1858}
1859EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
1860
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001861/**
1862 * snd_soc_update_bits - update codec register bits
1863 * @codec: audio codec
1864 * @reg: codec register
1865 * @mask: register mask
1866 * @value: new value
1867 *
1868 * Writes new register value.
1869 *
Timur Tabi180c3292011-01-10 15:58:13 -06001870 * Returns 1 for change, 0 for no change, or negative error code.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001871 */
1872int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001873 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001874{
Mark Brown8a713da2011-12-03 12:33:55 +00001875 bool change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001876 unsigned int old, new;
Timur Tabi180c3292011-01-10 15:58:13 -06001877 int ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001878
Mark Brown8a713da2011-12-03 12:33:55 +00001879 if (codec->using_regmap) {
1880 ret = regmap_update_bits_check(codec->control_data, reg,
1881 mask, value, &change);
1882 } else {
1883 ret = snd_soc_read(codec, reg);
Timur Tabi180c3292011-01-10 15:58:13 -06001884 if (ret < 0)
1885 return ret;
Mark Brown8a713da2011-12-03 12:33:55 +00001886
1887 old = ret;
1888 new = (old & ~mask) | (value & mask);
1889 change = old != new;
1890 if (change)
1891 ret = snd_soc_write(codec, reg, new);
Timur Tabi180c3292011-01-10 15:58:13 -06001892 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001893
Mark Brown8a713da2011-12-03 12:33:55 +00001894 if (ret < 0)
1895 return ret;
1896
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001897 return change;
1898}
1899EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1900
1901/**
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001902 * snd_soc_update_bits_locked - update codec register bits
1903 * @codec: audio codec
1904 * @reg: codec register
1905 * @mask: register mask
1906 * @value: new value
1907 *
1908 * Writes new register value, and takes the codec mutex.
1909 *
1910 * Returns 1 for change else 0.
1911 */
Mark Browndd1b3d52009-12-04 14:22:03 +00001912int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1913 unsigned short reg, unsigned int mask,
1914 unsigned int value)
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001915{
1916 int change;
1917
1918 mutex_lock(&codec->mutex);
1919 change = snd_soc_update_bits(codec, reg, mask, value);
1920 mutex_unlock(&codec->mutex);
1921
1922 return change;
1923}
Mark Browndd1b3d52009-12-04 14:22:03 +00001924EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001925
1926/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001927 * snd_soc_test_bits - test register for change
1928 * @codec: audio codec
1929 * @reg: codec register
1930 * @mask: register mask
1931 * @value: new value
1932 *
1933 * Tests a register with a new value and checks if the new value is
1934 * different from the old value.
1935 *
1936 * Returns 1 for change else 0.
1937 */
1938int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001939 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001940{
1941 int change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001942 unsigned int old, new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001943
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001944 old = snd_soc_read(codec, reg);
1945 new = (old & ~mask) | value;
1946 change = old != new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001947
1948 return change;
1949}
1950EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1951
1952/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001953 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1954 * @substream: the pcm substream
1955 * @hw: the hardware parameters
1956 *
1957 * Sets the substream runtime hardware parameters.
1958 */
1959int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1960 const struct snd_pcm_hardware *hw)
1961{
1962 struct snd_pcm_runtime *runtime = substream->runtime;
1963 runtime->hw.info = hw->info;
1964 runtime->hw.formats = hw->formats;
1965 runtime->hw.period_bytes_min = hw->period_bytes_min;
1966 runtime->hw.period_bytes_max = hw->period_bytes_max;
1967 runtime->hw.periods_min = hw->periods_min;
1968 runtime->hw.periods_max = hw->periods_max;
1969 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1970 runtime->hw.fifo_size = hw->fifo_size;
1971 return 0;
1972}
1973EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1974
1975/**
1976 * snd_soc_cnew - create new control
1977 * @_template: control template
1978 * @data: control private data
Mark Brownac11a2b2009-01-01 12:18:17 +00001979 * @long_name: control long name
Mark Brownefb7ac32011-03-08 17:23:24 +00001980 * @prefix: control name prefix
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001981 *
1982 * Create a new mixer control from a template control.
1983 *
1984 * Returns 0 for success, else error.
1985 */
1986struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
Mark Brownefb7ac32011-03-08 17:23:24 +00001987 void *data, char *long_name,
1988 const char *prefix)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001989{
1990 struct snd_kcontrol_new template;
Mark Brownefb7ac32011-03-08 17:23:24 +00001991 struct snd_kcontrol *kcontrol;
1992 char *name = NULL;
1993 int name_len;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001994
1995 memcpy(&template, _template, sizeof(template));
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001996 template.index = 0;
1997
Mark Brownefb7ac32011-03-08 17:23:24 +00001998 if (!long_name)
1999 long_name = template.name;
2000
2001 if (prefix) {
2002 name_len = strlen(long_name) + strlen(prefix) + 2;
Axel Lin57cf9d42011-08-20 11:03:44 +08002003 name = kmalloc(name_len, GFP_KERNEL);
Mark Brownefb7ac32011-03-08 17:23:24 +00002004 if (!name)
2005 return NULL;
2006
2007 snprintf(name, name_len, "%s %s", prefix, long_name);
2008
2009 template.name = name;
2010 } else {
2011 template.name = long_name;
2012 }
2013
2014 kcontrol = snd_ctl_new1(&template, data);
2015
2016 kfree(name);
2017
2018 return kcontrol;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002019}
2020EXPORT_SYMBOL_GPL(snd_soc_cnew);
2021
Liam Girdwood022658b2012-02-03 17:43:09 +00002022static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2023 const struct snd_kcontrol_new *controls, int num_controls,
2024 const char *prefix, void *data)
2025{
2026 int err, i;
2027
2028 for (i = 0; i < num_controls; i++) {
2029 const struct snd_kcontrol_new *control = &controls[i];
2030 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2031 control->name, prefix));
2032 if (err < 0) {
2033 dev_err(dev, "Failed to add %s: %d\n", control->name, err);
2034 return err;
2035 }
2036 }
2037
2038 return 0;
2039}
2040
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002041/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002042 * snd_soc_add_codec_controls - add an array of controls to a codec.
2043 * Convenience function to add a list of controls. Many codecs were
Ian Molton3e8e1952009-01-09 00:23:21 +00002044 * duplicating this code.
2045 *
2046 * @codec: codec to add controls to
2047 * @controls: array of controls to add
2048 * @num_controls: number of elements in the array
2049 *
2050 * Return 0 for success, else error.
2051 */
Liam Girdwood022658b2012-02-03 17:43:09 +00002052int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
Ian Molton3e8e1952009-01-09 00:23:21 +00002053 const struct snd_kcontrol_new *controls, int num_controls)
2054{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002055 struct snd_card *card = codec->card->snd_card;
Ian Molton3e8e1952009-01-09 00:23:21 +00002056
Liam Girdwood022658b2012-02-03 17:43:09 +00002057 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2058 codec->name_prefix, codec);
Ian Molton3e8e1952009-01-09 00:23:21 +00002059}
Liam Girdwood022658b2012-02-03 17:43:09 +00002060EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
Ian Molton3e8e1952009-01-09 00:23:21 +00002061
2062/**
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002063 * snd_soc_add_platform_controls - add an array of controls to a platform.
Liam Girdwood022658b2012-02-03 17:43:09 +00002064 * Convenience function to add a list of controls.
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002065 *
2066 * @platform: platform to add controls to
2067 * @controls: array of controls to add
2068 * @num_controls: number of elements in the array
2069 *
2070 * Return 0 for success, else error.
2071 */
2072int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2073 const struct snd_kcontrol_new *controls, int num_controls)
2074{
2075 struct snd_card *card = platform->card->snd_card;
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002076
Liam Girdwood022658b2012-02-03 17:43:09 +00002077 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2078 NULL, platform);
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002079}
2080EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2081
2082/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002083 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2084 * Convenience function to add a list of controls.
2085 *
2086 * @soc_card: SoC card to add controls to
2087 * @controls: array of controls to add
2088 * @num_controls: number of elements in the array
2089 *
2090 * Return 0 for success, else error.
2091 */
2092int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2093 const struct snd_kcontrol_new *controls, int num_controls)
2094{
2095 struct snd_card *card = soc_card->snd_card;
2096
2097 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2098 NULL, soc_card);
2099}
2100EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2101
2102/**
2103 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2104 * Convienience function to add a list of controls.
2105 *
2106 * @dai: DAI to add controls to
2107 * @controls: array of controls to add
2108 * @num_controls: number of elements in the array
2109 *
2110 * Return 0 for success, else error.
2111 */
2112int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2113 const struct snd_kcontrol_new *controls, int num_controls)
2114{
2115 struct snd_card *card = dai->card->snd_card;
2116
2117 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2118 NULL, dai);
2119}
2120EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2121
2122/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002123 * snd_soc_info_enum_double - enumerated double mixer info callback
2124 * @kcontrol: mixer control
2125 * @uinfo: control element information
2126 *
2127 * Callback to provide information about a double enumerated
2128 * mixer control.
2129 *
2130 * Returns 0 for success.
2131 */
2132int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2133 struct snd_ctl_elem_info *uinfo)
2134{
2135 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2136
2137 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2138 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002139 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002140
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002141 if (uinfo->value.enumerated.item > e->max - 1)
2142 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002143 strcpy(uinfo->value.enumerated.name,
2144 e->texts[uinfo->value.enumerated.item]);
2145 return 0;
2146}
2147EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2148
2149/**
2150 * snd_soc_get_enum_double - enumerated double mixer get callback
2151 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002152 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002153 *
2154 * Callback to get the value of a double enumerated mixer.
2155 *
2156 * Returns 0 for success.
2157 */
2158int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2159 struct snd_ctl_elem_value *ucontrol)
2160{
2161 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2162 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002163 unsigned int val, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002164
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002165 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002166 ;
2167 val = snd_soc_read(codec, e->reg);
Mark Brown3ff3f642008-05-19 12:32:25 +02002168 ucontrol->value.enumerated.item[0]
2169 = (val >> e->shift_l) & (bitmask - 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002170 if (e->shift_l != e->shift_r)
2171 ucontrol->value.enumerated.item[1] =
2172 (val >> e->shift_r) & (bitmask - 1);
2173
2174 return 0;
2175}
2176EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2177
2178/**
2179 * snd_soc_put_enum_double - enumerated double mixer put callback
2180 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002181 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002182 *
2183 * Callback to set the value of a double enumerated mixer.
2184 *
2185 * Returns 0 for success.
2186 */
2187int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2188 struct snd_ctl_elem_value *ucontrol)
2189{
2190 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2191 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002192 unsigned int val;
2193 unsigned int mask, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002194
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002195 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002196 ;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002197 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002198 return -EINVAL;
2199 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2200 mask = (bitmask - 1) << e->shift_l;
2201 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002202 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002203 return -EINVAL;
2204 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2205 mask |= (bitmask - 1) << e->shift_r;
2206 }
2207
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002208 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002209}
2210EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2211
2212/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002213 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
2214 * @kcontrol: mixer control
2215 * @ucontrol: control element information
2216 *
2217 * Callback to get the value of a double semi enumerated mixer.
2218 *
2219 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2220 * used for handling bitfield coded enumeration for example.
2221 *
2222 * Returns 0 for success.
2223 */
2224int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2225 struct snd_ctl_elem_value *ucontrol)
2226{
2227 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02002228 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002229 unsigned int reg_val, val, mux;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002230
2231 reg_val = snd_soc_read(codec, e->reg);
2232 val = (reg_val >> e->shift_l) & e->mask;
2233 for (mux = 0; mux < e->max; mux++) {
2234 if (val == e->values[mux])
2235 break;
2236 }
2237 ucontrol->value.enumerated.item[0] = mux;
2238 if (e->shift_l != e->shift_r) {
2239 val = (reg_val >> e->shift_r) & e->mask;
2240 for (mux = 0; mux < e->max; mux++) {
2241 if (val == e->values[mux])
2242 break;
2243 }
2244 ucontrol->value.enumerated.item[1] = mux;
2245 }
2246
2247 return 0;
2248}
2249EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2250
2251/**
2252 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
2253 * @kcontrol: mixer control
2254 * @ucontrol: control element information
2255 *
2256 * Callback to set the value of a double semi enumerated mixer.
2257 *
2258 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2259 * used for handling bitfield coded enumeration for example.
2260 *
2261 * Returns 0 for success.
2262 */
2263int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2264 struct snd_ctl_elem_value *ucontrol)
2265{
2266 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02002267 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002268 unsigned int val;
2269 unsigned int mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002270
2271 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2272 return -EINVAL;
2273 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2274 mask = e->mask << e->shift_l;
2275 if (e->shift_l != e->shift_r) {
2276 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2277 return -EINVAL;
2278 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2279 mask |= e->mask << e->shift_r;
2280 }
2281
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002282 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002283}
2284EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2285
2286/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002287 * snd_soc_info_enum_ext - external enumerated single mixer info callback
2288 * @kcontrol: mixer control
2289 * @uinfo: control element information
2290 *
2291 * Callback to provide information about an external enumerated
2292 * single mixer.
2293 *
2294 * Returns 0 for success.
2295 */
2296int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_info *uinfo)
2298{
2299 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2300
2301 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2302 uinfo->count = 1;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002303 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002304
Jon Smirlf8ba0b72008-07-29 11:42:27 +01002305 if (uinfo->value.enumerated.item > e->max - 1)
2306 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002307 strcpy(uinfo->value.enumerated.name,
2308 e->texts[uinfo->value.enumerated.item]);
2309 return 0;
2310}
2311EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
2312
2313/**
2314 * snd_soc_info_volsw_ext - external single mixer info callback
2315 * @kcontrol: mixer control
2316 * @uinfo: control element information
2317 *
2318 * Callback to provide information about a single external mixer control.
2319 *
2320 * Returns 0 for success.
2321 */
2322int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
2323 struct snd_ctl_elem_info *uinfo)
2324{
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002325 int max = kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002326
Mark Brownfd5dfad2009-04-15 21:37:46 +01002327 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002328 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2329 else
2330 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2331
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002332 uinfo->count = 1;
2333 uinfo->value.integer.min = 0;
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002334 uinfo->value.integer.max = max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002335 return 0;
2336}
2337EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
2338
2339/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002340 * snd_soc_info_volsw - single mixer info callback
2341 * @kcontrol: mixer control
2342 * @uinfo: control element information
2343 *
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002344 * Callback to provide information about a single mixer control, or a double
2345 * mixer control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002346 *
2347 * Returns 0 for success.
2348 */
2349int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2350 struct snd_ctl_elem_info *uinfo)
2351{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002352 struct soc_mixer_control *mc =
2353 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002354 int platform_max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002355
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002356 if (!mc->platform_max)
2357 mc->platform_max = mc->max;
2358 platform_max = mc->platform_max;
2359
2360 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002361 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2362 else
2363 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2364
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002365 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002366 uinfo->value.integer.min = 0;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002367 uinfo->value.integer.max = platform_max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002368 return 0;
2369}
2370EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2371
2372/**
2373 * snd_soc_get_volsw - single mixer get callback
2374 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002375 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002376 *
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002377 * Callback to get the value of a single mixer control, or a double mixer
2378 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002379 *
2380 * Returns 0 for success.
2381 */
2382int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2383 struct snd_ctl_elem_value *ucontrol)
2384{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002385 struct soc_mixer_control *mc =
2386 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002387 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002388 unsigned int reg = mc->reg;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002389 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002390 unsigned int shift = mc->shift;
2391 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002392 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002393 unsigned int mask = (1 << fls(max)) - 1;
2394 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002395
2396 ucontrol->value.integer.value[0] =
2397 (snd_soc_read(codec, reg) >> shift) & mask;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002398 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002399 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002400 max - ucontrol->value.integer.value[0];
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002401
2402 if (snd_soc_volsw_is_stereo(mc)) {
2403 if (reg == reg2)
2404 ucontrol->value.integer.value[1] =
2405 (snd_soc_read(codec, reg) >> rshift) & mask;
2406 else
2407 ucontrol->value.integer.value[1] =
2408 (snd_soc_read(codec, reg2) >> shift) & mask;
2409 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002410 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002411 max - ucontrol->value.integer.value[1];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002412 }
2413
2414 return 0;
2415}
2416EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2417
2418/**
2419 * snd_soc_put_volsw - single mixer put callback
2420 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002421 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002422 *
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002423 * Callback to set the value of a single mixer control, or a double mixer
2424 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002425 *
2426 * Returns 0 for success.
2427 */
2428int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2429 struct snd_ctl_elem_value *ucontrol)
2430{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002431 struct soc_mixer_control *mc =
2432 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002433 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002434 unsigned int reg = mc->reg;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002435 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002436 unsigned int shift = mc->shift;
2437 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002438 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002439 unsigned int mask = (1 << fls(max)) - 1;
2440 unsigned int invert = mc->invert;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002441 int err;
2442 bool type_2r = 0;
2443 unsigned int val2 = 0;
2444 unsigned int val, val_mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002445
2446 val = (ucontrol->value.integer.value[0] & mask);
2447 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002448 val = max - val;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002449 val_mask = mask << shift;
2450 val = val << shift;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002451 if (snd_soc_volsw_is_stereo(mc)) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002452 val2 = (ucontrol->value.integer.value[1] & mask);
2453 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002454 val2 = max - val2;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002455 if (reg == reg2) {
2456 val_mask |= mask << rshift;
2457 val |= val2 << rshift;
2458 } else {
2459 val2 = val2 << shift;
2460 type_2r = 1;
2461 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002462 }
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002463 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
Mark Brown3ff3f642008-05-19 12:32:25 +02002464 if (err < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002465 return err;
2466
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002467 if (type_2r)
2468 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2469
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002470 return err;
2471}
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002472EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002473
Mark Browne13ac2e2008-05-28 17:58:05 +01002474/**
2475 * snd_soc_info_volsw_s8 - signed mixer info callback
2476 * @kcontrol: mixer control
2477 * @uinfo: control element information
2478 *
2479 * Callback to provide information about a signed mixer control.
2480 *
2481 * Returns 0 for success.
2482 */
2483int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_info *uinfo)
2485{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002486 struct soc_mixer_control *mc =
2487 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002488 int platform_max;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002489 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002490
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002491 if (!mc->platform_max)
2492 mc->platform_max = mc->max;
2493 platform_max = mc->platform_max;
2494
Mark Browne13ac2e2008-05-28 17:58:05 +01002495 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2496 uinfo->count = 2;
2497 uinfo->value.integer.min = 0;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002498 uinfo->value.integer.max = platform_max - min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002499 return 0;
2500}
2501EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2502
2503/**
2504 * snd_soc_get_volsw_s8 - signed mixer get callback
2505 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002506 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002507 *
2508 * Callback to get the value of a signed mixer control.
2509 *
2510 * Returns 0 for success.
2511 */
2512int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2514{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002515 struct soc_mixer_control *mc =
2516 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002517 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002518 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002519 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002520 int val = snd_soc_read(codec, reg);
2521
2522 ucontrol->value.integer.value[0] =
2523 ((signed char)(val & 0xff))-min;
2524 ucontrol->value.integer.value[1] =
2525 ((signed char)((val >> 8) & 0xff))-min;
2526 return 0;
2527}
2528EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2529
2530/**
2531 * snd_soc_put_volsw_sgn - signed mixer put callback
2532 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002533 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002534 *
2535 * Callback to set the value of a signed mixer control.
2536 *
2537 * Returns 0 for success.
2538 */
2539int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2540 struct snd_ctl_elem_value *ucontrol)
2541{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002542 struct soc_mixer_control *mc =
2543 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002544 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002545 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002546 int min = mc->min;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002547 unsigned int val;
Mark Browne13ac2e2008-05-28 17:58:05 +01002548
2549 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2550 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2551
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002552 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
Mark Browne13ac2e2008-05-28 17:58:05 +01002553}
2554EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2555
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002556/**
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002557 * snd_soc_limit_volume - Set new limit to an existing volume control.
2558 *
2559 * @codec: where to look for the control
2560 * @name: Name of the control
2561 * @max: new maximum limit
2562 *
2563 * Return 0 for success, else error.
2564 */
2565int snd_soc_limit_volume(struct snd_soc_codec *codec,
2566 const char *name, int max)
2567{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002568 struct snd_card *card = codec->card->snd_card;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002569 struct snd_kcontrol *kctl;
2570 struct soc_mixer_control *mc;
2571 int found = 0;
2572 int ret = -EINVAL;
2573
2574 /* Sanity check for name and max */
2575 if (unlikely(!name || max <= 0))
2576 return -EINVAL;
2577
2578 list_for_each_entry(kctl, &card->controls, list) {
2579 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2580 found = 1;
2581 break;
2582 }
2583 }
2584 if (found) {
2585 mc = (struct soc_mixer_control *)kctl->private_value;
2586 if (max <= mc->max) {
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002587 mc->platform_max = max;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002588 ret = 0;
2589 }
2590 }
2591 return ret;
2592}
2593EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2594
2595/**
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002596 * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
2597 * mixer info callback
2598 * @kcontrol: mixer control
2599 * @uinfo: control element information
2600 *
2601 * Returns 0 for success.
2602 */
2603int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2604 struct snd_ctl_elem_info *uinfo)
2605{
2606 struct soc_mixer_control *mc =
2607 (struct soc_mixer_control *)kcontrol->private_value;
2608 int max = mc->max;
2609 int min = mc->min;
2610
2611 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2612 uinfo->count = 2;
2613 uinfo->value.integer.min = 0;
2614 uinfo->value.integer.max = max-min;
2615
2616 return 0;
2617}
2618EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
2619
2620/**
2621 * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
2622 * mixer get callback
2623 * @kcontrol: mixer control
2624 * @uinfo: control element information
2625 *
2626 * Returns 0 for success.
2627 */
2628int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2629 struct snd_ctl_elem_value *ucontrol)
2630{
2631 struct soc_mixer_control *mc =
2632 (struct soc_mixer_control *)kcontrol->private_value;
2633 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2634 unsigned int mask = (1<<mc->shift)-1;
2635 int min = mc->min;
2636 int val = snd_soc_read(codec, mc->reg) & mask;
2637 int valr = snd_soc_read(codec, mc->rreg) & mask;
2638
Stuart Longland20630c72010-06-18 12:56:10 +10002639 ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
2640 ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002641 return 0;
2642}
2643EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
2644
2645/**
2646 * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
2647 * mixer put callback
2648 * @kcontrol: mixer control
2649 * @uinfo: control element information
2650 *
2651 * Returns 0 for success.
2652 */
2653int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
2654 struct snd_ctl_elem_value *ucontrol)
2655{
2656 struct soc_mixer_control *mc =
2657 (struct soc_mixer_control *)kcontrol->private_value;
2658 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2659 unsigned int mask = (1<<mc->shift)-1;
2660 int min = mc->min;
2661 int ret;
2662 unsigned int val, valr, oval, ovalr;
2663
2664 val = ((ucontrol->value.integer.value[0]+min) & 0xff);
2665 val &= mask;
2666 valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
2667 valr &= mask;
2668
2669 oval = snd_soc_read(codec, mc->reg) & mask;
2670 ovalr = snd_soc_read(codec, mc->rreg) & mask;
2671
2672 ret = 0;
2673 if (oval != val) {
2674 ret = snd_soc_write(codec, mc->reg, val);
2675 if (ret < 0)
Mark Brownf1df5ae2010-06-15 15:14:31 +01002676 return ret;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002677 }
2678 if (ovalr != valr) {
2679 ret = snd_soc_write(codec, mc->rreg, valr);
2680 if (ret < 0)
Mark Brownf1df5ae2010-06-15 15:14:31 +01002681 return ret;
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02002682 }
2683
2684 return 0;
2685}
2686EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2687
2688/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002689 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2690 * @dai: DAI
2691 * @clk_id: DAI specific clock ID
2692 * @freq: new clock frequency in Hz
2693 * @dir: new clock direction - input/output.
2694 *
2695 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2696 */
2697int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2698 unsigned int freq, int dir)
2699{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002700 if (dai->driver && dai->driver->ops->set_sysclk)
2701 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00002702 else if (dai->codec && dai->codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01002703 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
Mark Brownec4ee522011-03-07 20:58:11 +00002704 freq, dir);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002705 else
2706 return -EINVAL;
2707}
2708EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2709
2710/**
Mark Brownec4ee522011-03-07 20:58:11 +00002711 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
2712 * @codec: CODEC
2713 * @clk_id: DAI specific clock ID
Mark Brownda1c6ea2011-08-24 20:09:01 +01002714 * @source: Source for the clock
Mark Brownec4ee522011-03-07 20:58:11 +00002715 * @freq: new clock frequency in Hz
2716 * @dir: new clock direction - input/output.
2717 *
2718 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
2719 */
2720int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
Mark Brownda1c6ea2011-08-24 20:09:01 +01002721 int source, unsigned int freq, int dir)
Mark Brownec4ee522011-03-07 20:58:11 +00002722{
2723 if (codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01002724 return codec->driver->set_sysclk(codec, clk_id, source,
2725 freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00002726 else
2727 return -EINVAL;
2728}
2729EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
2730
2731/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002732 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2733 * @dai: DAI
Mark Brownac11a2b2009-01-01 12:18:17 +00002734 * @div_id: DAI specific clock divider ID
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002735 * @div: new clock divisor.
2736 *
2737 * Configures the clock dividers. This is used to derive the best DAI bit and
2738 * frame clocks from the system or master clock. It's best to set the DAI bit
2739 * and frame clocks as low as possible to save system power.
2740 */
2741int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2742 int div_id, int div)
2743{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002744 if (dai->driver && dai->driver->ops->set_clkdiv)
2745 return dai->driver->ops->set_clkdiv(dai, div_id, div);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002746 else
2747 return -EINVAL;
2748}
2749EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2750
2751/**
2752 * snd_soc_dai_set_pll - configure DAI PLL.
2753 * @dai: DAI
2754 * @pll_id: DAI specific PLL ID
Mark Brown85488032009-09-05 18:52:16 +01002755 * @source: DAI specific source for the PLL
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002756 * @freq_in: PLL input clock frequency in Hz
2757 * @freq_out: requested PLL output clock frequency in Hz
2758 *
2759 * Configures and enables PLL to generate output clock based on input clock.
2760 */
Mark Brown85488032009-09-05 18:52:16 +01002761int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2762 unsigned int freq_in, unsigned int freq_out)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002763{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002764 if (dai->driver && dai->driver->ops->set_pll)
2765 return dai->driver->ops->set_pll(dai, pll_id, source,
Mark Brown85488032009-09-05 18:52:16 +01002766 freq_in, freq_out);
Mark Brownec4ee522011-03-07 20:58:11 +00002767 else if (dai->codec && dai->codec->driver->set_pll)
2768 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
2769 freq_in, freq_out);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002770 else
2771 return -EINVAL;
2772}
2773EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2774
Mark Brownec4ee522011-03-07 20:58:11 +00002775/*
2776 * snd_soc_codec_set_pll - configure codec PLL.
2777 * @codec: CODEC
2778 * @pll_id: DAI specific PLL ID
2779 * @source: DAI specific source for the PLL
2780 * @freq_in: PLL input clock frequency in Hz
2781 * @freq_out: requested PLL output clock frequency in Hz
2782 *
2783 * Configures and enables PLL to generate output clock based on input clock.
2784 */
2785int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
2786 unsigned int freq_in, unsigned int freq_out)
2787{
2788 if (codec->driver->set_pll)
2789 return codec->driver->set_pll(codec, pll_id, source,
2790 freq_in, freq_out);
2791 else
2792 return -EINVAL;
2793}
2794EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2795
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002796/**
2797 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2798 * @dai: DAI
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002799 * @fmt: SND_SOC_DAIFMT_ format value.
2800 *
2801 * Configures the DAI hardware format and clocking.
2802 */
2803int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2804{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002805 if (dai->driver && dai->driver->ops->set_fmt)
2806 return dai->driver->ops->set_fmt(dai, fmt);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002807 else
2808 return -EINVAL;
2809}
2810EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2811
2812/**
2813 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2814 * @dai: DAI
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002815 * @tx_mask: bitmask representing active TX slots.
2816 * @rx_mask: bitmask representing active RX slots.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002817 * @slots: Number of slots in use.
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002818 * @slot_width: Width in bits for each slot.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002819 *
2820 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2821 * specific.
2822 */
2823int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002824 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002825{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002826 if (dai->driver && dai->driver->ops->set_tdm_slot)
2827 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002828 slots, slot_width);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002829 else
2830 return -EINVAL;
2831}
2832EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2833
2834/**
Barry Song472df3c2009-09-12 01:16:29 +08002835 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2836 * @dai: DAI
2837 * @tx_num: how many TX channels
2838 * @tx_slot: pointer to an array which imply the TX slot number channel
2839 * 0~num-1 uses
2840 * @rx_num: how many RX channels
2841 * @rx_slot: pointer to an array which imply the RX slot number channel
2842 * 0~num-1 uses
2843 *
2844 * configure the relationship between channel number and TDM slot number.
2845 */
2846int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2847 unsigned int tx_num, unsigned int *tx_slot,
2848 unsigned int rx_num, unsigned int *rx_slot)
2849{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002850 if (dai->driver && dai->driver->ops->set_channel_map)
2851 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
Barry Song472df3c2009-09-12 01:16:29 +08002852 rx_num, rx_slot);
2853 else
2854 return -EINVAL;
2855}
2856EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2857
2858/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002859 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2860 * @dai: DAI
2861 * @tristate: tristate enable
2862 *
2863 * Tristates the DAI so that others can use it.
2864 */
2865int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2866{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002867 if (dai->driver && dai->driver->ops->set_tristate)
2868 return dai->driver->ops->set_tristate(dai, tristate);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002869 else
2870 return -EINVAL;
2871}
2872EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2873
2874/**
2875 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2876 * @dai: DAI
2877 * @mute: mute enable
2878 *
2879 * Mutes the DAI DAC.
2880 */
2881int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2882{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002883 if (dai->driver && dai->driver->ops->digital_mute)
2884 return dai->driver->ops->digital_mute(dai, mute);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002885 else
2886 return -EINVAL;
2887}
2888EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2889
Mark Brownc5af3a22008-11-28 13:29:45 +00002890/**
2891 * snd_soc_register_card - Register a card with the ASoC core
2892 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002893 * @card: Card to register
Mark Brownc5af3a22008-11-28 13:29:45 +00002894 *
Mark Brownc5af3a22008-11-28 13:29:45 +00002895 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05302896int snd_soc_register_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00002897{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002898 int i;
2899
Mark Brownc5af3a22008-11-28 13:29:45 +00002900 if (!card->name || !card->dev)
2901 return -EINVAL;
2902
Stephen Warren5a504962011-12-21 10:40:59 -07002903 for (i = 0; i < card->num_links; i++) {
2904 struct snd_soc_dai_link *link = &card->dai_link[i];
2905
2906 /*
2907 * Codec must be specified by 1 of name or OF node,
2908 * not both or neither.
2909 */
2910 if (!!link->codec_name == !!link->codec_of_node) {
2911 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002912 "Neither/both codec name/of_node are set for %s\n",
2913 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002914 return -EINVAL;
2915 }
2916
2917 /*
2918 * Platform may be specified by either name or OF node, but
2919 * can be left unspecified, and a dummy platform will be used.
2920 */
2921 if (link->platform_name && link->platform_of_node) {
2922 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002923 "Both platform name/of_node are set for %s\n", link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002924 return -EINVAL;
2925 }
2926
2927 /*
2928 * CPU DAI must be specified by 1 of name or OF node,
2929 * not both or neither.
2930 */
2931 if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) {
2932 dev_err(card->dev,
Liam Girdwood3b09bb82012-01-09 12:09:29 +00002933 "Neither/both cpu_dai name/of_node are set for %s\n",
2934 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07002935 return -EINVAL;
2936 }
2937 }
2938
Mark Browned77cc12011-05-03 18:25:34 +01002939 dev_set_drvdata(card->dev, card);
2940
Stephen Warren111c6412011-01-28 14:26:35 -07002941 snd_soc_initialize_card_lists(card);
2942
Vinod Koul150dd2f2011-01-13 22:48:32 +05302943 soc_init_card_debugfs(card);
2944
Jarkko Nikula2eea3922010-11-25 17:47:38 +02002945 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
2946 (card->num_links + card->num_aux_devs),
2947 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002948 if (card->rtd == NULL)
2949 return -ENOMEM;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02002950 card->rtd_aux = &card->rtd[card->num_links];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002951
2952 for (i = 0; i < card->num_links; i++)
2953 card->rtd[i].dai_link = &card->dai_link[i];
2954
Mark Brownc5af3a22008-11-28 13:29:45 +00002955 INIT_LIST_HEAD(&card->list);
Mark Browndb432b42011-10-03 21:06:40 +01002956 INIT_LIST_HEAD(&card->dapm_dirty);
Mark Brownc5af3a22008-11-28 13:29:45 +00002957 card->instantiated = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002958 mutex_init(&card->mutex);
Mark Brownc5af3a22008-11-28 13:29:45 +00002959
2960 mutex_lock(&client_mutex);
2961 list_add(&card->list, &card_list);
Mark Brown435c5e22008-12-04 15:32:53 +00002962 snd_soc_instantiate_cards();
Mark Brownc5af3a22008-11-28 13:29:45 +00002963 mutex_unlock(&client_mutex);
2964
2965 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2966
2967 return 0;
2968}
Vinod Koul70a7ca32011-01-14 19:22:48 +05302969EXPORT_SYMBOL_GPL(snd_soc_register_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00002970
2971/**
2972 * snd_soc_unregister_card - Unregister a card with the ASoC core
2973 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002974 * @card: Card to unregister
Mark Brownc5af3a22008-11-28 13:29:45 +00002975 *
Mark Brownc5af3a22008-11-28 13:29:45 +00002976 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05302977int snd_soc_unregister_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00002978{
Vinod Koulb0e26482011-01-13 22:48:02 +05302979 if (card->instantiated)
2980 soc_cleanup_card_resources(card);
Mark Brownc5af3a22008-11-28 13:29:45 +00002981 mutex_lock(&client_mutex);
2982 list_del(&card->list);
2983 mutex_unlock(&client_mutex);
Mark Brownc5af3a22008-11-28 13:29:45 +00002984 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2985
2986 return 0;
2987}
Vinod Koul70a7ca32011-01-14 19:22:48 +05302988EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00002989
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002990/*
2991 * Simplify DAI link configuration by removing ".-1" from device names
2992 * and sanitizing names.
2993 */
Dimitris Papastamos0b9a2142010-12-06 15:49:20 +00002994static char *fmt_single_name(struct device *dev, int *id)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002995{
2996 char *found, name[NAME_SIZE];
2997 int id1, id2;
2998
2999 if (dev_name(dev) == NULL)
3000 return NULL;
3001
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003002 strlcpy(name, dev_name(dev), NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003003
3004 /* are we a "%s.%d" name (platform and SPI components) */
3005 found = strstr(name, dev->driver->name);
3006 if (found) {
3007 /* get ID */
3008 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3009
3010 /* discard ID from name if ID == -1 */
3011 if (*id == -1)
3012 found[strlen(dev->driver->name)] = '\0';
3013 }
3014
3015 } else {
3016 /* I2C component devices are named "bus-addr" */
3017 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3018 char tmp[NAME_SIZE];
3019
3020 /* create unique ID number from I2C addr and bus */
Jarkko Nikula05899442010-10-19 11:10:45 +03003021 *id = ((id1 & 0xffff) << 16) + id2;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003022
3023 /* sanitize component name for DAI link creation */
3024 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003025 strlcpy(name, tmp, NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003026 } else
3027 *id = 0;
3028 }
3029
3030 return kstrdup(name, GFP_KERNEL);
3031}
3032
3033/*
3034 * Simplify DAI link naming for single devices with multiple DAIs by removing
3035 * any ".-1" and using the DAI name (instead of device name).
3036 */
3037static inline char *fmt_multiple_name(struct device *dev,
3038 struct snd_soc_dai_driver *dai_drv)
3039{
3040 if (dai_drv->name == NULL) {
3041 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
3042 dev_name(dev));
3043 return NULL;
3044 }
3045
3046 return kstrdup(dai_drv->name, GFP_KERNEL);
3047}
3048
Mark Brown91151712008-11-30 23:31:24 +00003049/**
3050 * snd_soc_register_dai - Register a DAI with the ASoC core
3051 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003052 * @dai: DAI to register
Mark Brown91151712008-11-30 23:31:24 +00003053 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003054int snd_soc_register_dai(struct device *dev,
3055 struct snd_soc_dai_driver *dai_drv)
Mark Brown91151712008-11-30 23:31:24 +00003056{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003057 struct snd_soc_dai *dai;
Mark Brown91151712008-11-30 23:31:24 +00003058
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003059 dev_dbg(dev, "dai register %s\n", dev_name(dev));
Mark Brown91151712008-11-30 23:31:24 +00003060
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003061 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
3062 if (dai == NULL)
Lu Guanquna7393622011-04-20 16:00:51 +08003063 return -ENOMEM;
Eric Miao6335d052009-03-03 09:41:00 +08003064
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003065 /* create DAI component name */
3066 dai->name = fmt_single_name(dev, &dai->id);
3067 if (dai->name == NULL) {
3068 kfree(dai);
3069 return -ENOMEM;
3070 }
3071
3072 dai->dev = dev;
3073 dai->driver = dai_drv;
3074 if (!dai->driver->ops)
3075 dai->driver->ops = &null_dai_ops;
Mark Brown91151712008-11-30 23:31:24 +00003076
3077 mutex_lock(&client_mutex);
3078 list_add(&dai->list, &dai_list);
Mark Brown435c5e22008-12-04 15:32:53 +00003079 snd_soc_instantiate_cards();
Mark Brown91151712008-11-30 23:31:24 +00003080 mutex_unlock(&client_mutex);
3081
3082 pr_debug("Registered DAI '%s'\n", dai->name);
3083
3084 return 0;
3085}
3086EXPORT_SYMBOL_GPL(snd_soc_register_dai);
3087
3088/**
3089 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3090 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003091 * @dai: DAI to unregister
Mark Brown91151712008-11-30 23:31:24 +00003092 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003093void snd_soc_unregister_dai(struct device *dev)
Mark Brown91151712008-11-30 23:31:24 +00003094{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003095 struct snd_soc_dai *dai;
3096
3097 list_for_each_entry(dai, &dai_list, list) {
3098 if (dev == dai->dev)
3099 goto found;
3100 }
3101 return;
3102
3103found:
Mark Brown91151712008-11-30 23:31:24 +00003104 mutex_lock(&client_mutex);
3105 list_del(&dai->list);
3106 mutex_unlock(&client_mutex);
3107
3108 pr_debug("Unregistered DAI '%s'\n", dai->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003109 kfree(dai->name);
3110 kfree(dai);
Mark Brown91151712008-11-30 23:31:24 +00003111}
3112EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
3113
3114/**
3115 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
3116 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003117 * @dai: Array of DAIs to register
3118 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00003119 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003120int snd_soc_register_dais(struct device *dev,
3121 struct snd_soc_dai_driver *dai_drv, size_t count)
Mark Brown91151712008-11-30 23:31:24 +00003122{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003123 struct snd_soc_dai *dai;
3124 int i, ret = 0;
3125
Liam Girdwood720ffa42010-08-18 00:30:30 +01003126 dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
Mark Brown91151712008-11-30 23:31:24 +00003127
3128 for (i = 0; i < count; i++) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003129
3130 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
Axel Linc46e0072010-11-03 15:04:45 +08003131 if (dai == NULL) {
3132 ret = -ENOMEM;
3133 goto err;
3134 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003135
3136 /* create DAI component name */
3137 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3138 if (dai->name == NULL) {
3139 kfree(dai);
3140 ret = -EINVAL;
Mark Brown91151712008-11-30 23:31:24 +00003141 goto err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003142 }
3143
3144 dai->dev = dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003145 dai->driver = &dai_drv[i];
Mark Brown0f9141c2010-10-12 15:43:21 +01003146 if (dai->driver->id)
3147 dai->id = dai->driver->id;
3148 else
3149 dai->id = i;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003150 if (!dai->driver->ops)
3151 dai->driver->ops = &null_dai_ops;
3152
3153 mutex_lock(&client_mutex);
3154 list_add(&dai->list, &dai_list);
3155 mutex_unlock(&client_mutex);
3156
3157 pr_debug("Registered DAI '%s'\n", dai->name);
Mark Brown91151712008-11-30 23:31:24 +00003158 }
3159
Axel Lin1dcb4f32010-12-06 16:48:03 +08003160 mutex_lock(&client_mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003161 snd_soc_instantiate_cards();
Axel Lin1dcb4f32010-12-06 16:48:03 +08003162 mutex_unlock(&client_mutex);
Mark Brown91151712008-11-30 23:31:24 +00003163 return 0;
3164
3165err:
3166 for (i--; i >= 0; i--)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003167 snd_soc_unregister_dai(dev);
Mark Brown91151712008-11-30 23:31:24 +00003168
3169 return ret;
3170}
3171EXPORT_SYMBOL_GPL(snd_soc_register_dais);
3172
3173/**
3174 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
3175 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003176 * @dai: Array of DAIs to unregister
3177 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00003178 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003179void snd_soc_unregister_dais(struct device *dev, size_t count)
Mark Brown91151712008-11-30 23:31:24 +00003180{
3181 int i;
3182
3183 for (i = 0; i < count; i++)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003184 snd_soc_unregister_dai(dev);
Mark Brown91151712008-11-30 23:31:24 +00003185}
3186EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
3187
Mark Brown12a48a8c2008-12-03 19:40:30 +00003188/**
3189 * snd_soc_register_platform - Register a platform with the ASoC core
3190 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003191 * @platform: platform to register
Mark Brown12a48a8c2008-12-03 19:40:30 +00003192 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003193int snd_soc_register_platform(struct device *dev,
3194 struct snd_soc_platform_driver *platform_drv)
Mark Brown12a48a8c2008-12-03 19:40:30 +00003195{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003196 struct snd_soc_platform *platform;
Mark Brown12a48a8c2008-12-03 19:40:30 +00003197
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003198 dev_dbg(dev, "platform register %s\n", dev_name(dev));
3199
3200 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
3201 if (platform == NULL)
Lu Guanquna7393622011-04-20 16:00:51 +08003202 return -ENOMEM;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003203
3204 /* create platform component name */
3205 platform->name = fmt_single_name(dev, &platform->id);
3206 if (platform->name == NULL) {
3207 kfree(platform);
3208 return -ENOMEM;
3209 }
3210
3211 platform->dev = dev;
3212 platform->driver = platform_drv;
Liam Girdwoodb7950642011-07-04 22:10:52 +01003213 platform->dapm.dev = dev;
3214 platform->dapm.platform = platform;
Liam Girdwood64a648c2011-07-25 11:15:15 +01003215 platform->dapm.stream_event = platform_drv->stream_event;
Mark Brown12a48a8c2008-12-03 19:40:30 +00003216
3217 mutex_lock(&client_mutex);
3218 list_add(&platform->list, &platform_list);
Mark Brown435c5e22008-12-04 15:32:53 +00003219 snd_soc_instantiate_cards();
Mark Brown12a48a8c2008-12-03 19:40:30 +00003220 mutex_unlock(&client_mutex);
3221
3222 pr_debug("Registered platform '%s'\n", platform->name);
3223
3224 return 0;
3225}
3226EXPORT_SYMBOL_GPL(snd_soc_register_platform);
3227
3228/**
3229 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
3230 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003231 * @platform: platform to unregister
Mark Brown12a48a8c2008-12-03 19:40:30 +00003232 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003233void snd_soc_unregister_platform(struct device *dev)
Mark Brown12a48a8c2008-12-03 19:40:30 +00003234{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003235 struct snd_soc_platform *platform;
3236
3237 list_for_each_entry(platform, &platform_list, list) {
3238 if (dev == platform->dev)
3239 goto found;
3240 }
3241 return;
3242
3243found:
Mark Brown12a48a8c2008-12-03 19:40:30 +00003244 mutex_lock(&client_mutex);
3245 list_del(&platform->list);
3246 mutex_unlock(&client_mutex);
3247
3248 pr_debug("Unregistered platform '%s'\n", platform->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003249 kfree(platform->name);
3250 kfree(platform);
Mark Brown12a48a8c2008-12-03 19:40:30 +00003251}
3252EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3253
Mark Brown151ab222009-05-09 16:22:58 +01003254static u64 codec_format_map[] = {
3255 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3256 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3257 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3258 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3259 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3260 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3261 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3262 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3263 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3264 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3265 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3266 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3267 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3268 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3269 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3270 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3271};
3272
3273/* Fix up the DAI formats for endianness: codecs don't actually see
3274 * the endianness of the data but we're using the CPU format
3275 * definitions which do need to include endianness so we ensure that
3276 * codec DAIs always have both big and little endian variants set.
3277 */
3278static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3279{
3280 int i;
3281
3282 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3283 if (stream->formats & codec_format_map[i])
3284 stream->formats |= codec_format_map[i];
3285}
3286
Mark Brown0d0cf002008-12-10 14:32:45 +00003287/**
3288 * snd_soc_register_codec - Register a codec with the ASoC core
3289 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003290 * @codec: codec to register
Mark Brown0d0cf002008-12-10 14:32:45 +00003291 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003292int snd_soc_register_codec(struct device *dev,
Mark Brown001ae4c2010-12-02 16:21:08 +00003293 const struct snd_soc_codec_driver *codec_drv,
3294 struct snd_soc_dai_driver *dai_drv,
3295 int num_dai)
Mark Brown0d0cf002008-12-10 14:32:45 +00003296{
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003297 size_t reg_size;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003298 struct snd_soc_codec *codec;
3299 int ret, i;
Mark Brown151ab222009-05-09 16:22:58 +01003300
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003301 dev_dbg(dev, "codec register %s\n", dev_name(dev));
Mark Brown0d0cf002008-12-10 14:32:45 +00003302
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003303 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3304 if (codec == NULL)
3305 return -ENOMEM;
Mark Brown0d0cf002008-12-10 14:32:45 +00003306
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003307 /* create CODEC component name */
3308 codec->name = fmt_single_name(dev, &codec->id);
3309 if (codec->name == NULL) {
3310 kfree(codec);
3311 return -ENOMEM;
Mark Brown151ab222009-05-09 16:22:58 +01003312 }
3313
Dimitris Papastamos23bbce32010-12-02 14:53:01 +00003314 if (codec_drv->compress_type)
3315 codec->compress_type = codec_drv->compress_type;
3316 else
3317 codec->compress_type = SND_SOC_FLAT_COMPRESSION;
3318
Mark Brownc3acec22010-12-02 16:15:29 +00003319 codec->write = codec_drv->write;
3320 codec->read = codec_drv->read;
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003321 codec->volatile_register = codec_drv->volatile_register;
3322 codec->readable_register = codec_drv->readable_register;
Dimitris Papastamos80204542011-03-24 13:45:17 +00003323 codec->writable_register = codec_drv->writable_register;
Mark Brown5124e692012-02-08 13:20:50 +00003324 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02003325 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
3326 codec->dapm.dev = dev;
3327 codec->dapm.codec = codec;
Mark Brown474b62d2011-01-18 16:14:44 +00003328 codec->dapm.seq_notifier = codec_drv->seq_notifier;
Liam Girdwood64a648c2011-07-25 11:15:15 +01003329 codec->dapm.stream_event = codec_drv->stream_event;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003330 codec->dev = dev;
3331 codec->driver = codec_drv;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003332 codec->num_dai = num_dai;
3333 mutex_init(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003334
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003335 /* allocate CODEC register cache */
3336 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003337 reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
Dimitris Papastamosaea170a2011-01-12 10:38:58 +00003338 codec->reg_size = reg_size;
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003339 /* it is necessary to make a copy of the default register cache
3340 * because in the case of using a compression type that requires
3341 * the default register cache to be marked as __devinitconst the
3342 * kernel might have freed the array by the time we initialize
3343 * the cache.
3344 */
Dimitris Papastamos2aa86322011-01-10 10:10:56 +00003345 if (codec_drv->reg_cache_default) {
3346 codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
3347 reg_size, GFP_KERNEL);
3348 if (!codec->reg_def_copy) {
3349 ret = -ENOMEM;
3350 goto fail;
3351 }
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003352 }
3353 }
3354
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003355 if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
3356 if (!codec->volatile_register)
3357 codec->volatile_register = snd_soc_default_volatile_register;
3358 if (!codec->readable_register)
3359 codec->readable_register = snd_soc_default_readable_register;
Dimitris Papastamos80204542011-03-24 13:45:17 +00003360 if (!codec->writable_register)
3361 codec->writable_register = snd_soc_default_writable_register;
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00003362 }
3363
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003364 for (i = 0; i < num_dai; i++) {
3365 fixup_codec_formats(&dai_drv[i].playback);
3366 fixup_codec_formats(&dai_drv[i].capture);
3367 }
3368
Mark Brown26b01cc2010-08-18 20:20:55 +01003369 /* register any DAIs */
3370 if (num_dai) {
3371 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3372 if (ret < 0)
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00003373 goto fail;
Mark Brown26b01cc2010-08-18 20:20:55 +01003374 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003375
Mark Brown0d0cf002008-12-10 14:32:45 +00003376 mutex_lock(&client_mutex);
3377 list_add(&codec->list, &codec_list);
3378 snd_soc_instantiate_cards();
3379 mutex_unlock(&client_mutex);
3380
3381 pr_debug("Registered codec '%s'\n", codec->name);
Mark Brown0d0cf002008-12-10 14:32:45 +00003382 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003383
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00003384fail:
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003385 kfree(codec->reg_def_copy);
3386 codec->reg_def_copy = NULL;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003387 kfree(codec->name);
3388 kfree(codec);
3389 return ret;
Mark Brown0d0cf002008-12-10 14:32:45 +00003390}
3391EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3392
3393/**
3394 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3395 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003396 * @codec: codec to unregister
Mark Brown0d0cf002008-12-10 14:32:45 +00003397 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003398void snd_soc_unregister_codec(struct device *dev)
Mark Brown0d0cf002008-12-10 14:32:45 +00003399{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003400 struct snd_soc_codec *codec;
3401 int i;
3402
3403 list_for_each_entry(codec, &codec_list, list) {
3404 if (dev == codec->dev)
3405 goto found;
3406 }
3407 return;
3408
3409found:
Mark Brown26b01cc2010-08-18 20:20:55 +01003410 if (codec->num_dai)
3411 for (i = 0; i < codec->num_dai; i++)
3412 snd_soc_unregister_dai(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003413
Mark Brown0d0cf002008-12-10 14:32:45 +00003414 mutex_lock(&client_mutex);
3415 list_del(&codec->list);
3416 mutex_unlock(&client_mutex);
3417
3418 pr_debug("Unregistered codec '%s'\n", codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003419
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00003420 snd_soc_cache_exit(codec);
Dimitris Papastamos3335ddc2010-12-02 16:11:05 +00003421 kfree(codec->reg_def_copy);
Dimitris Papastamos1aafcd42010-10-21 13:19:45 +01003422 kfree(codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003423 kfree(codec);
Mark Brown0d0cf002008-12-10 14:32:45 +00003424}
3425EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
3426
Stephen Warrenbec4fa02011-12-12 15:55:34 -07003427/* Retrieve a card's name from device tree */
3428int snd_soc_of_parse_card_name(struct snd_soc_card *card,
3429 const char *propname)
3430{
3431 struct device_node *np = card->dev->of_node;
3432 int ret;
3433
3434 ret = of_property_read_string_index(np, propname, 0, &card->name);
3435 /*
3436 * EINVAL means the property does not exist. This is fine providing
3437 * card->name was previously set, which is checked later in
3438 * snd_soc_register_card.
3439 */
3440 if (ret < 0 && ret != -EINVAL) {
3441 dev_err(card->dev,
3442 "Property '%s' could not be read: %d\n",
3443 propname, ret);
3444 return ret;
3445 }
3446
3447 return 0;
3448}
3449EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
3450
Stephen Warrena4a54dd2011-12-12 15:55:35 -07003451int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3452 const char *propname)
3453{
3454 struct device_node *np = card->dev->of_node;
3455 int num_routes;
3456 struct snd_soc_dapm_route *routes;
3457 int i, ret;
3458
3459 num_routes = of_property_count_strings(np, propname);
3460 if (num_routes & 1) {
3461 dev_err(card->dev,
3462 "Property '%s's length is not even\n",
3463 propname);
3464 return -EINVAL;
3465 }
3466 num_routes /= 2;
3467 if (!num_routes) {
3468 dev_err(card->dev,
3469 "Property '%s's length is zero\n",
3470 propname);
3471 return -EINVAL;
3472 }
3473
3474 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
3475 GFP_KERNEL);
3476 if (!routes) {
3477 dev_err(card->dev,
3478 "Could not allocate DAPM route table\n");
3479 return -EINVAL;
3480 }
3481
3482 for (i = 0; i < num_routes; i++) {
3483 ret = of_property_read_string_index(np, propname,
3484 2 * i, &routes[i].sink);
3485 if (ret) {
3486 dev_err(card->dev,
3487 "Property '%s' index %d could not be read: %d\n",
3488 propname, 2 * i, ret);
3489 return -EINVAL;
3490 }
3491 ret = of_property_read_string_index(np, propname,
3492 (2 * i) + 1, &routes[i].source);
3493 if (ret) {
3494 dev_err(card->dev,
3495 "Property '%s' index %d could not be read: %d\n",
3496 propname, (2 * i) + 1, ret);
3497 return -EINVAL;
3498 }
3499 }
3500
3501 card->num_dapm_routes = num_routes;
3502 card->dapm_routes = routes;
3503
3504 return 0;
3505}
3506EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
3507
Takashi Iwaic9b3a402008-12-10 07:47:22 +01003508static int __init snd_soc_init(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003509{
Mark Brown384c89e2008-12-03 17:34:03 +00003510#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00003511 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
3512 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
Mark Brown384c89e2008-12-03 17:34:03 +00003513 printk(KERN_WARNING
3514 "ASoC: Failed to create debugfs directory\n");
Mark Brown8a9dab12011-01-10 22:25:21 +00003515 snd_soc_debugfs_root = NULL;
Mark Brown384c89e2008-12-03 17:34:03 +00003516 }
Mark Brownc3c5a192010-09-15 18:15:14 +01003517
Mark Brown8a9dab12011-01-10 22:25:21 +00003518 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
Mark Brownc3c5a192010-09-15 18:15:14 +01003519 &codec_list_fops))
3520 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
3521
Mark Brown8a9dab12011-01-10 22:25:21 +00003522 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
Mark Brownf3208782010-09-15 18:19:07 +01003523 &dai_list_fops))
3524 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
Mark Brown19c7ac22010-09-15 18:22:40 +01003525
Mark Brown8a9dab12011-01-10 22:25:21 +00003526 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
Mark Brown19c7ac22010-09-15 18:22:40 +01003527 &platform_list_fops))
3528 pr_warn("ASoC: Failed to create platform list debugfs file\n");
Mark Brown384c89e2008-12-03 17:34:03 +00003529#endif
3530
Mark Brownfb257892011-04-28 10:57:54 +01003531 snd_soc_util_init();
3532
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003533 return platform_driver_register(&soc_driver);
3534}
Mark Brown4abe8e12010-10-12 17:41:03 +01003535module_init(snd_soc_init);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003536
Mark Brown7d8c16a2008-11-30 22:11:24 +00003537static void __exit snd_soc_exit(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003538{
Mark Brownfb257892011-04-28 10:57:54 +01003539 snd_soc_util_exit();
3540
Mark Brown384c89e2008-12-03 17:34:03 +00003541#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00003542 debugfs_remove_recursive(snd_soc_debugfs_root);
Mark Brown384c89e2008-12-03 17:34:03 +00003543#endif
Mark Brown3ff3f642008-05-19 12:32:25 +02003544 platform_driver_unregister(&soc_driver);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003545}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003546module_exit(snd_soc_exit);
3547
3548/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01003549MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Frank Mandarinodb2a4162006-10-06 18:31:09 +02003550MODULE_DESCRIPTION("ALSA SoC Core");
3551MODULE_LICENSE("GPL");
Kay Sievers8b45a202008-04-14 13:33:36 +02003552MODULE_ALIAS("platform:soc-audio");